Skip to content

Find the holes before someone else does. A fast, 100% Rust vulnerability scanner: XSS, SQL injection, leaked secrets, dependency CVEs and AI agent setups.

fix(secrets): detect post-quantum age private keys (#176)

Alejandro2b4cf5136721
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2a09be1..dbfa333 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,8 +21,9 @@
followed by 48 letters and digits).
- Secrets: new rule `secret.dockerhub-token` (critical) for Docker Hub personal access tokens
(`dckr_pat_` followed by 27 letters, digits, `_` or `-`).
-- Secrets: new rule `secret.age-key` (critical) for age private keys (`AGE-SECRET-KEY-1` followed by
- 58 upper-case Bech32 characters), which decrypt every file encrypted to them, SOPS files included.
+- Secrets: new rule `secret.age-key` (critical) for age private keys (`AGE-SECRET-KEY-1` and
+ post-quantum `AGE-SECRET-KEY-PQ-1` followed by 58 upper-case Bech32 characters), which decrypt
+ every file encrypted to them, SOPS files included.
- Secrets: when a line holds more than one secret or more than one finding, all secrets on that
line are now masked in every finding on it (two tokens of one kind, tokens of different kinds, a
token beside a `NEXT_PUBLIC_` or `VITE_` secret, another rule's finding on the same line such as
diff --git a/src/rules/secrets.rs b/src/rules/secrets.rs
index 9f78cba..2e12b3b 100644
--- a/src/rules/secrets.rs
+++ b/src/rules/secrets.rs
@@ -447,7 +447,7 @@ pub static RULES: &[Rule] = &[
Critical,
// In a JSON string the key can follow an escape like `\n`, where `\b` fails
// between `n` and `A`.
- r"(?:\\[nrt]|\b)(AGE-SECRET-KEY-1[QPZRY9X8GF2TVDW0S3JN54KHCE6MUA7L]{58})\b",
+ r"(?:\\[nrt]|\b)(AGE-SECRET-KEY-(?:PQ-)?1[QPZRY9X8GF2TVDW0S3JN54KHCE6MUA7L]{58})\b",
"An age private key is written in the file."
),
secret!(
@@ -738,34 +738,35 @@ mod tests {
#[test]
fn age_key_after_json_escape() {
- let key = [
- "AGE-SECRET-",
- "KEY-1",
- &"QPZRY9X8GF2TVDW0S3JN54KHCE6MUA7L".repeat(2)[..58],
- ]
- .concat();
+ let bech32 = &"QPZRY9X8GF2TVDW0S3JN54KHCE6MUA7L".repeat(2)[..58];
+ let classic = ["AGE-SECRET-", "KEY-1", bech32].concat();
+ let pq = ["AGE-SECRET-", "KEY-PQ-1", bech32].concat();
let age = |src: &str| -> Vec<_> {
check(&FileInfo::new("keys.json"), src, false)
.into_iter()
.filter(|f| f.rule == "secret.age-key")
.collect()
};
- for src in [
- format!(r#"{{"key":"line\n{key}"}}"#),
- format!(r#"{{"key":"line\r\n{key}\n"}}"#),
- format!(r#"{{"key":"\t{key}"}}"#),
- format!("key = \"{key}\""),
- ] {
- let found = age(&src);
- assert_eq!(found.len(), 1, "{src} => {found:#?}");
- assert!(!found[0].snippet.contains(&key), "{src} => {found:#?}");
- }
- for src in [
- format!("X{key}"),
- format!("{key}Q"),
- format!(r#""line\n{key}Q""#),
- ] {
- assert!(age(&src).is_empty(), "{src}");
+ for key in [&classic, &pq] {
+ for src in [
+ format!(r#"{{"key":"line\n{key}"}}"#),
+ format!(r#"{{"key":"line\r\n{key}\n"}}"#),
+ format!(r#"{{"key":"\t{key}"}}"#),
+ format!("key = \"{key}\""),
+ ] {
+ let found = age(&src);
+ assert_eq!(found.len(), 1, "{src} => {found:#?}");
+ assert!(!found[0].snippet.contains(key), "{src} => {found:#?}");
+ }
+ for src in [
+ format!("X{key}"),
+ format!("{key}Q"),
+ format!(r#""line\n{key}Q""#),
+ ] {
+ assert!(age(&src).is_empty(), "{src}");
+ }
}
+ let recipient = format!("recipient = \"age1pq1{}\"", bech32.to_lowercase());
+ assert!(age(&recipient).is_empty(), "{recipient}");
}
}
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index 46fa6bc..0ed8a3c 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -147,6 +147,9 @@ pub fn fake(name: &str) -> String {
"age" => ["AGE-SECRET-", "KEY-1", &body(58, BECH32)].concat(),
// `B` is not in the Bech32 alphabet.
"age-not-bech32" => ["AGE-SECRET-", "KEY-1", &body(57, BECH32), "B"].concat(),
+ "age-pq" => ["AGE-SECRET-", "KEY-PQ-1", &body(58, BECH32)].concat(),
+ "age-pq-short" => ["AGE-SECRET-", "KEY-PQ-1", &body(57, BECH32)].concat(),
+ "age-pq-not-bech32" => ["AGE-SECRET-", "KEY-PQ-1", &body(57, BECH32), "B"].concat(),
"dockerhub" => ["dckr", "_pat_", &body(26, MIXED), "-"].concat(),
"heroku" => ["HR", "KU-AA", &body(57, MIXED), "-"].concat(),
"heroku-short" => ["HR", "KU-AA", &body(57, MIXED)].concat(),
diff --git a/tests/fixtures/secrets/EXPECTED b/tests/fixtures/secrets/EXPECTED
index bc40343..a9c694d 100644
--- a/tests/fixtures/secrets/EXPECTED
+++ b/tests/fixtures/secrets/EXPECTED
@@ -72,3 +72,4 @@ config.py:96 secret.perplexity-key
config.py:100 secret.notion-token
config.py:103 secret.heroku-key
config.py:105 secret.heroku-key
+config.py:106 secret.age-key
diff --git a/tests/fixtures/secrets/config.py b/tests/fixtures/secrets/config.py
index db2c92b..b2f5f72 100644
--- a/tests/fixtures/secrets/config.py
+++ b/tests/fixtures/secrets/config.py
@@ -103,3 +103,5 @@ notion_short = "{{fake:notion-short}}"
heroku = "{{fake:heroku}}"
heroku_lookalike = "{{fake:heroku-short}} {{fake:heroku-no-aa}} {{fake:heroku}}a my{{fake:heroku}}"
heroku_escaped = "line\\n{{fake:heroku}}"
+age_pq_key = "{{fake:age-pq}}"
+age_pq_lookalike = "{{fake:age-pq-short}} {{fake:age-pq-not-bech32}} {{fake:age-pq}}Q age1pq1qpzry9x8gf2tvdw0s3jn54khce6mua7lqpzry9x8gf2tvdw0s3jn54kh"