Skip to content

fix(analysis): audit all non-exempt top-level builtins/ files#261

Merged
AlexandreYang merged 1 commit into
mainfrom
alex/fix-builtin-import-allowlist.md
May 22, 2026
Merged

fix(analysis): audit all non-exempt top-level builtins/ files#261
AlexandreYang merged 1 commit into
mainfrom
alex/fix-builtin-import-allowlist.md

Conversation

@AlexandreYang

@AlexandreYang AlexandreYang commented May 19, 2026

Copy link
Copy Markdown
Member

Summary

  • Closes vuln-hunt F-1 (builtin-import-allowlist.md): collectSubdirGoFiles had an unconditional subdir-only filter that shadowed the skipTopLevel callback, silently excluding builtins/proc_provider.go and builtins/features.go from the symbol allowlist. Banned imports (os/exec, net/*, plugin, reflect) could land in either file undetected.
  • Rename collectSubdirGoFilescollectGoFilesRecursive, drop the shadowing filter, so skipTopLevel solely controls top-level exemption. builtins.go stays exempt via the existing callback; proc_provider.go and features.go are now audited (their current imports already comply).
  • Add TestVerificationBuiltinsChecksNonExemptTopLevel regression test that injects os/exec into proc_provider.go and asserts the analyzer flags it. Update the stale F-1 reference comment in signal_handling_vuln_hunt_test.go (kept as defense-in-depth).

Test plan

  • go test ./analysis/... -count=1
  • TestBuiltinAllowedSymbols, TestBuiltinPerCommandSymbols, TestVerificationBuiltinsCleanPass, TestVerificationBuiltinsSkipsTopLevel, TestVerificationBuiltinsChecksNonExemptTopLevel all pass
  • make fmt clean

Closes vuln-hunt F-1 (2026-05-18-initial-audit / builtin-import-allowlist):
the collector helper had an unconditional subdir-only filter that shadowed
the skipTopLevel callback, silently excluding builtins/proc_provider.go and
builtins/features.go from the symbol allowlist. A maintainer could land a
banned import (os/exec, net/*, plugin, reflect) in either file undetected.

Rename collectSubdirGoFiles -> collectGoFilesRecursive and drop the
shadowing filter so skipTopLevel solely controls top-level exemption.
builtins.go remains exempt via the existing callback; proc_provider.go and
features.go are now audited (current imports already comply).

Add TestVerificationBuiltinsChecksNonExemptTopLevel as the regression
guard, and update the stale F-1 reference in the signal-handling
vuln-hunt fallback test.
@datadog-prod-us1-5

Copy link
Copy Markdown
Contributor

Pipelines

Fix all issues with BitsAI

⚠️ Warnings

🚦 1 Pipeline job failed

Static Analysis Verification | Static Analysis Label Check   View in Datadog   GitHub Actions

🛟 This job is unlikely to succeed on retry. Please review your pipeline configuration. Files in analysis/ have been modified. A human must review the changes and add the 'verified/analysis' label to this PR before it can be merged.

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 6b9c9cf | Docs | Datadog PR Page | Give us feedback!

@AlexandreYang

Copy link
Copy Markdown
Member Author

@codex review this PR

Please use the following severity format for all findings:

  • P0 (red): Exploitable vulnerability with high impact (RCE, sandbox bypass, data breach). Blocking merge.
  • P1 (orange): Likely exploitable or high-risk — correctness bugs vs bash, data races, panics.
  • P2 (yellow): Potential vulnerability, bash divergence, missing test coverage, missing docs.
  • P3 (blue): Style, minor simplification, hardening suggestion, nice-to-have test.

Prefix each finding title with its priority label, e.g. "P0: ...", "P1: ...", etc.
Include a summary table at the top with columns: # | Priority | File | Finding.

@AlexandreYang AlexandreYang left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-Review (iteration 1)

Scope: Closes vuln-hunt F-1 (2026-05-18-initial-audit / builtin-import-allowlist). Four-file change in analysis/:

  • symbols_test.go — rename helper, drop the shadowing subdir-only filter.
  • symbols_builtins_test.go — call-site updates + tightened comment.
  • symbols_builtins_verification_test.go — new regression test.
  • signal_handling_vuln_hunt_test.go — stale F-1 reference updated.

Overall assessment: safe to merge. The fix is surgical: it removes a filter that shadowed an intentional callback, restores the original design (skipTopLevel controls top-level exemption), and adds a regression test that fails if the subdir-only filter is reintroduced. No new attack surface; this strictly tightens analyzer coverage.

Findings

# Priority File Finding

(no P0/P1/P2/P3 findings raised in this iteration)

Verification performed

  • make fmt clean.
  • go test ./analysis/... -count=1 passes.
  • TestVerificationBuiltinsChecksNonExemptTopLevel confirmed to fail when the pre-fix strings.Contains(rel, separator) filter is reintroduced (the regression guard works in both directions).
  • Confirmed no remaining references to the old collectSubdirGoFiles name in the tree.
  • Confirmed internalCheckConfig's nil, nil call now nominally audits top-level files in builtins/internal/, but no such files exist today — benign contract widening.

Positive observations

  • Root-cause fix, not a workaround. The shadowing filter is removed rather than papered over with a second collector or a parallel test entry point. The contract change (skipTopLevel is now load-bearing) matches what any reader of builtinsCheckConfig would already assume — which is exactly the misreading that hid the original bug.
  • Test names the threat. TestVerificationBuiltinsChecksNonExemptTopLevel directly inverts TestVerificationBuiltinsSkipsTopLevel and references the vuln-hunt finding in its docstring, giving future maintainers a clear chain back to the audit.
  • Belt-and-braces kept. The signal-handling vuln-hunt fallback (TestVulnHuntSubsystemSignalHandling_NoSignalNotifyInProductionCode) is preserved as defense-in-depth — its comment is updated to note the original gap is closed, rather than removing the test outright.
  • Rename improves discoverability. collectGoFilesRecursive correctly describes the new contract; the prior name (collectSubdirGoFiles) was the exact misnomer that hid the bug.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@AlexandreYang

Copy link
Copy Markdown
Member Author

Iteration 1 self-review result: P0=0, P1=0, P2=0, P3=0 — no findings raised. Review URL: #261 (review)

@AlexandreYang
AlexandreYang marked this pull request as ready for review May 19, 2026 12:34
@AlexandreYang AlexandreYang added the verified/analysis Human-reviewed static analysis changes label May 19, 2026
@AlexandreYang
AlexandreYang added this pull request to the merge queue May 22, 2026
Merged via the queue into main with commit f89e6fc May 22, 2026
40 of 41 checks passed
@AlexandreYang
AlexandreYang deleted the alex/fix-builtin-import-allowlist.md branch May 22, 2026 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

verified/analysis Human-reviewed static analysis changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants