Skip to content

feat(rules): add security/tls-certificate for expiry, hostname, chain and key #712 - #716

Merged
nc9 merged 8 commits into
mainfrom
claude/712-tls-certificate
Oct 28, 2026
Merged

nc9 merged 8 commits into
mainfrom
claude/712-tls-certificate

Conversation

@nc9

@nc9 nc9 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

squirrel never looked at the certificate. security/https only checks the URL scheme, and a TLS failure during a crawl said only "check its expiry, hostname coverage, and that the full chain is served".

This adds the security/tls-certificate rule (site scope, skipOnPrivateTarget):

  • One handshake for the audited site's host, plus one for its www or apex counterpart on the same port. The counterpart comes from the registrable domain only (tldts, private suffixes included): example.com and www.example.com pair, blog.example.com has none, and acme.pages.dev pairs with www.acme.pages.dev, never www.pages.dev.
  • Expiry: fails when expired or inside error_days (default 7), warns inside warn_days (default 30). error_days above warn_days is refused. A pass shows the issuer, the expiry date and the days remaining.
  • Hostname: fails when the certificate does not cover the audited host, naming the host and up to ten of the names it does cover. A wildcard covers one label; IPv6 SAN entries compare in any spelling.
  • Chain: fails for a self-signed certificate, and for a server that omits its intermediate (UNABLE_TO_VERIFY_LEAF_SIGNATURE). UNABLE_TO_GET_ISSUER_CERT_LOCALLY gets its own message, because the same code can mean an untrusted root.
  • Key: warns on an RSA key under 2048 bits. ECDSA keys are not judged for size.
  • www/apex: warns when the counterpart answers and its certificate is not valid for that name. Nothing is reported when it does not resolve, does not answer, or is refused by the egress check.
  • Not checked, never pass: with no handshake available, or one that cannot complete, the rule reports an info "not checked" with the reason.

The crawl's TLS root failure now names the cause one handshake found (expired on a date, hostname not covered, missing intermediate, self-signed) instead of the generic list.

Closes #712

Design: the handshake is injected, and only the CLI injects it

