Skip to content

Commit 8f8188f

Browse files
committed
trustpub: Replace NO_VALIDATION and EMPTY_KEY with jsonwebtoken::dangerous::insecure_decode()
1 parent bdcf889 commit 8f8188f

File tree

1 file changed

+2
-25
lines changed

1 file changed

+2
-25
lines changed

crates/crates_io_trustpub/src/unverified.rs

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,6 @@
1+
use jsonwebtoken::TokenData;
12
use jsonwebtoken::errors::Error;
2-
use jsonwebtoken::{DecodingKey, TokenData, Validation};
33
use serde::Deserialize;
4-
use std::collections::HashSet;
5-
use std::sync::LazyLock;
6-
7-
/// [`Validation`] configuration for decoding JWTs without any
8-
/// signature validation.
9-
///
10-
/// **This must only be used to extract the `iss` claim from the JWT, which
11-
/// is then used to look up the corresponding OIDC key set.**
12-
static NO_VALIDATION: LazyLock<Validation> = LazyLock::new(|| {
13-
let mut no_validation = Validation::default();
14-
no_validation.validate_aud = false;
15-
no_validation.validate_exp = false;
16-
no_validation.required_spec_claims = HashSet::new();
17-
no_validation.insecure_disable_signature_validation();
18-
no_validation
19-
});
20-
21-
/// Empty [`DecodingKey`] used for decoding JWTs without any signature
22-
/// validation.
23-
///
24-
/// **This must only be used to extract the `iss` claim from the JWT, which
25-
/// is then used to look up the corresponding OIDC key set.**
26-
static EMPTY_KEY: LazyLock<DecodingKey> = LazyLock::new(|| DecodingKey::from_secret(b""));
274

285
/// Claims that are extracted from the JWT without any signature
296
/// validation. Specifically, this only extracts the `iss` claim, which is
@@ -41,7 +18,7 @@ impl UnverifiedClaims {
4118
/// **This must only be used to extract the `iss` claim from the JWT, which
4219
/// is then used to look up the corresponding OIDC key set.**
4320
pub fn decode(token: &str) -> Result<TokenData<Self>, Error> {
44-
jsonwebtoken::decode(token, &EMPTY_KEY, &NO_VALIDATION)
21+
jsonwebtoken::dangerous::insecure_decode(token)
4522
}
4623
}
4724

0 commit comments

Comments
 (0)