Skip to content

Commit 33aedfd

Browse files
committed
chore: merge main into reject-duplicate-components
2 parents c48711e + 7566559 commit 33aedfd

9 files changed

Lines changed: 923 additions & 2284 deletions

File tree

‎Cargo.lock‎

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crates/web-bot-auth/src/lib.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ pub enum ImplementationError {
5858
/// of [registered IANA signature algorithms](https://www.iana.org/assignments/http-message-signature/http-message-signature.xhtml)
5959
/// implemented here is provided by `Algorithms` struct.
6060
UnsupportedAlgorithm(Algorithm),
61+
/// The `alg` signature parameter is unknown or does not match the algorithm
62+
/// of the resolved key (RFC 9421 Section 3.2, step 6).
63+
AlgorithmMismatch,
6164
/// An attempt to resolve key identifier to a valid public key failed.
6265
/// This prevents message verification.
6366
NoSuchKey,
@@ -98,6 +101,7 @@ impl core::fmt::Display for ImplementationError {
98101
ImplementationError::UnsupportedAlgorithm(alg) => {
99102
write!(f, "unsupported algorithm: {alg:?}")
100103
}
104+
ImplementationError::AlgorithmMismatch => write!(f, "algorithm mismatch"),
101105
ImplementationError::NoSuchKey => write!(f, "no such key"),
102106
ImplementationError::InvalidKeyLength => write!(f, "invalid key length"),
103107
ImplementationError::InvalidSignatureLength => write!(f, "invalid signature length"),

‎crates/web-bot-auth/src/message_signatures.rs‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,13 @@ impl MessageVerifier {
598598
.and_then(|key| keyring.get_prepared(key)),
599599
})
600600
.ok_or(ImplementationError::NoSuchKey)?;
601+
let parameters = &self.parsed.base.parameters;
602+
if parameters.raw.get("alg").is_some()
603+
&& parameters.details.algorithm.as_ref() != Some(algorithm)
604+
&& !matches!(prepared, PreparedKey::Unsupported)
605+
{
606+
return Err(ImplementationError::AlgorithmMismatch);
607+
}
601608
let generation = UtcDateTime::now();
602609
let (base_representation, _) = self.parsed.base.into_ascii()?;
603610
let generation = (UtcDateTime::now() - generation).unsigned_abs();
@@ -772,6 +779,31 @@ mod tests {
772779
assert!(matches!(err, ImplementationError::ParsingError(_)));
773780
}
774781

782+
#[test]
783+
fn test_verifying_checks_alg_against_key() {
784+
// RFC 9421 Section 3.2, step 6.
785+
struct WithAlg(&'static str);
786+
impl SignedMessage for WithAlg {
787+
fn lookup_component(&self, name: &CoveredComponent) -> Vec<String> {
788+
(StandardTestVector {})
789+
.lookup_component(name)
790+
.into_iter()
791+
.map(|value| value.replace(r#";alg="ed25519""#, self.0))
792+
.collect()
793+
}
794+
}
795+
let keyring = keyring_with_test_key();
796+
for alg in [r#";alg="rsa-pss-sha512""#, r#";alg="foo""#] {
797+
let verifier = MessageVerifier::parse(&WithAlg(alg), |(_, _)| true).unwrap();
798+
let err = verifier.verify(&keyring, None).unwrap_err();
799+
assert!(matches!(err, ImplementationError::AlgorithmMismatch));
800+
}
801+
// Without `alg`, the key decides; the altered base then fails verification.
802+
let verifier = MessageVerifier::parse(&WithAlg(""), |(_, _)| true).unwrap();
803+
let err = verifier.verify(&keyring, None).unwrap_err();
804+
assert!(matches!(err, ImplementationError::FailedToVerify(_)));
805+
}
806+
775807
#[test]
776808
fn test_verifying_unsupported_algorithm() {
777809
let mut keyring = KeyRing::default();

‎examples/browser-extension/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
},
2929
"homepage": "https://github.com/cloudflareresearch/web-bot-auth#readme",
3030
"devDependencies": {
31-
"@types/chrome": "0.3.4",
31+
"@types/chrome": "0.3.5",
3232
"@types/libsodium-wrappers": "0.8.2",
3333
"crx": "5.0.1",
3434
"http-server": "14.1.1",

‎examples/verification-workers/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
"cf-typegen": "wrangler types"
1212
},
1313
"devDependencies": {
14-
"@cloudflare/vitest-plugin": "^1.4.0",
15-
"@cloudflare/workers-types": "^5.20260916.1",
14+
"@cloudflare/vitest-plugin": "^1.4.2",
15+
"@cloudflare/workers-types": "^5.20261014.1",
1616
"wrangler": "^4.132.0"
1717
}
1818
}

0 commit comments

Comments
 (0)