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.

feat(secrets): detect GitLab personal access tokens (#18)

Mingde4d8b2bd1c7
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 76d7982..0d7f0b6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,7 @@
## Unreleased
+- Secrets: new rule `secret.gitlab-token` (critical) for GitLab personal access tokens (`glpat-` followed by 20 characters).
- Secrets: new rule `secret.npm-token` (critical) for npm access tokens (`npm_` followed by 36 letters or digits).
- Dependencies: `uv.lock` entries whose `source` is `editable`, `virtual` or `path` (the project itself or a
local package) are no longer counted or looked up on PyPI.
diff --git a/README.md b/README.md
index 7317df2..0fecb0b 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@ Every finding comes with the line, the reason and the fix.</p>
<a href="https://github.com/erkamyaman/safe-anything"><img src="https://img.shields.io/github/stars/erkamyaman/safe-anything?style=social" alt="GitHub stars"></a>
</p>
-<p align="center"><b><a href="#quick-start">Install</a></b> · <a href="https://github.com/erkamyaman/safe-anything/releases">Releases</a> · <a href="#for-ai-agents">Claude Code plugin</a> · <a href="#in-ci">GitHub Action</a> · <a href="docs/rules.md">All 72 rules</a> · <a href="docs/agent-setups.md">Agent setups</a><br>
+<p align="center"><b><a href="#quick-start">Install</a></b> · <a href="https://github.com/erkamyaman/safe-anything/releases">Releases</a> · <a href="#for-ai-agents">Claude Code plugin</a> · <a href="#in-ci">GitHub Action</a> · <a href="docs/rules.md">All 74 rules</a> · <a href="docs/agent-setups.md">Agent setups</a><br>
Made in Türkiye 🇹🇷 by <a href="https://github.com/erkamyaman">erKam Yaman</a>, who also made <a href="https://github.com/erkamyaman/rust-anything">rust-anything</a> · <a href="https://github.com/sponsors/erkamyaman">❤️ Sponsor me</a> · Sponsored by <a href="https://coderabbit.link/erkamyaman">CodeRabbit</a></p>
<p align="center">
@@ -78,7 +78,7 @@ safe-anything --list-rules
## What it finds
-72 rules, each with a CWE id, an OWASP category and a link to the OWASP page that explains it.
+74 rules, each with a CWE id, an OWASP category and a link to the OWASP page that explains it.
The full list is in [docs/rules.md](docs/rules.md).
| | |
@@ -167,7 +167,7 @@ formats. Nothing is executed. The only network call is the dependency check, whi
names and versions to OSV.dev ([privacy](docs/privacy.md)).
It finds known patterns; it does not trace data through your program. A clean scan means none of
-these 72 problems were found, not that the code is safe. [Design notes](docs/adr).
+these 74 problems were found, not that the code is safe. [Design notes](docs/adr).
## Credits
diff --git a/docs/rules.md b/docs/rules.md
index 9085bd9..5123cf0 100644
--- a/docs/rules.md
+++ b/docs/rules.md
@@ -31,12 +31,13 @@ Every rule safe-anything checks, generated from `safe-anything --list-rules --js
| [`code.sql-grant-all`](https://cheatsheetseries.owasp.org/cheatsheets/Database_Security_Cheat_Sheet.html) | medium | [CWE-250](https://cwe.mitre.org/data/definitions/250.html) | A01:2021 Broken Access Control | A database user gets every privilege on every database. |
| [`code.sql-plaintext-password`](https://cheatsheetseries.owasp.org/cheatsheets/Database_Security_Cheat_Sheet.html) | medium | [CWE-798](https://cwe.mitre.org/data/definitions/798.html) | A07:2021 Identification and Authentication Failures | A database password is written in a SQL file. |
-## Secrets (14)
+## Secrets (16)
| Rule | Severity | CWE | OWASP | What it means |
| --- | --- | --- | --- | --- |
| [`secret.aws-access-key`](https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html) | critical | [CWE-798](https://cwe.mitre.org/data/definitions/798.html) | A07:2021 Identification and Authentication Failures | An AWS access key id is written in the file. |
| [`secret.github-token`](https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html) | critical | [CWE-798](https://cwe.mitre.org/data/definitions/798.html) | A07:2021 Identification and Authentication Failures | A GitHub token is written in the file. |
+| [`secret.gitlab-token`](https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html) | critical | [CWE-798](https://cwe.mitre.org/data/definitions/798.html) | A07:2021 Identification and Authentication Failures | A GitLab personal access token is written in the file. |
| [`secret.slack-token`](https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html) | high | [CWE-798](https://cwe.mitre.org/data/definitions/798.html) | A07:2021 Identification and Authentication Failures | A Slack token is written in the file. |
| [`secret.stripe-live-key`](https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html) | critical | [CWE-798](https://cwe.mitre.org/data/definitions/798.html) | A07:2021 Identification and Authentication Failures | A live Stripe secret key is written in the file. |
| [`secret.npm-token`](https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html) | critical | [CWE-798](https://cwe.mitre.org/data/definitions/798.html) | A07:2021 Identification and Authentication Failures | An npm access token is written in the file. |
diff --git a/src/rules/secrets.rs b/src/rules/secrets.rs
index 6301fb8..8670351 100644
--- a/src/rules/secrets.rs
+++ b/src/rules/secrets.rs
@@ -99,6 +99,12 @@ pub static RULES: &[Rule] = &[
r"\b(gh[pousr]_[A-Za-z0-9]{36,}|github_pat_[A-Za-z0-9_]{60,})",
"A GitHub token is written in the file."
),
+ secret!(
+ "secret.gitlab-token",
+ Critical,
+ r"\bglpat-[0-9a-zA-Z_\-]{20}",
+ "A GitLab personal access token is written in the file."
+ ),
secret!(
"secret.slack-token",
High,
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index 483db7f..e03f73f 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -12,6 +12,7 @@ pub fn fake(name: &str) -> String {
match name {
"aws" => ["AK", "IA", &body(16, UPPER)].concat(),
"github" => ["gh", "p_", &body(36, MIXED)].concat(),
+ "gitlab" => ["gl", "pat-", &body(20, MIXED)].concat(),
"github-pat" => ["github", "_pat_", &body(82, MIXED)].concat(),
"slack" => [
"xo",
diff --git a/tests/fixtures/secrets/EXPECTED b/tests/fixtures/secrets/EXPECTED
index ea61956..9ec6e17 100644
--- a/tests/fixtures/secrets/EXPECTED
+++ b/tests/fixtures/secrets/EXPECTED
@@ -16,3 +16,4 @@ keys/deploy.pem:1 secret.private-key
app/client.ts:1 secret.public-env-secret
app/client.ts:2 secret.public-env-secret
config.py:17 secret.npm-token
+config.py:18 secret.gitlab-token
diff --git a/tests/fixtures/secrets/config.py b/tests/fixtures/secrets/config.py
index 30e70ca..ef1bd57 100644
--- a/tests/fixtures/secrets/config.py
+++ b/tests/fixtures/secrets/config.py
@@ -15,3 +15,4 @@ api_key = "${API_KEY}"
secret = "your-secret-here"
token = ""
npm_token = "{{fake:npm}}"
+gitlab_token = "{{fake:gitlab}}"