feat(sast): hard-coded credentials in #define macros (#374)
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 8m33s

The C credential rule only matched variable initialisers, so the usual
`#define WIFI_PASS "..."` in a config header went unnoticed. A regex
alternative now covers #define lines in C and C++, PASS counts as a
credential name, and placeholders (changeme, YOUR_..., xxx) are
ignored. The nightly C fixture gains a config header with one real and
one placeholder credential.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
This commit is contained in:
Sharang ParnerkarandClaude Opus 5.5 committed 2026-09-25 13:01:45 +02:00
1 parent 9a0d690036
commit 5a5d7d11ee
3 files changed
+18 -3

No files matched your search

+6 -2
View File
@@ -188,12 +188,16 @@ rules:
- pattern: $TYPE *$NAME = "$VALUE";
- pattern: $TYPE $NAME[] = "$VALUE";
- pattern: $TYPE $NAME[$N] = "$VALUE";
# The usual embedded style: a macro in a config header
# (`#define WIFI_PASS "..."`), which semgrep's C patterns do not see.
- pattern-regex: '(?m)^[ \t]*#[ \t]*define[ \t]+(?P<NAME>\w+)[ \t]+"(?P<VALUE>[^"]*)"'
- metavariable-regex:
metavariable: $NAME
regex: (?i).*(passw|passwd|pwd|secret|api_?key|token|psk|credential).*
regex: (?i).*((^|_)pass($|_)|passw|pwd|secret|api_?key|token|psk|credential).*
# Six characters or more, and not a placeholder left for the installer.
- metavariable-regex:
metavariable: $VALUE
regex: .{6,}
regex: ^(?!(?i:changeme|change_me|password|secret|admin|x{3,}|your_\w*|<[^>]*>|\*+)$).{6,}$
- id: cra-ai-13-c-broken-hash-or-cipher
languages: [c, cpp]
@@ -19,7 +19,8 @@
"semgrep:cra-ai-20-c-unbounded-string-function comms.c:25",
"semgrep:cra-ai-8-c-hardcoded-credential cli.cpp:8",
"semgrep:cra-ai-8-c-hardcoded-credential comms.c:10",
"semgrep:cra-ai-8-c-hardcoded-credential comms.c:9"
"semgrep:cra-ai-8-c-hardcoded-credential comms.c:9",
"semgrep:cra-ai-8-c-hardcoded-credential net_config.h:7"
],
"cves": [],
"registry_rules": []
@@ -0,0 +1,10 @@
/* Network settings for the sensor node, as they are often shipped: in a
* header. Planted for the nightly: one real credential, one placeholder. */
#ifndef NET_CONFIG_H
#define NET_CONFIG_H
#define MQTT_HOST "broker.example.com"
#define MQTT_PASSWORD "sensor-Mq77!"
#define OTA_TOKEN "changeme"
#endif