Find the holes before someone else does. A fast, 100% Rust vulnerability scanner: XSS, SQL injection, leaked secrets, dependency CVEs and AI agent setups.
Rust ai-agentsclaude-codeclaude-code-pluginclicodexcursordevsecopsmcposvowasprustsastsecret-scanningsecretssecuritysecurity-scannersql-injectionvulnerabilityvulnerability-scannerxss
feat(config): flag public and unencrypted databases in Terraform (#109)
Onur Ugurec34dffc3be8
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 7722c40..92fa8d3 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -43,6 +43,8 @@`restrict_public_buckets = false` in an `aws_s3_bucket_public_access_block` or `aws_s3_account_public_access_block`.- Secrets: new rule `secret.groq-key` (critical) for Groq API keys (`gsk_` followed by 52 letters or digits).- Code: new rule `code.open-redirect` (medium) for redirects built straight from request input (`res.redirect(req.query.next)`, `redirect(request.args.get("next"))`); a redirect to a fixed path stays unflagged.+- Config: new rules `config.tf-public-database` (high) for `publicly_accessible = true` and `config.tf-unencrypted-storage` (medium)+ for `storage_encrypted = false` in Terraform files. `publicly_accessible = false`, `storage_encrypted = true` and commented-out lines stay unflagged.- Config: `config.remote-script` also checks GitHub Actions workflows, so a `run:` step (or a line in a`run: |` block) that pipes `curl` or `wget` into a shell is reported. `curl -o file URL`, a step `name:` and acommented-out line are not.diff --git a/README.md b/README.mdindex 20d3634..86f3c29 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 88 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 90 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/er-kam">CodeRabbit</a></p><p align="center">@@ -86,7 +86,7 @@ safe-anything --list-rules## What it finds-88 rules, each with a CWE id, an OWASP category and a link to the OWASP page that explains it.+90 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).| | |@@ -175,7 +175,7 @@ lockfile listed under Dependencies. Nothing is executed. The only network call inames 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 88 problems were found, not that the code is safe. [Design notes](docs/adr).+these 90 problems were found, not that the code is safe. [Design notes](docs/adr).## Creditsdiff --git a/docs/rules.md b/docs/rules.mdindex 26ff3ac..5cf29a7 100644--- a/docs/rules.md+++ b/docs/rules.md@@ -93,7 +93,7 @@ Every rule safe-anything checks, generated from `safe-anything --list-rules --js| [`mobile.ios-ats-disabled`](https://mas.owasp.org/MASVS/08-MASVS-NETWORK/) | high | [CWE-319](https://cwe.mitre.org/data/definitions/319.html) | MASVS-NETWORK | App Transport Security is off, so the app may load anything over plain HTTP. || [`mobile.insecure-storage`](https://mas.owasp.org/MASVS/05-MASVS-STORAGE/) | medium | [CWE-922](https://cwe.mitre.org/data/definitions/922.html) | MASVS-STORAGE | A token or password is saved in plain storage that other code, backups or XSS can read. |-## Config (16)+## Config (18)| Rule | Severity | CWE | OWASP | What it means || --- | --- | --- | --- | --- |@@ -111,6 +111,8 @@ Every rule safe-anything checks, generated from `safe-anything --list-rules --js| [`config.tf-open-ingress`](https://cheatsheetseries.owasp.org/cheatsheets/Infrastructure_as_Code_Security_Cheat_Sheet.html) | medium | [CWE-284](https://cwe.mitre.org/data/definitions/284.html) | A01:2021 Broken Access Control | A network rule is open to the whole internet. || [`config.tf-public-bucket`](https://cheatsheetseries.owasp.org/cheatsheets/Infrastructure_as_Code_Security_Cheat_Sheet.html) | high | [CWE-284](https://cwe.mitre.org/data/definitions/284.html) | A01:2021 Broken Access Control | A storage bucket is public. || [`config.tf-public-access-block`](https://cheatsheetseries.owasp.org/cheatsheets/Infrastructure_as_Code_Security_Cheat_Sheet.html) | medium | [CWE-284](https://cwe.mitre.org/data/definitions/284.html) | A01:2021 Broken Access Control | An S3 public access block is turned off, so a bucket policy can make the bucket (or every bucket in the account) public. |+| [`config.tf-public-database`](https://cheatsheetseries.owasp.org/cheatsheets/Infrastructure_as_Code_Security_Cheat_Sheet.html) | high | [CWE-284](https://cwe.mitre.org/data/definitions/284.html) | A01:2021 Broken Access Control | A database gets a public IP address, so only its security group stands between it and the internet. |+| [`config.tf-unencrypted-storage`](https://cheatsheetseries.owasp.org/cheatsheets/Cryptographic_Storage_Cheat_Sheet.html) | medium | [CWE-311](https://cwe.mitre.org/data/definitions/311.html) | A02:2021 Cryptographic Failures | A database's storage is not encrypted at rest, so its snapshots and backups are not encrypted either. || [`config.nginx-autoindex`](https://cheatsheetseries.owasp.org/cheatsheets/Attack_Surface_Analysis_Cheat_Sheet.html) | low | [CWE-548](https://cwe.mitre.org/data/definitions/548.html) | A05:2021 Security Misconfiguration | Directory listing is on, so every file in the folder can be browsed. || [`config.weak-tls-version`](https://cheatsheetseries.owasp.org/cheatsheets/Transport_Layer_Security_Cheat_Sheet.html) | medium | [CWE-326](https://cwe.mitre.org/data/definitions/326.html) | A02:2021 Cryptographic Failures | Old TLS or SSL versions are enabled; they have known attacks. |diff --git a/src/refs.rs b/src/refs.rsindex b89290f..694900f 100644--- a/src/refs.rs+++ b/src/refs.rs@@ -233,13 +233,21 @@ pub fn of(id: &str) -> Refs {"config.gha-script-injection" => {r!("CWE-78", "A03:2021 Injection", "CI_CD_Security_Cheat_Sheet")}- "config.tf-open-ingress" | "config.tf-public-bucket" | "config.tf-public-access-block" => {+ "config.tf-open-ingress"+ | "config.tf-public-bucket"+ | "config.tf-public-access-block"+ | "config.tf-public-database" => {r!("CWE-284","A01:2021 Broken Access Control","Infrastructure_as_Code_Security_Cheat_Sheet")}+ "config.tf-unencrypted-storage" => r!(+ "CWE-311",+ "A02:2021 Cryptographic Failures",+ "Cryptographic_Storage_Cheat_Sheet"+ ),"config.nginx-autoindex" => r!("CWE-548","A05:2021 Security Misconfiguration",diff --git a/src/rules/config.rs b/src/rules/config.rsindex 661f913..fa5b280 100644--- a/src/rules/config.rs+++ b/src/rules/config.rs@@ -176,6 +176,24 @@ pub static RULES: &[Rule] = &["An S3 public access block is turned off, so a bucket policy can make the bucket (or every bucket in the account) public.","Set block_public_policy and restrict_public_buckets to true. Ignore for a bucket that serves a public website on purpose."),+ rule!(+ "config.tf-public-database",+ High,+ terraform,+ r#"(?m)^[ \t]*publicly_accessible[ \t]*=[ \t]*(?:true|"true")[ \t]*(?:\r?$|#|//|/\*)"#,+ None,+ "A database gets a public IP address, so only its security group stands between it and the internet.",+ "Set publicly_accessible = false and reach the database from inside its network, through a bastion host or a VPN."+ ),+ rule!(+ "config.tf-unencrypted-storage",+ Medium,+ terraform,+ r#"(?m)^[ \t]*storage_encrypted[ \t]*=[ \t]*(?:false|"false")[ \t]*(?:\r?$|#|//|/\*)"#,+ None,+ "A database's storage is not encrypted at rest, so its snapshots and backups are not encrypted either.",+ "Set storage_encrypted = true, with a kms_key_id if you manage your own keys."+ ),rule!("config.nginx-autoindex",Low,diff --git a/tests/fixtures/config/EXPECTED b/tests/fixtures/config/EXPECTEDindex a936bc2..bda1501 100644--- a/tests/fixtures/config/EXPECTED+++ b/tests/fixtures/config/EXPECTED@@ -15,6 +15,8 @@ Dockerfile:8 config.docker-root-userdocker-compose.yml:3 config.privileged-containerinfra/main.tf:3 config.tf-open-ingressinfra/main.tf:6 config.tf-public-bucket+infra/main.tf:34 config.tf-public-database+infra/main.tf:35 config.tf-unencrypted-storageinfra/main.tf:11 config.tf-public-access-blockinfra/main.tf:13 config.tf-public-access-blockinfra/main.tf:17 config.tf-public-access-blockdiff --git a/tests/fixtures/config/infra/main.tf b/tests/fixtures/config/infra/main.tfindex 9b65387..b2e0f45 100644--- a/tests/fixtures/config/infra/main.tf+++ b/tests/fixtures/config/infra/main.tf@@ -30,3 +30,12 @@ resource "aws_s3_access_point" "reports" {restrict_public_buckets = false}}+resource "aws_db_instance" "d" {+ publicly_accessible = true+ storage_encrypted = false+}+resource "aws_db_instance" "private" {+ publicly_accessible = false+ storage_encrypted = true # was = false+ # publicly_accessible = true+}