[Duplicate Code] Cloud Hypervisor development-artifact bypass gate duplicated in runtime-validation and preflight-artifact-trust
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 76/100
- Issue 类型
- 重构
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- typescript
- 领域
- security
调研方向
阅读src/cloud-hypervisor/runtime-validation.ts和src/cloud-hypervisor/preflight-artifact-trust.ts中的现有检查,然后检查src/cloud-hypervisor/artifact-trust.ts,将其作为建议的 helper 位置。保留每个调用方的保护条件,并整合环境变量检查和错误消息;当两个路径都使用共享 helper,且仍要求变量等于'1'时,任务即完成。
由索引模型根据 Issue 内容生成。
描述
Duplicate Code Opportunity
Summary
- Pattern: The
AWF_CLOUD_HYPERVISOR_DEVELOPMENT_ALLOW_UNATTESTED_ARTIFACTS=1opt-in check and its identical error message are repeated in two artifact-trust validation paths. - Locations:
src/cloud-hypervisor/runtime-validation.tsandsrc/cloud-hypervisor/preflight-artifact-trust.ts - Impact: About 8 duplicated lines per copy. This is a security control (the gate that permits unattested artifacts). If the variable name, the required value, or the message changes in one copy but not the other, the two validation paths can disagree about whether the bypass is permitted.
Evidence
src/cloud-hypervisor/runtime-validation.ts: lines 110-117
if (
process.env.AWF_CLOUD_HYPERVISOR_DEVELOPMENT_ALLOW_UNATTESTED_ARTIFACTS !== '1'
) {
throw new Error(
'Cloud Hypervisor development artifact bypass requires ' +
'AWF_CLOUD_HYPERVISOR_DEVELOPMENT_ALLOW_UNATTESTED_ARTIFACTS=1',
);
}
src/cloud-hypervisor/preflight-artifact-trust.ts: lines 73-81
if (
developmentBypass &&
process.env.AWF_CLOUD_HYPERVISOR_DEVELOPMENT_ALLOW_UNATTESTED_ARTIFACTS !== '1'
) {
throw new Error(
'Cloud Hypervisor development artifact bypass requires ' +
'AWF_CLOUD_HYPERVISOR_DEVELOPMENT_ALLOW_UNATTESTED_ARTIFACTS=1',
);
}
Both copies have the same env check, the same error text, and the same thrown error. Only the guarding condition differs (developmentAllowUnattestedArtifacts versus developmentBypass).
Suggested Refactoring
- Add
assertDevelopmentArtifactBypassAllowed(env = process.env)tosrc/cloud-hypervisor/artifact-trust.ts, which already reads env for artifact trust decisions. It should throw the canonical message when the variable is not'1'. - Replace both inline checks with a call to this helper, keeping each caller's own guarding condition unchanged.
- Optionally add a unit test in
artifact-trustcovering the message and the'1'requirement, so both call sites are covered by one test.
Affected Files
src/cloud-hypervisor/runtime-validation.ts— lines 110-117src/cloud-hypervisor/preflight-artifact-trust.ts— lines 73-81src/cloud-hypervisor/artifact-trust.ts— target for the shared helper
Effort Estimate
Low
Detected by Duplicate Code Detector workflow. Run date: 2026-11-30
Generated by Duplicate Code Detector · copilot · routed: haiku55 xhigh · ~2 AIC · ⊞ 18.3K · history
- expires on Dec 30, 2026, 9:54 PM UTC
- 主要语言
- TypeScript
- 星标
- 169
- 派生
- 89
- 平均合并
- 5 小时 18 分钟
- 30 天内合并 PR
- 450
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
github/gh-aw-firewall 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
github/gh-aw-firewall#12415 ·
维护者通常 1 天内回复
-
code-quality refactoring
难度 2/5 1-3 小时 新手友好度 78/100
github/gh-aw-firewall#12345 ·
维护者通常 1 天内回复
-
[Duplicate Code] Repeated lstat identity-swap stub and fixture setup in src/nvx/live-mount-policy.test.ts可能已有人在做 @lpcox 于 1 天前认领。 未关闭code-quality refactoring
难度 2/5 1-3 小时 新手友好度 65/100
github/gh-aw-firewall#12023 · 1 个 reaction · 已指派 2 人 ·
维护者通常 1 天内回复
-
awf-triage
难度 2/5 1-3 小时 新手友好度 72/100
github/gh-aw-firewall#11612 ·
维护者通常 1 天内回复
-
agentic-workflows automated dependencies
难度 2/5 1-3 小时 新手友好度 68/100
github/gh-aw-firewall#3837 ·
维护者通常 1 天内回复
查看 github/gh-aw-firewall 的全部 Issue
相似的 Issue
-
area: documentation status: in progress type: documentation
难度 1/5 1 小时以内 新手友好度 76/100
Oddmash/oddmash-ui#222 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 79/100
appium/appium-wincore-driver#169 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
india-ultimate/hub#715 ·
维护者通常 1 天内回复
-
documentation Entwickler
难度 1/5 1 小时以内 新手友好度 89/100
维护者通常 1 天内回复