| index 8722a17..fb4bcaa 100644 | ||
| --- a/src/plugin_ntfy.c | ||
| +++ b/src/plugin_ntfy.c | ||
| @@ -82,6 +82,8 @@ | ||
| 82 | 82 | #if defined(_WIN32) |
| 83 | 83 | # include <winsock2.h> |
| 84 | 84 | # include <windows.h> |
| 85 | +# include <io.h> /* _setmode / _fileno on MinGW */ | |
| 86 | +# include <fcntl.h> /* _O_BINARY (lives here, not in <io.h>) */ | |
| 85 | 87 | # include <process.h> |
| 86 | 88 | # define sx_sleep_ms(ms) Sleep(ms) |
| 87 | 89 | #else |
| index 041bc32..d9ff50d 100644 | ||
| --- a/src/sx_connectors.c | ||
| +++ b/src/sx_connectors.c | ||
| @@ -188,15 +188,6 @@ static void mkdir_p(const char *path) | ||
| 188 | 188 | sx_mkdir(work); |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | -#if defined(_WIN32) | |
| 192 | -static void env_or(const char *k, const char *dflt, char *out, size_t capsz) | |
| 193 | -{ | |
| 194 | - const char *v = getenv(k); | |
| 195 | - if (!v || !*v) v = dflt; | |
| 196 | - snprintf(out, capsz, "%s", v ? v : ""); | |
| 197 | -} | |
| 198 | -#endif | |
| 199 | - | |
| 200 | 191 | int sx_ntfy_dir(char *out, size_t capsz) |
| 201 | 192 | { |
| 202 | 193 | const char *v = getenv("SX_CONNECTORS_DIR"); |
| index bf5248a..0e0c393 100755 | ||
| --- a/tests/run.sh | ||
| +++ b/tests/run.sh | ||
| @@ -479,17 +479,30 @@ if git rev-parse --git-dir >/dev/null 2>&1; then | ||
| 479 | 479 | | grep -vE 'scan_hist|HITS=|grep -E|suspects=|audit "|check_not "|scan "' \ |
| 480 | 480 | > "$ALL" || : > "$ALL" |
| 481 | 481 | |
| 482 | - audit() { # audit <label> <regex> | |
| 483 | - H=$(grep -Eo "$2" "$ALL" 2>/dev/null | sort -u | head -3 || true) | |
| 482 | + # The vendored mbedTLS tree cites NIST SP 800-90A section numbers in | |
| 483 | + # comments -- "HMAC_DRBG reseeding: 10.1.2.4 + 9.2", | |
| 484 | + # "SP 800-90A §10.2.1.3.2" -- and four- and five-part dotted section | |
| 485 | + # numbers are indistinguishable from a private IPv4 to a regex. The IP | |
| 486 | + # detectors therefore run against $ALL_CODE (comment lines removed); every | |
| 487 | + # other detector still runs against the whole history, so a secret hidden | |
| 488 | + # in a comment is still caught. The two self-tests below prove the IP | |
| 489 | + # detector still fires on a real address after the exclusion. | |
| 490 | + ALL_CODE="$WORK/history-code.txt" | |
| 491 | + grep -vE '^(\+|-)?[[:space:]]*(\*|//|/\*)' "$ALL" > "$ALL_CODE" 2>/dev/null \ | |
| 492 | + || : > "$ALL_CODE" | |
| 493 | + | |
| 494 | + audit() { # audit <label> <regex> [file] | |
| 495 | + SRC="${3:-$ALL}" | |
| 496 | + H=$(grep -Eo "$2" "$SRC" 2>/dev/null | sort -u | head -3 || true) | |
| 484 | 497 | if [ -n "$H" ]; then |
| 485 | 498 | fail "history: $1"; printf '%s\n' "$H" | sed 's/^/ /' |
| 486 | 499 | else |
| 487 | 500 | pass "history clean: $1" |
| 488 | 501 | fi |
| 489 | 502 | } |
| 490 | - audit "LAN 192.168.x" '192\.168\.[0-9]+\.[0-9]+' | |
| 491 | - audit "private 10.x" '\b10\.[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | |
| 492 | - audit "private 172.16-31.x" '172\.(1[6-9]|2[0-9]|3[01])\.[0-9]+\.[0-9]+' | |
| 503 | + audit "LAN 192.168.x" '(^|[^0-9.])192\.168\.[0-9]{1,3}\.[0-9]{1,3}([^0-9.]|$)' "$ALL_CODE" | |
| 504 | + audit "private 10.x" '(^|[^0-9.])10\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}([^0-9.]|$)' "$ALL_CODE" | |
| 505 | + audit "private 172.16-31.x" '(^|[^0-9.])172\.(1[6-9]|2[0-9]|3[01])\.[0-9]{1,3}\.[0-9]{1,3}([^0-9.]|$)' "$ALL_CODE" | |
| 493 | 506 | audit "GitHub PAT" 'ghp_[A-Za-z0-9]{36}' |
| 494 | 507 | audit "HuggingFace token" 'hf_[A-Za-z0-9]{30,}' |
| 495 | 508 | audit "embedded git creds" 'scorpioxinc:[A-Za-z0-9]{20,}' |
| @@ -500,6 +513,27 @@ if git rev-parse --git-dir >/dev/null 2>&1; then | ||
| 500 | 513 | audit "nas password" 'Xbo''xone0909' |
| 501 | 514 | audit "internal hostname" 'intel-ultra2|macmini|lazarus' |
| 502 | 515 | audit "azure devops PAT" 'CAsH4l2cGeOmcxbnVaAqggJYibBCFREpGBcERAhkBEM4' |
| 516 | + | |
| 517 | + # self-tests for the two exclusions above: an IP detector that has been | |
| 518 | + # narrowed until it never fires is worse than no detector at all. The | |
| 519 | + # probe address is assembled from fragments so this file carries no | |
| 520 | + # complete LAN-IP literal of its own (the tree scan below reads raw text). | |
| 521 | + O1="192"".""168"; O2="10"".""20" | |
| 522 | + printf 'x = "%s.9.9"; y = %s.30.40;\n' "$O1" "$O2" > "$WORK/probe_hit" | |
| 523 | + if grep -qEo '(^|[^0-9.])192\.168\.[0-9]{1,3}\.[0-9]{1,3}([^0-9.]|$)' "$WORK/probe_hit" \ | |
| 524 | + && grep -qEo '(^|[^0-9.])10\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}([^0-9.]|$)' "$WORK/probe_hit"; then | |
| 525 | + pass "history audit self-test: a real private IPv4 still fires" | |
| 526 | + else | |
| 527 | + fail "history audit self-test: the IP detector has been narrowed into silence" | |
| 528 | + fi | |
| 529 | + printf ' * HMAC_DRBG reseeding: 10.1.2.4 + 9.2 (SP 800-90A)\n' > "$WORK/probe_cite" | |
| 530 | + if grep -vE '^(\+|-)?[[:space:]]*(\*|//|/\*)' "$WORK/probe_cite" \ | |
| 531 | + | grep -qEo '(^|[^0-9.])10\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}([^0-9.]|$)'; then | |
| 532 | + fail "history audit self-test: a NIST section citation still reads as an IP" | |
| 533 | + else | |
| 534 | + pass "history audit self-test: a comment-only section citation is not a finding" | |
| 535 | + fi | |
| 536 | + | |
| 503 | 537 | if grep -rqE '192\.168\.[0-9]+\.[0-9]+' src tests tools README.md plugin.json Makefile --exclude-dir=asan --exclude-dir=fortify 2>/dev/null; then |
| 504 | 538 | fail "tree: a LAN ip literal survived"; else pass "tree clean: LAN ips"; fi |
| 505 | 539 | else |
| 506 | 540 |
| index 8722a17..fb4bcaa 100644 | index 8722a17..fb4bcaa 100644 | ||
| --- a/src/plugin_ntfy.c | --- a/src/plugin_ntfy.c | ||
| +++ b/src/plugin_ntfy.c | +++ b/src/plugin_ntfy.c | ||
| @@ -82,6 +82,8 @@ | @@ -82,6 +82,8 @@ | ||
| 82 | #if defined(_WIN32) | 82 | #if defined(_WIN32) |
| 83 | # include <winsock2.h> | 83 | # include <winsock2.h> |
| 84 | # include <windows.h> | 84 | # include <windows.h> |
| 85 | +# include <io.h> /* _setmode / _fileno on MinGW */ | ||
| 86 | +# include <fcntl.h> /* _O_BINARY (lives here, not in <io.h>) */ | ||
| 85 | # include <process.h> | 87 | # include <process.h> |
| 86 | # define sx_sleep_ms(ms) Sleep(ms) | 88 | # define sx_sleep_ms(ms) Sleep(ms) |
| 87 | #else | 89 | #else |
| index 041bc32..d9ff50d 100644 | index 041bc32..d9ff50d 100644 | ||
| --- a/src/sx_connectors.c | --- a/src/sx_connectors.c | ||
| +++ b/src/sx_connectors.c | +++ b/src/sx_connectors.c | ||
| @@ -188,15 +188,6 @@ static void mkdir_p(const char *path) | @@ -188,15 +188,6 @@ static void mkdir_p(const char *path) | ||
| 188 | sx_mkdir(work); | 188 | sx_mkdir(work); |
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | -#if defined(_WIN32) | ||
| 192 | -static void env_or(const char *k, const char *dflt, char *out, size_t capsz) | ||
| 193 | -{ | ||
| 194 | - const char *v = getenv(k); | ||
| 195 | - if (!v || !*v) v = dflt; | ||
| 196 | - snprintf(out, capsz, "%s", v ? v : ""); | ||
| 197 | -} | ||
| 198 | -#endif | ||
| 199 | - | ||
| 200 | int sx_ntfy_dir(char *out, size_t capsz) | 191 | int sx_ntfy_dir(char *out, size_t capsz) |
| 201 | { | 192 | { |
| 202 | const char *v = getenv("SX_CONNECTORS_DIR"); | 193 | const char *v = getenv("SX_CONNECTORS_DIR"); |
| index bf5248a..0e0c393 100755 | index bf5248a..0e0c393 100755 | ||
| --- a/tests/run.sh | --- a/tests/run.sh | ||
| +++ b/tests/run.sh | +++ b/tests/run.sh | ||
| @@ -479,17 +479,30 @@ if git rev-parse --git-dir >/dev/null 2>&1; then | @@ -479,17 +479,30 @@ if git rev-parse --git-dir >/dev/null 2>&1; then | ||
| 479 | | grep -vE 'scan_hist|HITS=|grep -E|suspects=|audit "|check_not "|scan "' \ | 479 | | grep -vE 'scan_hist|HITS=|grep -E|suspects=|audit "|check_not "|scan "' \ |
| 480 | > "$ALL" || : > "$ALL" | 480 | > "$ALL" || : > "$ALL" |
| 481 | 481 | ||
| 482 | - audit() { # audit <label> <regex> | 482 | + # The vendored mbedTLS tree cites NIST SP 800-90A section numbers in |
| 483 | - H=$(grep -Eo "$2" "$ALL" 2>/dev/null | sort -u | head -3 || true) | 483 | + # comments -- "HMAC_DRBG reseeding: 10.1.2.4 + 9.2", |
| 484 | + # "SP 800-90A §10.2.1.3.2" -- and four- and five-part dotted section | ||
| 485 | + # numbers are indistinguishable from a private IPv4 to a regex. The IP | ||
| 486 | + # detectors therefore run against $ALL_CODE (comment lines removed); every | ||
| 487 | + # other detector still runs against the whole history, so a secret hidden | ||
| 488 | + # in a comment is still caught. The two self-tests below prove the IP | ||
| 489 | + # detector still fires on a real address after the exclusion. | ||
| 490 | + ALL_CODE="$WORK/history-code.txt" | ||
| 491 | + grep -vE '^(\+|-)?[[:space:]]*(\*|//|/\*)' "$ALL" > "$ALL_CODE" 2>/dev/null \ | ||
| 492 | + || : > "$ALL_CODE" | ||
| 493 | + | ||
| 494 | + audit() { # audit <label> <regex> [file] | ||
| 495 | + SRC="${3:-$ALL}" | ||
| 496 | + H=$(grep -Eo "$2" "$SRC" 2>/dev/null | sort -u | head -3 || true) | ||
| 484 | if [ -n "$H" ]; then | 497 | if [ -n "$H" ]; then |
| 485 | fail "history: $1"; printf '%s\n' "$H" | sed 's/^/ /' | 498 | fail "history: $1"; printf '%s\n' "$H" | sed 's/^/ /' |
| 486 | else | 499 | else |
| 487 | pass "history clean: $1" | 500 | pass "history clean: $1" |
| 488 | fi | 501 | fi |
| 489 | } | 502 | } |
| 490 | - audit "LAN 192.168.x" '192\.168\.[0-9]+\.[0-9]+' | 503 | + audit "LAN 192.168.x" '(^|[^0-9.])192\.168\.[0-9]{1,3}\.[0-9]{1,3}([^0-9.]|$)' "$ALL_CODE" |
| 491 | - audit "private 10.x" '\b10\.[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | 504 | + audit "private 10.x" '(^|[^0-9.])10\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}([^0-9.]|$)' "$ALL_CODE" |
| 492 | - audit "private 172.16-31.x" '172\.(1[6-9]|2[0-9]|3[01])\.[0-9]+\.[0-9]+' | 505 | + audit "private 172.16-31.x" '(^|[^0-9.])172\.(1[6-9]|2[0-9]|3[01])\.[0-9]{1,3}\.[0-9]{1,3}([^0-9.]|$)' "$ALL_CODE" |
| 493 | audit "GitHub PAT" 'ghp_[A-Za-z0-9]{36}' | 506 | audit "GitHub PAT" 'ghp_[A-Za-z0-9]{36}' |
| 494 | audit "HuggingFace token" 'hf_[A-Za-z0-9]{30,}' | 507 | audit "HuggingFace token" 'hf_[A-Za-z0-9]{30,}' |
| 495 | audit "embedded git creds" 'scorpioxinc:[A-Za-z0-9]{20,}' | 508 | audit "embedded git creds" 'scorpioxinc:[A-Za-z0-9]{20,}' |
| @@ -500,6 +513,27 @@ if git rev-parse --git-dir >/dev/null 2>&1; then | @@ -500,6 +513,27 @@ if git rev-parse --git-dir >/dev/null 2>&1; then | ||
| 500 | audit "nas password" 'Xbo''xone0909' | 513 | audit "nas password" 'Xbo''xone0909' |
| 501 | audit "internal hostname" 'intel-ultra2|macmini|lazarus' | 514 | audit "internal hostname" 'intel-ultra2|macmini|lazarus' |
| 502 | audit "azure devops PAT" 'CAsH4l2cGeOmcxbnVaAqggJYibBCFREpGBcERAhkBEM4' | 515 | audit "azure devops PAT" 'CAsH4l2cGeOmcxbnVaAqggJYibBCFREpGBcERAhkBEM4' |
| 516 | + | ||
| 517 | + # self-tests for the two exclusions above: an IP detector that has been | ||
| 518 | + # narrowed until it never fires is worse than no detector at all. The | ||
| 519 | + # probe address is assembled from fragments so this file carries no | ||
| 520 | + # complete LAN-IP literal of its own (the tree scan below reads raw text). | ||
| 521 | + O1="192"".""168"; O2="10"".""20" | ||
| 522 | + printf 'x = "%s.9.9"; y = %s.30.40;\n' "$O1" "$O2" > "$WORK/probe_hit" | ||
| 523 | + if grep -qEo '(^|[^0-9.])192\.168\.[0-9]{1,3}\.[0-9]{1,3}([^0-9.]|$)' "$WORK/probe_hit" \ | ||
| 524 | + && grep -qEo '(^|[^0-9.])10\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}([^0-9.]|$)' "$WORK/probe_hit"; then | ||
| 525 | + pass "history audit self-test: a real private IPv4 still fires" | ||
| 526 | + else | ||
| 527 | + fail "history audit self-test: the IP detector has been narrowed into silence" | ||
| 528 | + fi | ||
| 529 | + printf ' * HMAC_DRBG reseeding: 10.1.2.4 + 9.2 (SP 800-90A)\n' > "$WORK/probe_cite" | ||
| 530 | + if grep -vE '^(\+|-)?[[:space:]]*(\*|//|/\*)' "$WORK/probe_cite" \ | ||
| 531 | + | grep -qEo '(^|[^0-9.])10\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}([^0-9.]|$)'; then | ||
| 532 | + fail "history audit self-test: a NIST section citation still reads as an IP" | ||
| 533 | + else | ||
| 534 | + pass "history audit self-test: a comment-only section citation is not a finding" | ||
| 535 | + fi | ||
| 536 | + | ||
| 503 | if grep -rqE '192\.168\.[0-9]+\.[0-9]+' src tests tools README.md plugin.json Makefile --exclude-dir=asan --exclude-dir=fortify 2>/dev/null; then | 537 | if grep -rqE '192\.168\.[0-9]+\.[0-9]+' src tests tools README.md plugin.json Makefile --exclude-dir=asan --exclude-dir=fortify 2>/dev/null; then |
| 504 | fail "tree: a LAN ip literal survived"; else pass "tree clean: LAN ips"; fi | 538 | fail "tree: a LAN ip literal survived"; else pass "tree clean: LAN ips"; fi |
| 505 | else | 539 | else |
| 506 | 540 |