fix(security): self_propagation covers PHP/Ruby/PowerShell/Shell and two evasive shapes (#1172, #1174) - #2695
Merged
Conversation
…two evasive shapes (#1172, #1174) #1172 -- the `__FILE__` half of the alternation was dead code. The token was accepted, but no PHP or Ruby copy/write function was ever paired with it, and `__FILE__` appears only in PHP/Ruby source, which never calls `shutil.copy`. Adds PHP (`copy`, `rename`, `file_put_contents`/`file_get_contents`), Ruby (`FileUtils.cp`, `File.write`/`File.read`), PowerShell (`Copy-Item` with `$PSCommandPath` / `$MyInvocation.MyCommand.Path`) and Shell (`cp`/`install` with `$0`) -- the last two because self-copy into a startup folder or cron directory is the classic dropper persistence step. #1174 -- two equally worm-like shapes slipped through the literal-first-argument rule: one bounded path-normalization wrapper (`shutil.copy(os.path.abspath(__file__), dest)`) and read-then-write (`fs.writeFileSync(dest, fs.readFileSync(__filename))`), a self-copy spelled as two calls. The precision rule from #1150/#1169 is unchanged: the self-reference token must visibly, directly feed a copy/write call, never merely appear nearby. Only the routes to that call widen. `$0` is accepted solely as a literal argument to `cp`/`install`, since it is otherwise ubiquitous in usage banners and logging -- 11 false-positive guards cover exactly those idioms, including a `cp` whose flag takes a value (`cp -m 755 /src/a /dst/b`), which the first draft of the flag repeat let through. Verified over the whole language-crucible corpus (3366 files): zero hits before, zero hits after. The signal fires nowhere in real corpus code, so there is no golden-master movement and no bless -- which is also the acceptance criterion #1172 asked for. Every quantifier bounded (Engine Rule 14), with a detonation test per new branch. Suite 7483 passed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1172 and #1174 (epic #1171). Both are
security_lens.py'sself_propagationsignature — one layer, one file.#1172 — the
__FILE__branch was dead codeThe token was already accepted, but no PHP or Ruby copy/write function was ever paired with it, and
__FILE__appears only in PHP/Ruby source — which never callsshutil.copy. That half of the alternation could not match anything.Added: PHP (
copy,rename,file_put_contents/file_get_contents), Ruby (FileUtils.cp,File.write/File.read), PowerShell (Copy-Itemwith$PSCommandPath/$MyInvocation.MyCommand.Path), Shell (cp/installwith$0) — the last two because self-copy into a startup folder or cron directory is the classic dropper persistence step.#1174 — two evasive shapes
shutil.copy(os.path.abspath(__file__), dest)fs.writeFileSync(dest, fs.readFileSync(__filename))— a self-copy spelled as two callsThe precision rule is unchanged: the self-reference token must visibly, directly feed a copy/write call, never merely appear nearby. Only the routes to that call widen.
Precision
$0is ubiquitous in usage banners and logging, so it is accepted only as a literal argument tocp/install. 11 false-positive guards cover those idioms — includingcp -m 755 /src/a /dst/b, acpwhose flag takes a value, which the first draft of the flag repeat let through and a negative test caught.Verification
origin/main.audit_checkclear (ruff baseline regenerated, pure line-shifts).🤖 Generated with Claude Code