Repository navigation
strip trailing dot before matching spki pinning rules - #902
Conversation
|
@arturobernalg What about this PR? |
@ok2c I'll check it today. |
There was a problem hiding this comment.
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.
|
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 Please cherry-pick to |
done |
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.