[Duplicate Code] Cloud Hypervisor development-artifact bypass gate duplicated in runtime-validation and preflight-artifact-trust

未关闭 适合新手
#12,411 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 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 内容生成。

描述

code-quality refactoring

Duplicate Code Opportunity

Summary
  • Pattern: The AWF_CLOUD_HYPERVISOR_DEVELOPMENT_ALLOW_UNATTESTED_ARTIFACTS=1 opt-in check and its identical error message are repeated in two artifact-trust validation paths.
  • Locations: src/cloud-hypervisor/runtime-validation.ts and src/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) to src/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-trust covering 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-117
  • src/cloud-hypervisor/preflight-artifact-trust.ts — lines 73-81
  • src/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 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

github/gh-aw-firewall 的其他 Issue

查看 github/gh-aw-firewall 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。