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

Open Beginner friendly
#12,411 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
security

Research direction

Read the existing checks in src/cloud-hypervisor/runtime-validation.ts and src/cloud-hypervisor/preflight-artifact-trust.ts, then inspect src/cloud-hypervisor/artifact-trust.ts as the proposed helper location. Keep each caller's guarding condition and consolidate the environment check and error message; done when both paths use the shared helper and still require the variable to equal '1'.

Written by the indexing model from the issue text.

Description

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
Dominant language
TypeScript
Stars
169
Forks
89
Avg merge
5h 18m
Merged PRs (30d)
450

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from github/gh-aw-firewall

All issues in github/gh-aw-firewall

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.