Skip to content

Extend self_propagation language coverage: fix dead PHP/Ruby token, add PowerShell + Shell #1172

Closed

Description

@squid-protocol

Part of epic #1171.

🛑 Problem Statement

security_lens.py's self_propagation signature (added in #1150/PR #1169) only pairs a
self-file-reference token with copy/write function names for two ecosystems: JS/TS
(fs.copyFileSync/writeFileSync/appendFileSync/renameSync) and Python (shutil.copy2?/
copyfile/move, os.rename).

The regex already accepts __FILE__ (PHP and Ruby's self-reference token) as a valid match
target in its token alternation — but no PHP or Ruby copy/write/rename function names are paired
with it anywhere in the function-name alternation. That half of the pattern is currently dead: it
can never match anything, because __FILE__ only ever appears in PHP/Ruby source, and this
pattern's function-name branch has no PHP/Ruby entries to pair it with.

🎯 Objective

  1. Fix the dead __FILE__ pairing: add PHP's copy()/rename()/
    file_put_contents($x, file_get_contents(__FILE__)) and Ruby's FileUtils.cp/File.write
    (paired with File.read(__FILE__)) to the function-name alternation.
  2. Add PowerShell: self-reference tokens $PSCommandPath / $MyInvocation.MyCommand.Path, paired
    with Copy-Item. Real-world precedent: Windows dropper/persistence malware very commonly
    self-copies via PowerShell to a startup folder.
  3. Add Shell (bash/sh): self-reference token $0, paired with cp/install. Real-world
    precedent: malicious postinstall.sh/dropper scripts copying themselves for persistence. $0
    is used for plenty of legitimate things (usage banners, basename $0 logging) — precision here
    depends entirely on requiring it as the literal argument to cp/install, same discipline as
    the existing JS/Python pattern, not a loose proximity match.

🛠️ Proposed Implementation

Extend the existing self_propagation regex's function-name alternation (in
security_lens.py's THREAT_SIGNATURES) with the PHP/Ruby/PowerShell/Shell function names above,
keeping the same "self-ref token as the literal first argument" structure that's already proven
zero-FP across the crucible corpus. No new schema key needed — this extends the existing
sec_self_propagation signal.

✅ Acceptance Criteria

  • Synthetic tests prove detection for PHP, Ruby, PowerShell, and Shell self-copy/self-overwrite
    shapes (mirroring the existing JS/Python tests in tests/security_auditing/test_security_lens.py)
  • False-positive guard tests: ordinary $0 usage in a usage banner, ordinary
    $PSCommandPath logging, and ordinary PHP __FILE__ path-resolution idioms must not fire
  • Verified against the full language-crucible corpus: zero unintended hits before the
    golden-master rebless (same process as PR feat(security): build a narrow GlassWorm-style detector for obfuscation_flag #1169)
  • ReDoS timing sweep on the updated pattern

Activity

  1. added
    bug
    appsec
    supply-chain
    threat: false-negative
    on Aug 9, 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

    appsecbugpriority: mediumsupply-chainthreat: false-negative

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions