Repository navigation
Stop a crafted package.json script key becoming a memory - #371
Merged
Merged
Conversation
…301) detectPackageScripts built "npm run ${name}" from any notable key, so a checkout shipping a key like "test && echo SYNTHETIC" stored a command memory carrying the injected text. The row is tagged init/package.json, so it gets no [via ...] provenance marker and rides into every later session of the repo, outliving the branch the crafted key came from. Make/Just targets were already restricted; package.json was the detector without a filter. Keys outside /^[A-Za-z0-9_.:-]+$/ are skipped. Deliberate widening of the ticket's [A-Za-z0-9_-]+: the colon and dot carry no shell meaning and npm convention uses them (test:ci, lint.fix), and dropping them would lose the CI command a repo most wants remembered. The test pins both halves.
Owner
Author
Adversarial self-review (author-side, not independent)Tried to route a crafted key around Verified clean:
Findings:
Verdict: approve. Branch is 23 commits behind |
|
🎉 This PR is included in version 0.22.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Owner
Author
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.
What this does
/repo-initreads yourpackage.jsonand remembers the notable scripts (test,lint,build, …) as memories, phrased as "runnpm run <name>from the repo root". It took the script name from the file with no character check, so a checkout shipping a key like{ "scripts": { "test && echo SYNTHETIC": "vitest run" } }stored a memory whose command contained
&& echo SYNTHETIC. That row is taggedinit/package.json, so it gets no[via ...]provenance marker, and it is injected into every later session of that repository — surviving long after the branch or clone that carried the crafted key is gone. Make and Just targets were already restricted to identifier characters;package.jsonwas the one detector without a filter.Keys that are not a plain identifier are now skipped: no record, no row. Everything else about init is unchanged.
One deliberate deviation from the ticket
#301 specified
[A-Za-z0-9_-]+, the class the Make detector uses. That would also drop ordinary npm keys such astest:ciandlint.fix— the colon and the dot carry no shell meaning, and a CI test command is exactly the kind of thing worth remembering. This filter is/^[A-Za-z0-9_.:-]+$/: it rejects everything the ticket is about (whitespace,&,;,|,$, quotes, paths) and keeps the npm convention. The test pins both halves — the crafted key is dropped,test:cisurvives. Say the word if you want the narrower class instead.Tests
"test && echo SYNTHETIC","lint --fix; rm -rf /","test:ci"andlint,detectScriptsreturned the crafted keys.lintandtest:cionly, every returned key matches the identifier class, and no returned command contains the injected text.npm run test/npm run lintrows, idempotency, force) still pass.bun run gategreen: 1130 unit tests + 30 terminal/BDD tests against a real host, 0 fail.bunx tsc --noEmitclean; lint and format identical to main's baseline.Closes #301.