Skip to content

fix(rules): lifetime-relative TLS expiry warning, visible not-checked and a CONNECT tunnel for security/tls-certificate - #1306

Closed
nc9 wants to merge 4 commits into
mainfrom
fix/tls-certificate-1279-1259
Closed

nc9 wants to merge 4 commits into
mainfrom
fix/tls-certificate-1279-1259

Conversation

@nc9

@nc9 nc9 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1279
Refs #1259 (partial: items 1 and 3 of the issue are done, see below; the issue stays open)

#1279: expiry warning relative to the certificate's lifetime (Nik's decision)

  • The default warning no longer uses a fixed 30 days. It is the last third of the certificate's lifetime (notAfter - notBefore) less a 14-day renewal margin: floor(L / 3 - 14), never below error_days. 16 days for a 90-day certificate, 52 for 200 days, and it shrinks with SC-081's shorter lifetimes. If the lifetime cannot be read the window is 30 days.
  • Why the margin: "warn in the last third" alone would still warn at 28 days on a 90-day certificate, which is exactly the routine-renewal window the issue's AC says must pass. The margin means a warning appears only once a renewal is 14 days overdue. This is my reading of the decision; one constant (RENEWAL_MARGIN_DAYS) changes it.
  • warn_days is now optional and unset by default; set, it replaces the window with a fixed number of days as before (error_days <= warn_days is still refused when both are set). error_days default 7 is unchanged. The warn check's details carry warnDays and warnDaysSource (lifetime or option).
  • Tests pin a 90-day certificate with 28 days left (pass), 10 (warn, "within the 16-day warning threshold") and 5 (fail), the lifetime table, and the override.

#1259 items done

  1. Visible not checked. With no handshake (proxy, refused address, unresolved or unreachable host) the rule now returns a skipped check carrying a new tls-certificate-not-checked skip reason, which is in NOT_CHECKED_SKIP_REASONS, so it appears under "Not checked" in every format and in notChecked in -f json (it used to be an info check the report dropped).
  2. CONNECT tunnel behind a proxy. With HTTPS_PROXY or HTTP_PROXY (either case) set, the CLI probe opens a CONNECT tunnel and does TLS inside it (SNI and verification intact). Spiked first: TLS over a CONNECT socket works on Bun 1.4.3. NO_PROXY (*, host, .suffix, *.suffix, optional port) is honoured and probed directly. A proxy answering 403, 407 or 502, never answering (PROXY_TIMEOUT), unreachable, or sending garbage gives a not-checked entry with that reason, never a pass or a crash; an https: or socks proxy is reported as unsupported; no address is resolved and no direct socket is opened for the target while a proxy applies; proxy credentials go in Proxy-Authorization and never appear in a result.

#1259 NOT done in this PR (needs your call)

  • Report instead of abort on a broken start-URL certificate (issue item 2). The reachability preflight aborts before any rule runs, so a JSON report with security/tls-certificate failing needs a report for a crawl that fetched nothing (a new synthetic-report path in the CLI audit controller and all report formats, like the redirected report). That is a separate, larger change.
  • The key and certificate options (key_types, rsa_min_bits, ecdsa_min_bits, dsa_min_bits, reject_weak_signature, min_tls_version, check_counterpart): the issue itself says signature and protocol options ship only after a probe spike, and the key-type options need the probe to read key type and curve.
  • The local fixture suites for expired, wrong host, self-signed and weak key already exist; the proxy fixture (accepting, refusing, timeout, NO_PROXY) is new.

Tests

  • apps/cli/tests/audit/tls-probe.test.ts (47): real handshakes through a local CONNECT proxy fixture (accept, 403, 407, 502, hang, garbage, down, credentials, NO_PROXY table, socks unsupported) and the rule end to end; packages/rules/tests/tls-certificate.test.ts and tls-certificate-pipeline.test.ts; packages/report/tests/not-checked-tls-1259.test.ts (JSON notChecked, text and markdown).
  • Passing: those, rule-options-check, docs-rule-pages, private-target-skip, streaming-rules-canonical-golden (no pin moved), tls-cause, apps/cli format, lint and tsgo, tsgo on rules, report and core-contracts, make validate in docs/.
  • Not run: a live proxy, the whole --run cli or --run rules suites, an end-to-end audit through a real egress proxy. Local Bun is not the pinned 1.4.4.

Docs: docs/rules/security/tls-certificate.mdx (expiry window, options table, not checked, proxy behaviour). Skill: none.

Egress and SSRF review of the tunnel (security scan lead), head 534c9e5

