Skip to content

Harden self_propagation matching: tolerate path-normalization wrappers and read-then-write shapeΒ #1174

Closed

Description

@squid-protocol

Part of epic #1171.

πŸ›‘ Problem Statement

self_propagation (#1150/PR #1169) is intentionally strict: it only matches when the
self-reference token is the literal, immediate first argument to a copy/write call β€” nothing
between the opening parenthesis and the token but optional whitespace. That precision was the
right call to ship the first version with zero false positives, but it also means two extremely
common, equally worm-like real-world shapes slip through untouched:

  1. Wrapped in a path-normalization call first: shutil.copy(os.path.abspath(__file__), dest)
    or fs.copyFileSync(path.resolve(__filename), dest) β€” still obviously self-copying, just with
    one extra normalization step the current pattern doesn't look through.
  2. Read-then-write instead of one copy call: fs.writeFileSync(dest, fs.readFileSync(__filename))
    β€” reads its own bytes, writes them somewhere else. Same behavior, different call shape than a
    single copyFileSync.

🎯 Objective

Extend self_propagation to catch both shapes above, without loosening the core precision rule
("self-reference token has to visibly, directly feed into a copy/write, not just appear nearby").

πŸ› οΈ Proposed Implementation

  • Allow the self-reference token to appear wrapped in a small, explicit, bounded set of
    normalization calls (os\.path\.(?:abspath|realpath|normpath)\(, path\.resolve\() between the
    outer call's opening paren and the token β€” bounded alternation, not an open-ended nested-call
    matcher (keep Rule 11's nested-delimiter ReDoS guidance in mind from
    how_to_add_a_language.md if the wrapper needs to tolerate its own closing paren).
  • Add a second alternative to the pattern for the read-then-write shape: a read call
    (readFileSync/open/File.read) taking the self-reference token as its argument, appearing
    as an argument to an outer write call, within the same statement.
  • Explicitly not in scope here: chasing the self-reference token through an intermediate
    variable assignment (const me = __filename; ...; fs.copyFileSync(me, dest);). That requires
    real short-range taint tracking rather than a single-statement pattern match β€” a bigger, fuzzier
    change with real false-positive risk (the variable name could be reused/reassigned), and belongs
    in its own follow-on issue if pursued.

βœ… Acceptance Criteria

  • Synthetic tests prove detection of both the wrapped-token and read-then-write shapes, across
    the languages already covered by Extend self_propagation language coverage: fix dead PHP/Ruby token, add PowerShell + ShellΒ #1172 (JS/Python at minimum, plus whichever of
    PHP/Ruby/PowerShell/Shell land first)
  • False-positive guard tests: ordinary use of os.path.abspath/path.resolve on values that
    are not the self-reference token must not fire
  • Verified against the full language-crucible corpus: zero unintended hits before the
    golden-master rebless
  • ReDoS timing sweep on the updated pattern, specifically probing the wrapper-tolerance
    alternative for the adjacent-quantifier shape called out in Rule 14

Activity

  1. added
    appsec
    supply-chain
    threat: false-negative
    on Aug 9, 2026
  2. squid-protocol commented on Oct 3, 2026

    @squid-protocol
    OwnerAuthor

    Implemented by PR #2695 (merged 2026-09-03): self_propagation in security_lens.py now accepts one bounded path-normalization wrapper (abspath/realpath/normpath/path.resolve) and the read-then-write shape. The PR said 'Closes #1174' but the issue didn't auto-close, so closing manually.

  3. added
    scope:frontier
    on Oct 16, 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

    appsecpriority: mediumscope:frontiersupply-chainthreat: false-negative

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions