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

Đang mở Phù hợp với người mới
#12,411 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
76/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
security

Hướng nghiên cứu

Đọc các kiểm tra hiện có trong src/cloud-hypervisor/runtime-validation.ts và src/cloud-hypervisor/preflight-artifact-trust.ts, sau đó xem src/cloud-hypervisor/artifact-trust.ts là vị trí đề xuất cho helper. Giữ nguyên điều kiện bảo vệ của từng bên gọi và hợp nhất phần kiểm tra biến môi trường cùng thông báo lỗi; hoàn tất khi cả hai đường dẫn đều dùng helper dùng chung và vẫn yêu cầu biến có giá trị bằng '1'.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
TypeScript
Star
169
Fork
89
Merge trung bình
5 giờ 18 phút
Pull request đã merge (30 ngày)
450

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của github/gh-aw-firewall

Tất cả issue của github/gh-aw-firewall

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.