Hosted composer.lock rewrite splices the server's url and sha1 through expanding Regex::replace with no validation or JSON escaping

Aperta
#1,934 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust

Direzione di ricerca

Start in formats/composer/hosted.rs around L268-L281, where the url and sha1 are spliced into the rewritten composer.lock through regex replacement, then check the vendored-path test at L232-L233. Compare the sha1 check in patch/redirect/mod.rs near L1988 and the parse_vendor_path helper used by wired_to. Done means a url containing $1 and a quote produces valid JSON with the exact url, and a non-hex sha1 is refused with a warning, with the existing composer equivalence tests still passing.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

agent:triaged arch-audit bug priority:p2

[agent] Filed by the scheduled architecture audit (audit-core). Register: register.

Kind: bug (missing validator; extends A06). Register ID: A56.

Problem

formats/composer/hosted.rs L268-L281 builds the replacement text from server-supplied values:

rewritten = url_re.replace(&rewritten, format!("${{1}}{}${{2}}", dep.artifact_url).as_str())
...
shasum_re.replace(&rewritten, format!("${{1}}{sha1}${{2}}").as_str())
  • The replacer expands $n/${name} inside the url and the sha1.
  • Neither value is JSON-escaped.
  • The sha1 is never checked to be 40 lowercase hex.

The cargo hosted path does validate its checksum (redirect/mod.rs L1988).

Executed (a scratch copy at cbbbdb9): url …?s=$1&q="z with sha1 not"hex$2 produces "url": "https://h.test/x?s="url": "&q="z", and the rewritten composer.lock no longer parses as JSON.

The vendored check at L232-L233 is a hand-rolled ".socket/vendor/" prefix test, where mod.rs's wired_to uses parse_vendor_path.

Proposed change

  • Refuse the dep unless digest::sha1_hex-style validation passes.
  • Serialize the url with serde_json::to_string and splice it with regex::NoExpand.
  • Use parse_vendor_path for the vendored check.

Size

1 file, about ±25 lines, plus 2 tests.

Acceptance criteria

  • New tests: a url containing $1 and " round-trips to valid JSON with the exact url, and a non-hex sha1 is refused with a warning code.
  • Composer equivalence tests pass.
Lingua principale
Rust
Stelle
9
Fork
2
Merge medio
20h 47m
PR unite (30g)
681

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di SocketDev/socket-patch

Tutte le issue di SocketDev/socket-patch

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.