Repository navigation
feat(rules): flag commands that switch off TLS certificate checks (SG-016) #210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3553,6 +3553,51 @@ def _check_brand_name_impersonation(text: str) -> list[str]: | |
| ) | ||
|
|
||
|
|
||
| # ── SG-016: Certificate Checks Turned Off ────────────────────── | ||
|
|
||
| # A command or setting that switches off TLS certificate checking for a download | ||
| # or install. The source may be the right one, but the connection to it no longer | ||
| # proves who answers (CWE-295, Improper Certificate Validation). Every whitespace | ||
| # run is [ \t] and no pattern crosses a newline, so a scan stays linear. | ||
| _TLS_OFF_PATTERNS = [ | ||
| # pip install --trusted-host host | ||
| r"--trusted-host(?:=|[ \t]+)\S+", | ||
| # npm, yarn or pnpm: config set strict-ssl false, or "strict-ssl=false" in .npmrc | ||
| r"\b(?:npm|yarn|pnpm)[ \t]+config[ \t]+set[ \t]+strict-ssl[ \t]+false\b", | ||
| r"^[ \t]*strict-ssl[ \t]*=[ \t]*false\b", | ||
| # NODE_TLS_REJECT_UNAUTHORIZED=0 and PYTHONHTTPSVERIFY=0 (quoted or not) | ||
| r"\bNODE_TLS_REJECT_UNAUTHORIZED[ \t]*=[ \t]*['\"]?0\b", | ||
| r"\bPYTHONHTTPSVERIFY[ \t]*=[ \t]*['\"]?0\b", | ||
| # curl --insecure, and -k alone or inside a group of short flags such as -sSLk | ||
| r"\bcurl\b[^\n|;&]*?[ \t](?:--insecure\b|-[a-zA-Z]*(?-i:k)[a-zA-Z]*(?=[ \t;&|)]|$))", | ||
| # wget --no-check-certificate | ||
| r"\bwget\b[^\n|;&]*?[ \t]--no-check-certificate\b", | ||
| # git config [--global] [http.<url>.]sslVerify false, and GIT_SSL_NO_VERIFY | ||
| r"\bgit\b[^\n|;&]*?[ \t]http(?:\.\S*)?\.sslVerify(?:=|[ \t]+)(?:false|0|off|no)\b", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exclude Git queries and removal operations. At Distinguish configuration writes from queries and removals. Add this near-miss test. Retain detection of As per coding guidelines, “Low false positives.”
|
||
| r"\bGIT_SSL_NO_VERIFY[ \t]*=[ \t]*['\"]?(?:1|true)\b", | ||
| ] | ||
|
|
||
| RULE_TLS_VERIFICATION_OFF = Rule( | ||
| id="SG-016", | ||
| name="Certificate Checks Turned Off", | ||
| severity=Severity.MEDIUM, | ||
| description=( | ||
| "The skill switches off TLS certificate checking for a download or install " | ||
| "(curl -k, wget --no-check-certificate, pip --trusted-host, npm strict-ssl " | ||
| "false, NODE_TLS_REJECT_UNAUTHORIZED=0, git http.sslVerify false). The " | ||
| "registry or host may be the right one, but anyone on the network can then " | ||
| "swap the download for something else (CWE-295, OWASP AST02)." | ||
| ), | ||
| remediation=( | ||
| "Keep certificate checking on. Remove -k/--insecure, --no-check-certificate, " | ||
| "--trusted-host and the settings that disable verification; if a host uses a " | ||
| "private certificate authority, trust that CA instead of turning checks off." | ||
| ), | ||
| pattern=re.compile("|".join(_TLS_OFF_PATTERNS), re.IGNORECASE | re.MULTILINE), | ||
| tags=["tls", "certificate-validation", "supply-chain", "owasp-asi04", "owasp-ast02"], | ||
| ) | ||
|
|
||
|
|
||
| # ── SG-104: Suspicious Tool Name ─────────────────────────────── | ||
|
|
||
| # A tool name is split into words, at "_", "-", "." and camelCase boundaries, and a | ||
|
|
@@ -3783,6 +3828,7 @@ def _listing_tool_gaps(listing: ToolListing) -> list[tuple[McpTool, str]]: | |
| RULE_PACKAGE_REGISTRY, | ||
| RULE_BRAND_NAME_IMPERSONATION, | ||
| RULE_COMPILED_PYTHON, | ||
| RULE_TLS_VERIFICATION_OFF, | ||
| RULE_UNRESTRICTED_PATH, | ||
| RULE_SUSPICIOUS_TOOL_NAME, | ||
| RULE_TOOL_NO_DESCRIPTION_OR_SCHEMA, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove ambiguous backtracking inside a short-option group.
At
src/skillshield/rules.py, Line 3572, input"curl -" + "k" * 50_000 + "1"fails the final boundary. Both letter repetitions can consume the samekcharacters, so the engine retries quadratically many splits. This occurs with only one command name and is separate from repeated-prefix rescanning. (docs.python.org)Make the split occur at the first lowercase
k, or inspect the option token once. Preserve detection of-sSLkand-kk. Add this failing-boundary performance case.As per path instructions, “Flag patterns that can take quadratic or exponential time.”
Source: Path instructions
Do not interpret option arguments as grouped flags.
At
src/skillshield/rules.py, Line 3572,curl -obook https://example.com/filematchescurl -obook. However,-oconsumesbookas its output filename; itskdoes not disable certificate checks. curl permits an attached argument for short options. (curl.se)Consume arguments of value-taking options before checking for
k. Add this near-miss test and retain the-sSLkpositive case.As per coding guidelines, “Low false positives.”
Source: Coding guidelines
Scanning one long line with many
curl,wget, orgittokens is quadratic.The curl, wget, and git branches of SG-016 search the rest of the line from every command name. A single line of 20,000
curltokens (about 100 KB, no option, no newline) takes about 30 seconds in the rule regex. Time grows roughly fourfold each time the input length doubles. The comment atsrc/skillshield/rules.py:3558-3561says these patterns stay linear. That is only true across lines.Rewrite the three branches so that a command name that does not produce a match is not searched again through the rest of its line. Each scan of a line must complete in one pass. Keep the current positive matches:
curl -k, grouped short flags such as-sSLk,--insecure,wget --no-check-certificate,git config http.sslVerify false, andgit -c http.sslVerify=false.Add a regression case that feeds one long line of repeated
curl,wget, andgittokens and requires it to finish in bounded time. Keep the existing positive and near-miss cases.