Skip to content

fix(security): secret masking tells code from literals by the file's syntax, not by receiver names #889

Description

@dan-petty

Context & Rationale

mask_secrets (security/sanitizer.py:269) masks password = <value> assignments. Code must not be rewritten before review (:136-141). So _is_code_value (:124-133) leaves an unquoted dotted name alone, but only when its first part is in CONST_CODE_EXEMPTION_RECEIVERS (config/constants.py:2347-2364). That list holds 14 names, such as request, settings and self.

At ef21785 it fails in both directions:

  • password = cfg.db_password becomes password=<masked-password>, because cfg is not on the list. The code the reviewer needs to see is hidden.
  • PASSWORD=settings.Hunter22 in an env file is left as it is, because settings is on the list.

The review masks whole files and pages before the model sees them (ai/review/verification.py:196, :287; ai/review/classification.py:329). Every other caller masks logs, errors and telemetry.

Scope & Deliverables

  • Deliverable:
    • mask_secrets takes the syntax of the text it masks:
      • code: a programming language, from detect_language (ai/analyze/scanner.py:127) on the reviewed path;
      • data: everything else. This is the default.
    • In code, an unquoted right-hand side made of names, calls or indexing is an expression, and stays as written. In data, every value is masked.
    • The review callers pass the syntax per file.
    • Delete CONST_CODE_EXEMPTION_RECEIVERS.
  • Acceptance criteria:
    • A table test runs both examples above in both syntaxes. In code, cfg.db_password stays. In data, settings.Hunter22 is masked. Verified by the test.
    • The existing sanitizer tests pass. Verified by the gate.
    • A review of one Python file and one env file masks each by its own syntax. Verified by a test with fake files, without a model.
    • grep -rn CONST_CODE_EXEMPTION_RECEIVERS src tests prints nothing. Verified by the command.
  • Key questions:
    • What about pages that hold several files (classification.py:329)? Mask each file before the page is put together (proposed). Where that is not possible, the page uses data, which masks more and so is safe.
    • Which languages count as code? The scanner's own language table decides, because it is a closed set this project defines (proposed). Config, markup and plain text count as data.
  • Constraint: Callers that pass no syntax keep masking as much as today or more, never less.

Strategic Alignment

Split off #431 during the v0.2.25/v0.2.26 readiness review (2026-10-01): Part of #431's original scope (CONST_CODE_EXEMPTION_RECEIVERS is an arbitrary identifier-prefix list) that #431 no longer covers. It changes the sanitizer's interface and the review callers, so it is its own PR.

Update 2026-10-08: refinement

The defect stands (security/sanitizer.py:124-134). Single-file maskers: ai/review/verification.py:233, :324, ai/review/classification.py:329, ai/review/judged_claims.py:117, ai/analyze/outlines.py:96, :301; data maskers: ai/review/sanitization.py:27, ai/review/pipeline.py:3193. Each single-file caller passes its file's syntax.

Activity

  1. added
    type/bug
    scope/security
    priority/p3-low
    on Oct 1, 2026
  2. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    Lines cited at dcafadf.

    #1109 also edits security/sanitizer.py, but different code: the URL-credential entry of _SECRET_PATTERNS (:235-239), mask_uri_credentials (:288-307) and sanitize_telemetry_endpoint (:343-366), which it moves onto urllib.parse.urlsplit and httpx2.URL. This item changes _is_code_value (:124-134) and the signature of mask_secrets (:269), so whichever lands second rebases. Keep #1109's URL-credential masking in force under both the code and the data syntax, since a password inside a URL is a literal in either.

    Two more notes (consolidation, 2026-10-03):

  3. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Linked: #540 and #887. This item picks masking syntax with scanner.detect_language, which #540 replaces with one classifier; #887 replaces other hand-written security tables under the same library-first rule. Found by the 2026-10-08 backlog review.

  4. dan-petty commented on Oct 9, 2026

    @dan-petty
    OwnerAuthor

    Folded in: a token right after < is never masked (found by #1398's review, 2026-10-09)

    Since v0.2.18 (#116), the GitHub-token and sk- patterns in security/sanitizer.py carry < in their lookbehind ((?<![A-Za-z0-9_<]) after #1398). So a token right after <, as in a Markdown autolink or a hook message that wraps the value in angle brackets (<ghs_...>), is printed whole, for every prefix. Neither #116's task file nor its commit says why < was added; the likely reason is to leave doc placeholders such as <ghp_token> alone, which the length minimums now do anyway.

    This belongs with this item's rework of how masking tells code from literals: drop < from the lookbehinds (keeping the length minimums), with a test that <ghs_ + a real-length body is masked and a placeholder such as <ghp_token> is not.

    When this lands, also update docs/agent/tasks/task-1398-mask-every-github-token-prefix.md, whose note says the < lookbehind gap "needs a follow-up issue": it should name this issue (#1398 merged before the fold).

  5. added a commit that references this issue on Oct 24, 2026
    a18a342
  6. added a commit that references this issue on Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p3-lowscope/securitytype/bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions