Skip to content

strip trailing dot before matching spki pinning rules - #902

Merged
arturobernalg merged 2 commits into
apache:masterfrom
dxbjavid:spki-pin-trailing-dot
Nov 4, 2026
Merged

arturobernalg merged 2 commits into
apache:masterfrom
dxbjavid:spki-pin-trailing-dot

Conversation

@dxbjavid

Copy link
Copy Markdown
Contributor

SpkiPinningClientTlsStrategy matches pin rules against the host exactly as given, so a request to https://api.example.com./ yields api.example.com. and no rule applies, while the default built-in hostname check still accepts it because the JDK drops the root dot from SNI. In practice any CA-trusted certificate for a pinned host appears to be accepted whenever the URL is spelt in its absolute form (for instance after a redirect), which rather defeats the pinning; against a local TLS server with a non-matching pin the plain host is rejected while the dotted one returns 200. The patch strips a single trailing dot from both the request host and the configured patterns before matching, with a regression test covering the exact and wildcard cases.

@ok2c

ok2c commented Nov 1, 2026

Copy link
Copy Markdown
Member

@arturobernalg What about this PR?

@arturobernalg

Copy link
Copy Markdown
Member

@arturobernalg What about this PR?

@ok2c I'll check it today.

@arturobernalg arturobernalg left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wildcard validation runs before stripping the trailing dot. As a result, *.com. is accepted and normalized to *.com, which would otherwise be rejected.

Please normalize before validating and add a regression test.

It would also be good to cover a valid pin with a trailing-dot hostname, trailing-dot rule patterns (exact and wildcard), and single-label wildcard matching.

@dxbjavid

dxbjavid commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Good catch. The pattern is now normalised straight after the IDN step, before the empty and wildcard checks, so ".com." is rejected the same way ".com" is. Running the existing tests showed that the obvious version of this had a hole of its own: "." strips down to a bare "" and would have slipped past the startsWith(".") check as an exact host, so the wildcard check now treats any pattern beginning with "" as a wildcard attempt and requires the .label.label shape. A side effect is that a bare "" is rejected too, where before it went in as a harmless exact rule that could never match.

Tests added for ".com." and "" being rejected, a valid pin with a trailing-dot host going through verifySession, trailing-dot rule patterns in both exact and wildcard form matched against the plain and the dotted host, and the single-label check for "*.example.com." against a.b.example.com and example.com.

@arturobernalg arturobernalg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dxbjavid LGTM

@arturobernalg
arturobernalg merged commit b0bdae9 into apache:master Nov 4, 2026
10 checks passed
@ok2c

ok2c commented Nov 4, 2026

Copy link
Copy Markdown
Member

@arturobernalg Please cherry-pick to 5.6.x

@arturobernalg

Copy link
Copy Markdown
Member

@arturobernalg Please cherry-pick to 5.6.x

done

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.

3 participants