The first version opened raw TLS sockets from packages/utils (called by the rule and by the crawl's root-failure path), which goes around the hosted engine's request-level network policy. This version:

  • Shared packages hold no socket code. @squirrelscan/utils/tls-certificate is the facts and their meaning plus a TlsProbeFn type. A guard test fails if any shared package src imports node:tls, node:http2, node:dgram, socket parts of node:net (only isIP is allowed) or Bun's socket APIs.
  • The one handshake is apps/cli/src/audit/tls-probe.ts, behind the same egress guard as the crawl's own hosts (repo#3430): each name is resolved once per probe, a link-local or cloud metadata answer is refused, and the socket connects to the checked address with the name as SNI, so a rebinding answer cannot move it. For the rule, the audited origin (host and port) may resolve privately because the crawl already requests it, while the counterpart of a public site must resolve to public addresses. A refused target is unreachable with code EGRESS_REFUSED, and nothing is sent. Behind an HTTP proxy from the environment it makes no direct connection.
  • Wiring: RunnerScope.tlsProbe becomes ctx.tlsProbe on site rules (CLI audit and analyze). CrawlerConfig.tlsProbe feeds the root-failure cause (CLI audit and crawl): one handshake per origin, only for a failure that can still become the root failure, waiting at most 3 s or whatever the URL's watchdog has left. Without a probe (cloud, embedders, tests) the rule says "not checked" and the crawl keeps the fetch's own detail.
  • The apex and www handshakes run at once, so the worst case is one probe deadline (8 s). Certificate text is server-chosen: control characters are stripped, names capped at 1000 and 253 characters, the issuer at 200.

Phase 2 (legacy TLS versions) is out of scope.

Golden constants (merge note)

packages/audit-engine/tests/streaming-rules-canonical-golden.test.ts: findings 102743 to 102744, per-rule tally 311 to 312, and a tally pin for the rule (one skipped, not-https: the synthetic origin is plain http and the harness injects no probe). healthScore.overall is unmoved at 51. Any site rule merged before this one shifts both again.

Verification

Certificates are generated with openssl at test time and served from 127.0.0.1. Names resolve through injected resolvers. No live host or DNS server is contacted by the tests.

# pure facts + the no-socket guard
cd packages/utils && bun test tests/tls-certificate.test.ts            # 19 pass
# rule (fact probes), audit rule stage via RunnerScope.tlsProbe, private-target skip
cd packages/rules && bun test tests/tls-certificate.test.ts tests/tls-certificate-pipeline.test.ts tests/private-target-skip.test.ts   # 65 pass
# crawl cause: no probe, 3 s cap, remaining budget, memo
cd packages/crawler && bun test tests/tls-cause.test.ts                # 11 pass
# the CLI probe on real loopback handshakes: facts, egress refusals, pinning, timeout, proxy;
# a real crawl's root failure through the injected probe, and without one
cd apps/cli && bun test tests/audit/tls-probe.test.ts tests/audit/tls-root-failure.test.ts   # 25 pass
# CI guards this PR used to trip
cd packages/report && bun test tests/merged-message-numbers-2231.test.ts   # 25 pass
cd packages/audit-engine && bun test tests/streaming-rules-canonical-golden.test.ts  # pass; full test:golden set pass
# typecheck: utils, rules, crawler, audit-engine, apps/cli clean; apps/cli lint + format:check clean
# docs: bun scripts/glossary.ts --check, tangly check --strict, scripts/check-links.ts all good

A live CLI run (squirrel audit https://squirrelscan.com/ --offline --max-pages 1 --rule-include security/tls-certificate, isolated HOME) stored tls-certificate-expiry pass: "Certificate valid until 2027-01-16, 80 days remaining, issued by Google Trust Services", through real DNS, the egress check and a pinned handshake.

Acceptance Criteria

  • A CLI audit of a host whose certificate expires in 20 days produces a warning showing the expiry date and days remaining; 5 days produces an error; an expired certificate produces an error
    • Through the audit's rule stage (runSiteRules with RunnerScope.tlsProbe), with the real handshake covered separately in the CLI probe tests. The squirrel binary path was run live against a public host (pass shown above).
  • warn_days and error_days options change the thresholds (fixture: warn_days = 60 makes a 45-day certificate warn)
  • A certificate that does not cover the audited hostname produces an error naming the hostname and the names the certificate does cover
  • A self-signed certificate produces an error that says self-signed
  • A server that omits its intermediate certificate produces an incomplete-chain error (Bun reports this as a missing leaf signature)
  • Auditing example.com where www.example.com resolves and serves a certificate that does not cover it produces a warning naming www.example.com; when the variant does not resolve, nothing is reported
  • An RSA key under 2048 bits produces a warning
  • A valid certificate produces a pass that shows the issuer and expiry date
  • Auditing localhost or a private-network host skips the rule
  • In an environment without a TLS probe, the rule reports "not checked", not pass or fail
  • When the crawl fails on a TLS error, the failure message names the specific cause (expired, hostname, chain, self-signed)
  • Tests use local TLS fixtures (generated certificates), not live third-party hosts
  • The rule has a docs page under docs/rules/security/, including its options

Checklist

  • I added or updated tests for behavioral changes.
  • I did not include secrets, customer data, or incompatible third-party material.
  • Every commit includes a DCO Signed-off-by line (git commit -s).

Docs: docs/rules/security/tls-certificate.mdx (options under [rule_options."security/tls-certificate"], the egress check, the proxy and first-error limits) and the regenerated Security hub. Skill: no change needed; the rule needs no flag or agent action, and its "not checked" results carry their reason.

@claude

claude Bot commented Oct 12, 2026

Copy link
Copy Markdown

Reviewed the TLS probe, the rule and the crawler hook. I did not run the tests, and I only skimmed the docs and fixtures. The design is clean: the probe never throws, "not checked" is never a pass, and the logic is shared between the rule and the crawl. Findings:

  • (medium) packages/crawler/src/tls-cause.ts:25 — withTlsCause runs a raw probeTlsCertificate (up to 8s) inside the crawl root-failure path. It skips the crawler withRequestDeadline and phase budget, and any private-target or SSRF guard the fetcher applies. A root TLS failure can therefore exceed the audit time budget. It also opens a second direct socket that ignores proxy env settings and fetcher rate limits. Wrap it in the request deadline or pass a shorter timeoutMs, and reuse the same host policy as the fetcher.
  • (medium) packages/rules/src/security/tls-certificate.ts:125 — the www/apex variant host is derived, not audited. skipOnPrivateTarget only checks the audited host. A public site whose www. name resolves to a private or internal address gets a TCP connect to it from the scanner. Resolve and apply the same private-address check before probing the variant.
  • (low) packages/utils/src/tls-certificate.ts:242 — trustProblem maps CERT_HAS_EXPIRED to no problem so the expiry check owns it. Node reports only the first verification error, so an expired certificate with a broken chain (self-signed, missing intermediate) shows only as expired. The chain failure is hidden until renewal. Worth a code comment or doc note.
  • (low) packages/rules/src/security/tls-certificate.ts:21 — nothing enforces error_days <= warn_days. With error_days: 40 and the default warn_days, the warn branch is unreachable and the messages read oddly. Add a .refine.
  • (low) packages/utils/src/tls-certificate.ts:204 — certificateCovers compares IP SAN entries by string. IPv6 forms (compressed against expanded) can give false hostname failures, though only for IP-literal sites. Normalize with node:net or note the limitation.
  • (low) packages/rules/src/security/tls-certificate.ts:67 — only ctx.site.baseUrl is probed, though the PR text says "per audited host". If the audit covers several hosts, such as redirect targets or subdomains, they are not checked. Clarify in the docs.
  • (nit) packages/rules/src/security/tls-certificate.ts:134 — the www warning says "answers on ${port}" even when the port is the default 443. Wording only.
  • (nit) Test coverage looks good: it uses local fixture servers, and there are tests for the crawler cause and the private-target skip. A test for the probe timeout path (a server that accepts but never handshakes) and one for the error_days > warn_days case would round it out.

No critical or high issues found.

@claude

claude Bot commented Oct 12, 2026

Copy link
Copy Markdown

Reviewed the diff for the new security/tls-certificate rule, the shared probe in packages/utils/src/tls-certificate.ts, and the crawler's TLS cause. I didn't run the tests or check CI. The design is sound and the tests are thorough. The rule never reports a pass for a certificate it didn't read, and the fixtures are generated locally with no live hosts. I found nothing that should block the merge.

  • (medium) packages/crawler/src/tls-cause.ts:28 – withTlsCause awaits a raw handshake of up to 8s (TLS_PROBE_TIMEOUT_MS) inside the crawl's root-failure path. That wait sits outside withRequestDeadline and the phase budget. A host that accepts the TCP connection and then stalls adds 8s before a zero-page audit can report. Consider bounding it by the remaining phase budget, or a shorter timeout (2–3s) for this diagnostic. The same handshake also skips whatever proxy or egress settings the fetcher applies. Please confirm that is intended for the crawl path.
  • (low) packages/rules/src/security/tls-certificate.ts (expiryCheck) – dayText(-days) is computed from Math.floor of a negative value. A certificate that expired 2 hours ago prints "1 day ago", and one that expired 1.5 days ago prints "2 days ago". Use Math.ceil of the absolute elapsed time, or print "less than a day ago" the way the forward case does.
  • (low) packages/rules/src/security/tls-certificate.ts:30 – nothing validates error_days <= warn_days. With error_days = 40 and warn_days = 30, the warn branch can never fire, and the error branch's "expected" text is misleading. A .refine or a clamp would help.
  • (low) packages/utils/src/tls-certificate.ts (certificateCovers) – IPv6 SAN entries are compared as lowercased strings against the bracket-stripped hostname. Compressed and expanded forms of the same address won't match, and a SAN with a trailing dot won't either. That gives a false hostname failure for IP-literal audits. It is an edge case, and you can normalize both sides with node:net if you care.
  • (low) packages/utils/src/tls-certificate.ts (trustProblem) – the probe sees only the runtime's first authorization error. An expired certificate that is also self-signed or has an incomplete chain reports only the expiry. This is probably unavoidable, but the docs could say that fixing one problem may reveal another.
  • (nit) packages/utils/src/tls-certificate.ts – routeTlsHostForTests and the module-level testRoutes map are test hooks in a production module. That is acceptable, but consider @internal or moving the route to the options object so production code can never be redirected through global state.
  • (nit) CHANGELOG.md – the entry says "each audited host", but the rule probes only the site's base host plus its www/apex counterpart. "The audited site's host" is more accurate.
  • (nit) docs/rules/security/tls-certificate.mdx – the sentence about UNABLE_TO_VERIFY_LEAF_SIGNATURE / UNABLE_TO_GET_ISSUER_CERT_LOCALLY is hard to read. Splitting it into two bullets would help.

Test coverage is good. It covers the expiry thresholds, hostname, chain, key and www variant checks, the not-checked cases, the audit-stage pipeline, and the crawl root failure. It doesn't cover a stalled handshake (the timeout path) or a SAN containing an IP address.

@nc9

nc9 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Maintainer review (2026-10-12)

Verdict: ON HOLD pending design. Fix 1 changes how the probe reaches the engine. Do that first. Merge last of #714-#720. I reviewed head 1442e1c against main 2dca3b9. Main CI is green at that sha, so the red checks come from this PR.

Acceptance criteria (#712)

11 of 13 are met.

  • AC1, partly met. The 20-day, 5-day and expired cases go through runSiteRules with real loopback handshakes, but not through a CLI binary run. The PR leaves that box unticked.
  • AC13, partly met. The docs page exists, but its options example is wrong (fix 4).
  • The rest are met: hostname, self-signed, incomplete chain, www variant, RSA key, pass detail, private-target skip, not checked, crawl cause, local fixtures and options.

Fixes

  1. Design blocker: the probe must be injectable. The rule and the crawler's TLS root-failure path (packages/crawler/src/tls-cause.ts) both open sockets through packages/utils/src/tls-certificate.ts, which does await import("node:tls") and tls.connect.
    • Raw TLS sockets bypass the hosted audit environment's request-level network policy. That policy covers private addresses, DNS rebinding and allowed ports. So a public site whose www. name resolves to an internal address would be reached from the hosted environment.
    • Make the probe an injectable function, for example TlsProbeFn. The rule gets it from the rule context or runner options, and withTlsCause gets it from the crawler options.
    • Put the node:tls implementation in a module that only apps/cli imports and wires. The shared packages (utils, rules, crawler, audit-engine) must not import node:tls or node:net (an isIP-style address helper is fine).
    • With no probe injected, the rule reports "not checked" and the crawl keeps the fetch's own failure detail. That is what New rule: TLS certificate expiry, hostname, chain and key checks (CLI first) #712 specifies for the hosted engine.
    • Add a unit test that the engine never opens a socket without an injected probe. One way: run the rule and withTlsCause with no probe and assert the not-checked result, with nothing listening. Another: assert that the shared packages contain no node:tls import.
  2. CI, Report tests step of "CLI tests". packages/report/tests/merged-message-numbers-2231.test.ts:341 rejects (${probe.code}) in TLS certificate not checked: no TLS handshake with ${hostname} (${probe.code}). Write it as (error code ${probe.code}), or end the message with : ${probe.code}.
  3. CI, golden gate. This fails "Audit engine golden tests" and the "Audit engine tests" step of "CLI tests". The apps/cli tests step itself passes.
    • File: packages/audit-engine/tests/streaming-rules-canonical-golden.test.ts.
    • expect(v1.findings.length).toBe(101736); (line 154): CI received 101737. security/tls-certificate is site-scoped and adds one whole-crawl check. Raise the number by 1 and add a comment line in the existing style, for example // 101736 -> 101737: security/tls-certificate is site-scoped and adds one whole-crawl check (#712). <its status on the fixture>.
    • expect(v1.perRuleTally.length).toBe(301); (line 176) fails next. Raise it by 1 and extend the tripwire comment.
    • The numbers are relative to the main you rebase on. Every rule PR edits these lines, so rebase and re-read them after each merge.
    • Verify with cd packages/audit-engine && bun test tests/streaming-rules-canonical-golden.test.ts. healthScore.overall must stay 51, or the comment must explain why it moved.
  4. The docs options example is ignored. [rules."security/tls-certificate"] sets nothing: options are read only from config.rule_options[ruleId] (packages/rules/src/runner.ts:192), and the [rules] schema strips unknown keys silently.
    • Change it to [rule_options."security/tls-certificate"].
    • Quote the crawl failure as a template, certificate has expired on {date}, not ... on 2026-09-01.
  5. The www variant gives false positives on subdomains. wwwVariant() prefixes www. to any host. Auditing app.example.com therefore probes www.app.example.com. With wildcard DNS and a *.example.com certificate, that name resolves and the certificate does not cover it, so the rule warns wrongly.
    • Derive the variant only for the registrable domain and for www. plus that domain. registrableDomain() is in packages/rules/src/content/dev-leakage.ts.
    • Add a test for the subdomain case.
  6. Bound the work.
    • Resolve the variant host and apply the same private-address test as skipOnPrivateTarget before connecting.
    • withTlsCause waits up to 8 s outside withRequestDeadline and the phase budget. Give it about 3 s, or whatever remains of the budget.
  7. Smaller items, all still open from the review bot:
    • dayText(-days) floors a negative number, so a certificate that expired 2 hours ago prints "1 day ago". Use ceil, or print "less than a day ago".
    • Add .refine((o) => o.error_days <= o.warn_days) to the options schema.
    • Normalise IPv6 SAN entries before comparing them.
    • Say in the docs that the runtime reports only the first verification error. An expired self-signed certificate shows as expired only.
    • In the CHANGELOG entry, "each audited host" should read "the audited site's host and its www or apex counterpart".
    • Mark the test route hook (routeTlsHostForTests) @internal, or move it into the options object.
    • Add tests for a stalled handshake (timeout path) and for an IP SAN.
  8. Conflicts with feat(rules): add security.txt and version-disclosure rules (#713) #717 in docs/rules/security/index.mdx and packages/rules/src/security/index.ts. feat(rules): add security.txt and version-disclosure rules (#713) #717 merges first, so rebase on it. When both have landed, the Security count is 23.

PR hygiene

  • CHANGELOG: the entry is present. Fix the wording as in item 7.
  • PR description: add a line saying whether the squirrelscan agent skill (squirrelscan/skills) needs a change.
  • Attribution:
    • Remove the Co-Authored-By: and Claude-Session: trailers from both commits. Keep Signed-off-by:.
    • Remove the "Generated with Claude Code" footer and the session URL from the PR body.
    • No attribution lines of any kind in commit or PR text.
  • Docs: quote message templates with placeholders, never filled examples. No em-dashes.
  • Rule counts: leave the per-category counts in the README and docs tables alone. The maintainer will update them in one docs PR after these rule PRs merge.

@github-actions

Copy link
Copy Markdown
Contributor

Auto-review did not complete

The claude-review job failed before posting a review. This PR has not been auto-reviewed. Run a review manually (/review) before merging.

  • Result: success / is_error=true after 1 turns, 0 permission denial(s), $0.00
  • Job log

Partial findings recovered from the session (incomplete, unverified, and NOT a merge signal):

Show partial review

You've hit your session limit · resets 10:10pm (UTC)

nc9 pushed a commit that referenced this pull request Oct 27, 2026
… and key #712

The original #716 work (rule, socket probe, crawl TLS cause, tests, docs),
squashed onto main.

Signed-off-by: Claude <[email protected]>
@nc9
nc9 force-pushed the claude/712-tls-certificate branch from 32374e8 to b253a49 Compare October 27, 2026 07:37
nc9 pushed a commit that referenced this pull request Oct 27, 2026
… and key #712

The original #716 work (rule, socket probe, crawl TLS cause, tests, docs),
squashed onto main.

Signed-off-by: Claude <[email protected]>
@nc9
nc9 force-pushed the claude/712-tls-certificate branch from b253a49 to 94ab4a5 Compare October 27, 2026 08:43
@claude

claude Bot commented Oct 27, 2026

Copy link
Copy Markdown

Review of #716 (security/tls-certificate). I read the CLI probe, the crawler cause hook, the rule and the runner wiring. I did not run the tests. CI was still pending when I looked.

The design holds up. The egress guard runs before every handshake and the socket connects to the vetted address, with the name as SNI. Proxy environments report not checked instead of going around the proxy. The www/apex counterpart is limited to registrable domains. The cause lookup is memoized per origin and capped at 3 s.

  • (medium) apps/cli/src/controllers/audit.ts (the tlsProbe: createTlsProbe({ siteUrl }) line in the rule run): the --offline flag is not consulted. The crawl sets ownSiteOnly for --offline (squirrel audit --offline: hold the crawl's own redirects and off-site sitemaps to the audited site #819), and AGENTS.md says --offline skips cloud features and telemetry. This probe still opens direct sockets to the www/apex counterpart, which is a different host. Consider omitting tlsProbe when options.offline is set so the rule reports not checked. Alternatively, document that the counterpart is contacted and add a test that pins whichever you choose.
  • (low) apps/cli/src/controllers/analyze.ts: analyzeStoredCrawl re-analyzes a stored crawl but now makes live TLS handshakes to the site. Confirm that is intended for report and re-analysis flows. The certificate state is then "now", not as of the crawl.
  • (low) packages/rules/src/security/tls-certificate.ts: when the www/apex probe is unreachable or unavailable, nothing is reported. That is a reasonable default, since the counterpart may legitimately not exist. A short comment would show it is deliberate.
  • (nit) packages/rules/src/security/tls-certificate.ts: the optionsSchema hunk in the diff has a stray }) indentation before .refine. Run oxfmt on the file (the oxfmt --check <path> command from AGENTS.md).
  • (nit) apps/cli/src/audit/tls-probe.ts: deadline and lookupDeadline both start at timeoutMs. DNS time is therefore not subtracted from the handshake budget by AbortSignal.timeout, but it is by deadline - Date.now(). Both are correct, but a comment would help the next reader.

Test coverage looks thorough. It covers real handshakes against fixtures generated at test time, egress refusals, a hung server and the pipeline. Please make sure bun run scripts/test-suites.ts --check passes for the new test files, along with the secret scan baseline.

Comment thread apps/cli/src/audit/tls-probe.ts Dismissed
nc9 added a commit that referenced this pull request Oct 27, 2026
…ts www/apex counterpart #712

Review follow-ups on #716: under --offline the rule's probe contacts the
audited host only (the counterpart is unavailable, nothing resolved or sent);
comments say why an unreachable counterpart reports nothing, that analyze
reads the certificate as served now, and how the lookup and handshakes share
one deadline; the options schema is indented as an object. Docs and the
CHANGELOG entry name the --offline and analyze behaviour.

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

claude Bot commented Oct 27, 2026

Copy link
Copy Markdown

Review of the security/tls-certificate rule and the TLS probe. I read the rule, tls-probe.ts and the certificate helpers in utils. I did not run the tests or CI, and I only skimmed the controllers, crawler and docs changes.

The design holds up. The handshake is injected, every address is vetted by the egress guard before connecting, and the socket connects to the vetted IP with the host name as SNI. Certificate text from the site is control-char stripped and length-clamped, and the SAN list is capped. The www/apex counterpart comes from the registrable domain only, so another tenant's name is never derived.

  • (low) apps/cli/src/audit/tls-probe.ts (siteHostOnly check): hostname has its trailing dot stripped, but site.hostname does not. A site audited as https://example.com./ would be treated as a different host under --offline and reported as unavailable. Normalise the trailing dot in siteOrigin as well.
  • (nit) packages/rules/src/security/tls-certificate.ts (www check): only the first problem from certificateProblems(other, variant) is reported. That is fine for a warning, but a comment saying so would help.
  • (nit) tls-probe.ts (handshake): the timeout option on connect and the manual timer overlap. This is harmless, since finish is idempotent.

I found no blocking issues.

claude and others added 4 commits October 27, 2026 20:55
… and key #712

The original #716 work (rule, socket probe, crawl TLS cause, tests, docs),
squashed onto main.

Signed-off-by: Claude <[email protected]>
…the egress guard #712

The shared packages opened raw TLS sockets (node:tls in utils, called from the
rule and the crawl's TLS root failure), which go around the hosted engine's
request-level network policy: a public site whose www name resolves to an
internal or metadata address would be reached.

- @squirrelscan/utils/tls-certificate is pure now: facts, meaning and a
  TlsProbeFn type, no socket code. A guard test asserts no shared package
  imports node:tls, and node:net only for isIP.
- The handshake lives in apps/cli/src/audit/tls-probe.ts and is the only one:
  each name is resolved once (memoized per probe), link-local and metadata
  answers are refused, the www/apex counterpart of a public site must resolve
  public (the audited origin may resolve privately, the crawl requests it),
  and the socket connects to the checked address with the name as SNI. Behind
  an HTTP proxy from the environment it does not run. A refused target is
  unreachable/EGRESS_REFUSED and nothing is sent.
- RunnerScope.tlsProbe -> ctx.tlsProbe on site rules; the CLI wires it for
  audit and analyze. With none (cloud, embedders) the rule reports
  "not checked" with the reason.
- CrawlerConfig.tlsProbe for the TLS root-failure cause: one handshake per
  origin, only for a failure that can still become the root failure, at most
  3 s or what the URL's watchdog has left. Without one the fetch's detail
  stands. The CLI wires it for audit and crawl.
- wwwVariant derives the counterpart from the registrable domain only (tldts,
  private suffixes included): no www.blog.example.com, no www.pages.dev.
- Hardening from the security review: the connect uses the URL parser's
  reading of the host and refuses one it reads differently (0x7f.1, a@b,
  x/y); socket errors use on("error"); certificate text loses control
  characters and is bounded (1000 names, 253 chars); messages list ten names
  and count the rest; the apex and www handshakes run at once (worst case one
  deadline); the guard test also covers export *, http2, dgram and Bun
  sockets.
- Review follow-ups: error_days <= warn_days refine; "expired less than a day
  ago" instead of "1 day ago"; IPv6 SAN entries compared canonically; the
  not-checked message no longer writes the code alone in parentheses (#2231
  guard); stalled-handshake and IP SAN tests.
- Docs: [rule_options."security/tls-certificate"] (the [rules] table ignores
  options), the guard, the first-error limit, a templated cause; hub
  regenerated. CHANGELOG entry re-added. Canonical golden: 102743 -> 102744
  findings, 311 -> 312 rules (skipped, not-https).

Signed-off-by: Nik Cubrilovic <[email protected]>
…ts www/apex counterpart #712

Review follow-ups on #716: under --offline the rule's probe contacts the
audited host only (the counterpart is unavailable, nothing resolved or sent);
comments say why an unreachable counterpart reports nothing, that analyze
reads the certificate as served now, and how the lookup and handshakes share
one deadline; the options schema is indented as an object. Docs and the
CHANGELOG entry name the --offline and analyze behaviour.

Signed-off-by: Nik Cubrilovic <[email protected]>
…#712

Review of 4cb7dd8: a site audited as https://example.com./ was not the same
host as example.com under --offline. siteOrigin now strips the root dot like
the probe's targets; a comment says why the counterpart reports only its
first problem.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the claude/712-tls-certificate branch from 4cb7dd8 to b0e9201 Compare October 27, 2026 09:56
@claude

claude Bot commented Oct 27, 2026

Copy link
Copy Markdown

Reviewed the diff, mainly the probe, the rule and the runner and controller wiring. I didn't run the tests, and CI was still pending when I looked. The design holds up: shared packages hold no socket code, every handshake goes through the egress guard, and the connection is pinned to the vetted address. I found nothing that should block merge.

  • (low) apps/cli/src/controllers/analyze.ts: analyzeStoredCrawl builds createTlsProbe({ siteUrl: crawl.baseUrl }) with no siteHostOnly. Re-analysing a stored crawl therefore contacts the live www/apex counterpart. audit restricts this under --offline. If analyze can be run offline, it should honour the same flag. If it can't, a comment saying so would help.
  • (low) apps/cli/src/audit/tls-probe.ts: with --offline, the audited host still gets a live handshake. The CHANGELOG states this, so it is intentional. Make sure docs/rules/security/tls-certificate.mdx and the --offline flag docs say it too, because users may read "offline" as "no network".
  • (low) packages/rules/src/security/tls-certificate.ts (wwwVariant): /^[\d.]+$/ rejects only dotted-decimal IPv4. Other numeric host spellings reach getDomain, which will likely return null for them. This is harmless but worth a test case.
  • (nit) packages/rules/src/security/tls-certificate.ts: this file uses trailing commas in multi-line parameter lists (deps: TlsCertificateDeps,), and several lines are over-long. The sibling rules are formatted differently. Run the pinned oxfmt --check on the new files, as AGENTS.md describes.
  • (nit) packages/rules/src/security/tls-certificate.ts (expiryCheck): the validFrom > now branch is only reached after the expiry check. That is fine. The not-yet-valid problem is skipped in certificateProblems and handled here, so a short comment tying the two together would stop a later cleanup from breaking it.
  • (nit) Test coverage looks broad: probe, cause, rule, pipeline, and the shared-package socket guard. As AGENTS.md asks, confirm you reverted the fix once and watched the new tests fail. Also confirm rule-verdict-scope, template-verdict-inputs and docs-rule-pages pass, since they only run registry-wide.

@nc9

nc9 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Replies to the review of b0e9201 (no blocking findings):

  • (low) analyze and --offline: squirrel analyze has no --offline flag (its only argument is --id), so there is no mode for the probe to honour. It re-reads the certificate as served now, and the code comment and the rule docs say so. This is deliberate.
  • (low) --offline still handshakes the audited host: this is deliberate, and docs/rules/security/tls-certificate.mdx says it ("With --offline, only the audited host is contacted"), as does the CHANGELOG entry. It is the same host the offline crawl itself fetches.
  • (low) wwwVariant and numeric hosts: the hostname always comes from URL.hostname, which canonicalises every IPv4 spelling (0x7f.1, 2130706433) to dotted decimal before it gets here, so no other spelling reaches getDomain. The CLI probe also refuses non-canonical hosts before any lookup (tested).
  • (nit) Formatting: public packages/* files are not under format:check in this repo. apps/cli is, and it passes.
  • (nit) not-yet-valid versus expiryCheck: noted. The continue on expired/not-yet-valid in the problem loop sits right next to it.
  • (nit) Registry-wide suites: docs-rule-pages, rule-verdict-scope and template-verdict-inputs pass locally (354 pass), as do the 2231 message guard and the canonical golden. Both of those failed first on this branch and were fixed. The no-socket guard regex was checked against sample offending imports (it flags them) and the allowed isIP import.

@claude

claude Bot commented Oct 27, 2026

Copy link
Copy Markdown

Reviewed the CLI wiring, tls-probe.ts and the controllers. The design is sound. The address is vetted once and the socket connects to that address with the name as SNI. Proxy, --offline and private-host handling are all explicit. I found nothing that should block the merge. I did not run the tests.

  • (low) apps/cli/src/audit/tls-probe.ts handshake(): a peer that closes the TCP connection cleanly before secureConnect fires only a close event, not error. The probe then waits out the full 8s timer before it reports ETIMEDOUT. Listening for close and finishing with a distinct code (for example ECONNRESET) would make that failure fast and more accurate. It matters most when the crawl's TLS failure cause waits on it.
  • (low) tls-probe.ts siteOrigin / allowPrivateTarget: the site port is 80 for an http: base URL, but the probe always targets 443 unless target.port is set. For an http:// site on a private-resolving name that is not recognised as non-public, the audited host never matches allowPrivateTarget, so it is refused as private. That is the safe direction, but the reported reason could be confusing. A short comment or a test would settle it.
  • (nit) The catch around connect() returns unavailable, while connect failures at runtime return unreachable. A one-line comment saying why would help.
  • (nit) In analyze.ts the probe is built even when the rule is disabled. That is cheap because the probe is lazy, so there is nothing to change.

* origin/main:
  feat(contracts): free plan renders 2 pages at once, up from 1 (#1207)
  ci(deps): daily dependency advisory check files one issue when the release gate fails (#1217)
  docs(rules): the SEO rules page counts 26 structured data rules (#1213)
  build(deps): ignore GHSA-gcqx-w48m-w2h4 (deepmerge via ultracite, dev tooling only) to unblock the release gate (#1216)
  chore(release): v0.0.138 notes and version bump (#1212)
  feat(report,rules): link sections, component-aware findings, fix rollups, Page structure block (#1181)
  fix(classifier): parse homepage URLs safely, backslash paths are not the root (#1206)
  build(deps): ignore GHSA-wx4j-mvgx-mqwp (satori, docs build only) to unblock the release gate (#1210)
@claude

claude Bot commented Oct 28, 2026

Copy link
Copy Markdown

Reviewed the TLS probe (apps/cli/src/audit/tls-probe.ts), the rule (packages/rules/src/security/tls-certificate.ts) and the certificate helpers (packages/utils/src/tls-certificate.ts). I did not read the CLI controller wiring, the docs or the tests in depth, and I did not run anything.

No blocking issues. The design holds up:

  • The handshake is injected rather than opened in the shared packages.
  • Every address goes through the egress guard and the socket connects to the vetted IP, with the name as SNI.
  • The probe skips the handshake behind an HTTP proxy and under --offline.
  • Certificate strings are control-character-stripped and length/count-bounded in readPeerCertificate.

Findings, all minor:

  • (low) packages/utils/src/tls-certificate.ts readPeerCertificate: SANs are split on ,. Node's format is DNS:a, DNS:b, and an attacker-controlled SAN value can contain , DNS:victim.com-style text. This only affects the names shown in messages and in the hostname check, and certificateCovers is evaluated against the same list Node produced, so the impact is small. Consider noting this in a comment, or reading raw.subjectaltname with Node's escaping rules in mind.
  • (low) apps/cli/src/audit/tls-probe.ts handshake: timeout: timeoutMs makes the socket emit an unhandled-by-design timeout event, and only the manual timer settles the promise. That works. Dropping the socket option would remove a second, redundant timer.
  • (low) tls-certificate.ts checkTlsCertificate: the www/apex probe runs on every audit even when the audited host has no www counterpart in DNS. The cost is bounded to one extra parallel handshake and the lookup is covered by the shared deadline, so this is only worth a mention in the docs as extra outbound contact beyond the audited host.
  • (nit) packages/rules/src/security/tls-certificate.ts is not oxfmt-formatted (trailing commas, long lines). Per AGENTS.md this is not checked in CI for packages/*, but running oxfmt --check on the new files would keep it consistent with the neighbouring rules.
  • (nit) certificateCovers: for a wildcard, an empty left label (.example.com against *.example.com) would count as covered, because host.slice(0, -suffix.length) is "". URL parsing makes that host unreachable in practice, but a > 0 length guard is cheap.

…no backtracking (CodeQL polynomial-redos) #712

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

claude Bot commented Oct 28, 2026

Copy link
Copy Markdown

Reviewed the diff, with most attention on apps/cli/src/audit/tls-probe.ts, the injected-probe wiring and the PR's design notes. I didn't run the tests.

  • (low) tls-probe.ts, handshake(): connect({ timeout }) sets a socket idle timeout, but no 'timeout' listener is registered. The setTimeout guard covers the deadline, so this is harmless. Dropping the option, or handling the event, would avoid confusion.
  • (low) tls-probe.ts, address loop: it falls through to the next address only for connect-level failures. A handshake timeout or reset on the first address (a common dual-stack symptom with a broken IPv6 route) is returned straight away. If you want fewer false "not checked" results on dual-stack hosts, consider also retrying on ETIMEDOUT. The time left in the shared budget is the limit.
  • (nit) siteOrigin's port comes from the site URL's scheme (80 for http). The probe's target.port defaults to 443. For an http audited site the private-target allowance then never matches a 443 probe. This looks intended, since the rule skips on a non-https site, but a short comment would help.
  • (nit) .replace(/^\[|\]$/g, "") and the trailing-dot strip are repeated in several places. A small bareHost() helper would reduce the drift risk.

Strengths:

  • The design keeps socket code out of the shared packages and has a guard test for it.
  • Egress vetting is done once per name, and the socket connects to the vetted address with SNI set to the name.
  • The proxy case is handled by reporting "not checked" instead of going around the proxy.
  • Certificate text from the server is stripped and capped before it is shown.
  • Test coverage is broad, including real loopback handshakes.
  • The golden pins and docs are updated.

No blocking issues found.

@nc9
nc9 merged commit 506509c into main Oct 28, 2026
15 checks passed
@nc9
nc9 deleted the claude/712-tls-certificate branch October 28, 2026 03:17
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.

New rule: TLS certificate expiry, hostname, chain and key checks (CLI first)

3 participants