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

オープン 初心者向け
#12,411 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
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をヘルパーの配置候補として調べてください。各呼び出し元のガード条件を維持し、環境変数のチェックとエラーメッセージを集約してください。両方の経路が共有ヘルパーを使い、引き続き変数が'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分
マージ済み PR(30日)
450

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

github/gh-aw-firewall のほかの issue

github/gh-aw-firewall の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。