feat(sast): hard-coded credentials in #define macros (#374) #392

Merged
sharang merged 1 commits from feat/define-credentials into main 2026-09-25 11:16:33 +00:00
3 changed files with 18 additions and 3 deletions

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