The first version CONNECTed to the NAME and skipped the egress guard, so the proxy resolved it: a bypass. Fixed:

  • The tunnel path now goes through the same guard as the direct path. The name is resolved once locally; a link-local, cloud-metadata (169.254.169.254, 168.63.129.16, IPv6 link-local) or, for any host other than the audited one (the www/apex counterpart), a private answer is refused before a byte is sent. IP-literal start hosts are refused the same way.
  • The CONNECT names the vetted ADDRESS, not the name; the name is only the SNI and verification name. So the proxy's own DNS and a rebinding answer cannot redirect the tunnel, and the proxy's reply is only a status (a 3xx is a refusal), never a target.
  • Hosts in NO_PROXY take the direct path, which is vetted identically. A SAN or link in page content is never connected to. Redirects are not followed.
  • Proxy credentials go only into Proxy-Authorization; results and console output carry the proxy host and port only (asserted).
  • Trade-off: a name this machine cannot resolve is "not checked" even if the proxy could resolve it, and a proxy whose policy allows only hostnames will refuse an address CONNECT (shown as not checked with its status). Documented on the rule page.
  • Adversarial tests added: names resolving to metadata, link-local, WireServer and IPv6 link-local addresses; a metadata literal as the start host; a private answer for the www counterpart of a public site; a private answer for a public name; a hostile rebinding resolver; a name that only the proxy could resolve; a 307 reply; NO_PROXY with a metadata answer; credentials absent from result and logs. In each refusal case the proxy fixture saw no CONNECT.
  • Decision recorded: Nik confirmed the lifetime-relative expiry warning (security/tls-certificate: 30-day expiry warning fires on healthy auto-renewing certs (73% of warnings at 25-30 days left) #1279).

Review round 1 (head e9c9d1c)

  • HIGH-1: a tunnelled handshake passed no identity, so an IP-literal start host was judged against the PROXY address (a valid cert read as untrusted). connectForFacts now gets host for the tunnel; test with the proxy on ::1 and the certificate on 127.0.0.1 (fails without the fix; direct and tunnelled agree).
  • HIGH-2 (CodeQL js/disabling-certificate-validation): there is exactly ONE rejectUnauthorized: false site, in connectForFacts, shared by the direct and the tunnelled handshake. It is deliberate and commented there: the audit reads whatever certificate the host serves and judges it on the facts (authorized, authorizationError, names, dates) so an expired, self-signed or mismatched certificate is reported instead of aborting; nothing is sent over the connection. Same reason the alert was dismissed on main; needs the maintainer dismissal for the new fingerprint.
  • MEDIUM-3: a malformed percent escape in proxy credentials (http://us%zzer:p@host) is PROXY_BAD_URL (not checked), and the whole probe is wrapped so it can never reject (the rule and the crawl cause-read call it unguarded).
  • MEDIUM-4: kept the SSRF-safe address CONNECT; no name-CONNECT now. security/tls-certificate: run through HTTPS_PROXY and fail the rule instead of aborting on a broken start-URL certificate #1259 stays open for the proxy-owns-DNS case, tracked as security/tls-certificate: opt-in proxy-resolves-names mode for the TLS handshake behind HTTPS_PROXY (follow-up to #1259) #1317 (opt-in mode, audited host and counterpart only, never page-derived hosts).
  • MEDIUM-5: error_days is now lifetime-relative as well: 7 days, or a tenth of the lifetime (at least 1 day) under 70 days, and the warn window is derived with a margin of at most 15% of the lifetime and never below the error threshold. Lifetimes are rounded to whole days (Let's Encrypt 90 days less a second reads 90, warn 16). 6, 10, 30, 47, 90 and 365-day tables tested; explicit options still win.
  • LOW: stale not-checked hint rewritten; an empty NO_PROXY no longer shadows no_proxy; CIDR in NO_PROXY documented as unsupported (tested); html, llm and xml not-checked output tested.

… and CONNECT tunnel for security/tls-certificate #1279 #1259

Signed-off-by: Nik Cubrilovic <[email protected]>
Comment thread apps/cli/src/audit/tls-probe.ts Fixed
Comment thread apps/cli/src/audit/tls-probe.ts Dismissed
nc9 added 2 commits October 30, 2026 12:37
…fetime-relative error threshold, proxy URL hardening #1259 #1279

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9

nc9 commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Landed in v0.0.143 as bf192ce9 3be4dcfb 38cc022e 7cfcc02c via #1341. Release: https://github.com/squirrelscan/squirrelscan/releases/tag/v0.0.143. Closing this original.

nik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

security/tls-certificate: 30-day expiry warning fires on healthy auto-renewing certs (73% of warnings at 25-30 days left)

2 participants