diff options
| author | aur-build <aur-build@localhost> | 2026-11-18 18:16:12 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-18 18:16:12 +0000 |
| commit | 2a8ce53f6754217c8e24f92a7b13190b68708d7a (patch) | |
| tree | 9d398ef68a59f59d7b19536a801a327c146a4914 | |
| parent | c712124f214fc53a57b23c10ed98e8e869cbf7c2 (diff) | |
| download | aur-build-2a8ce53f6754217c8e24f92a7b13190b68708d7a.tar.gz aur-build-2a8ce53f6754217c8e24f92a7b13190b68708d7a.zip | |
http, pipeline: form pairs parsed once, and a rebuild identity in the real format
n-3. `Req::form_get` called `form()`, which re-parsed the entire request body
every time. The approve handler asks five times — two hashes, a note, a CSRF
token, and a confirm flag — so a single POST parsed its own body five times. The
pairs are parsed once at decode, next to the query pairs, and `form()` returns
the stored slice.
n-5. `enqueue_manual_rebuild` invented its own identity format,
`hex("{aur_commit}|{recipe_hash}|manual")`, while every other identity in the
system is a `sha256:` over the canonical JSON of the identity tuple (§3). Two
formats for one concept is how a comparison quietly stops meaning anything, and
the ad-hoc one had a delimiter that can appear inside a URL-shaped value and
ignored the pins and digests that are the whole point of an identity. A rebuild
is now identified by the canonical-JSON hash of the release's actual commit,
recipe, pins and digests plus a `requested: manual_rebuild` marker — the marker
being what keeps a rebuild a distinct build from the one that landed, while
staying deterministic so that clicking rebuild twice is one build, not two.
| -rw-r--r-- | src/http/mod.rs | 14 | ||||
| -rw-r--r-- | src/pipeline/mod.rs | 24 | ||||
| -rw-r--r-- | tests/invariants.rs | 23 |
3 files changed, 54 insertions, 7 deletions
diff --git a/src/http/mod.rs b/src/http/mod.rs index 24da43f..81c526c 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -36,17 +36,22 @@ pub struct Req { pub body: String, pub cookies: Vec<(String, String)>, pub query_pairs: Vec<(String, String)>, + /// The body's form pairs, parsed once when the request is decoded (n-3). + /// `form_get` used to re-parse the whole body on every call, and a single + /// handler — approve, with its two hashes, its note and its CSRF token — + /// asks five times. + pub form_pairs: Vec<(String, String)>, /// Whether the client said it can take gzip. Used to decide whether to hand /// out the precompressed static asset. pub accept_gzip: bool, } impl Req { - pub fn form(&self) -> Vec<(String, String)> { - forms::parse(&self.body) + pub fn form(&self) -> &[(String, String)] { + &self.form_pairs } pub fn form_get(&self, key: &str) -> Option<String> { - self.form().into_iter().find(|(k, _)| k == key).map(|(_, v)| v) + self.form_pairs.iter().find(|(k, _)| k == key).map(|(_, v)| v.clone()) } pub fn query_get(&self, key: &str) -> Option<String> { self.query_pairs.iter().find(|(k, _)| k == key).map(|(_, v)| v.clone()) @@ -162,6 +167,8 @@ fn serve(state: Arc<State>, mut request: tiny_http::Request) -> std::io::Result< .find(|h| h.field.equiv("Accept-Encoding")) .map(|h| h.value.as_str().contains("gzip")) .unwrap_or(false); + // Parsed once, here, rather than per `form_get` call (n-3). + let form_pairs = forms::parse(&body); let req = Req { method: request.method().as_str().to_string(), path: percent_decode(&path), @@ -169,6 +176,7 @@ fn serve(state: Arc<State>, mut request: tiny_http::Request) -> std::io::Result< body, cookies, query_pairs: forms::parse(&query), + form_pairs, accept_gzip, }; diff --git a/src/pipeline/mod.rs b/src/pipeline/mod.rs index c3a2cb3..20648c0 100644 --- a/src/pipeline/mod.rs +++ b/src/pipeline/mod.rs @@ -283,10 +283,26 @@ pub fn enqueue_manual_rebuild(cfg: &Config, db: &Db, pkgbase: &str) -> Result<St .ok_or_else(|| Error::not_found(format!("pkgbase {pkgbase}")))?; let rel = db::accepted_release(db, pkgbase)? .ok_or_else(|| Error::invalid(format!("{pkgbase} has no accepted release")))?; - let identity = crate::hash::hex_str(&format!( - "{}|{}|manual", - rel.aur_commit, rel.recipe_hash - )); + // A manual rebuild is the accepted release asked for again, so its identity + // is derived from what that release actually is — commit, recipe, pins, + // digests — through the same canonical-JSON hash every other identity uses + // (n-5). The old version was an ad-hoc `commit|hash|manual` string: a + // different format for the same concept, with a delimiter that could appear + // inside the values, and no pins or digests at all, so two releases with the + // same recipe but different upstream commits... were distinguished only by + // luck. `requested` is what keeps a rebuild a *distinct* build from the one + // that produced the release, while staying deterministic (§8.2): clicking + // rebuild twice is one build, not two. + let identity = format!( + "sha256:{}", + crate::hash::hex(crate::hash::canonical_json(&serde_json::json!({ + "aur_commit": rel.aur_commit, + "recipe_hash": rel.recipe_hash, + "upstream_pins": rel.pins(), + "source_digests": rel.digests(), + "requested": "manual_rebuild", + }))?.as_bytes()) + ); let world = publish::index_world(db)?; let world_hash = crate::hash::canonical_json(&world)?; let id = builds::build_id(pkgbase, &identity, &world_hash, &cfg.build_profile); diff --git a/tests/invariants.rs b/tests/invariants.rs index 8026a79..1f6f7f2 100644 --- a/tests/invariants.rs +++ b/tests/invariants.rs @@ -301,6 +301,29 @@ fn i6_manual_rebuild_publishes_the_same_version_without_a_new_approval() { ); } +/// n-5: a manual rebuild's identity used to be a hand-rolled +/// `format!("{commit}|{hash}|manual}")` — a second, incompatible format for the +/// same concept, with a delimiter that can occur inside the values. It is now +/// derived through the same canonical-JSON hash as every other identity, and +/// what the change must not disturb is the two properties the queue depends on. +#[test] +fn a_manual_rebuild_is_deterministic_and_its_own_build() { + let (env, _fx) = env_with_fixture("plain-make"); + full_run(&env, "plain-make"); + let original = env + .query_str("SELECT id FROM build ORDER BY rowid LIMIT 1", &[]) + .expect("the published build"); + let a = pipeline::enqueue_manual_rebuild(&env.cfg, &env.db, "plain-make").unwrap(); + let b = pipeline::enqueue_manual_rebuild(&env.cfg, &env.db, "plain-make").unwrap(); + assert_eq!(a, b, "clicking rebuild twice is one build, not two (§8.2)"); + assert_ne!(a, original, "a rebuild is a distinct build from the one that landed"); + assert_eq!( + count(&env, "SELECT count(*) FROM build"), + 2, + "the second call must not enqueue a third row" + ); +} + /// **I10 — the audit log is append-only**, and every consequential action is in it. #[test] fn i10_audit_is_append_only_and_records_the_decisions() { |
