Repository navigation
Description
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
- Fix the dead
__FILE__pairing: add PHP'scopy()/rename()/
file_put_contents($x, file_get_contents(__FILE__))and Ruby'sFileUtils.cp/File.write
(paired withFile.read(__FILE__)) to the function-name alternation. - Add PowerShell: self-reference tokens
$PSCommandPath/$MyInvocation.MyCommand.Path, paired
withCopy-Item. Real-world precedent: Windows dropper/persistence malware very commonly
self-copies via PowerShell to a startup folder. - Add Shell (bash/sh): self-reference token
$0, paired withcp/install. Real-world
precedent: maliciouspostinstall.sh/dropper scripts copying themselves for persistence.$0
is used for plenty of legitimate things (usage banners,basename $0logging) — precision here
depends entirely on requiring it as the literal argument tocp/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 intests/security_auditing/test_security_lens.py) - False-positive guard tests: ordinary
$0usage in a usage banner, ordinary
$PSCommandPathlogging, and ordinary PHP__FILE__path-resolution idioms must not fire - Verified against the full
language-cruciblecorpus: 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
fix(security): self_propagation covers PHP/Ruby/PowerShell/Shell and …