Commit 8476563
authored
Reject URIs containing '@' in name constraint checking (#3202)
### Issues:
Addresses P422947832
### Description of changes:
`nc_uri()` extracts the host from a URI by scanning for `:` (port) then
`/` (path start). It does not account for the `@` delimiter that
separates optional userinfo from the host in RFC 3986 §3.2 (authority =
`[userinfo "@"] host [":" port]`). Since `:` is permitted inside
userinfo, a URI like `spiffe://x.team-a.corp:x@team-b.corp/admin` causes
nc_uri() to extract x`.team-a.corp` as the host instead of the actual
host `team-b.corp`
This change makes three improvements to nc_uri():
1. Reject `@` in authority — URIs containing userinfo are rejected with
`X509_V_ERR_UNSUPPORTED_NAME_SYNTAX`. Certificate SAN URIs have no
standards-defined use for userinfo, so rejecting is the correct
fail-closed behavior — consistent with the IPv6 literal rejection added
in `fed51c342`. The @ scan stops at /, ?, or # (the characters that
terminate the authority per RFC 3986), so @ appearing in the path (e.g.,
`foo://example.com/@user`) is not affected.
2. Trailing dot normalization — Strip trailing dots from both the host
and constraint before comparison, so `team-a.corp.` and `team-a.corp`
are treated as the same FQDN (RFC 1034 §3.1). This matches the existing
normalization in nc_dns().
3. FQDN validation — Validate that the extracted host contains only
characters valid in a DNS name (`a-zA-Z0-9-.`) per RFC 1034 §3.5. RFC
5280 §4.2.1.10 requires the host to be a fully qualified domain name, so
any host containing percent-encoding, `?`, `#`, or other non-FQDN
characters is rejected. This prevents equivalence bypasses (e.g.,
`b%61d.com` evading an exclusion for .bad.com).
### Call-outs:
This intentionally rejects rather than normalizes percent-encoded hosts.
RFC 5280 requires the host to be a FQDN, and `%` is not a valid FQDN
character — a conformant CA should never issue such a cert. Rejecting is
stricter than the RFC 3986 §6.2.2.2 SHOULD-level normalization guidance,
but avoids being more permissive than the standard.
### Testing:
Nine new cases in `X509Test.NameConstraints`:
- Basic `user@host` rejection
- Colon-in-userinfo bypass
(`spiffe://x.team-a.corp:x@team-b.corp/admin`) tested against both the
fake and real host constraints
- Userinfo with path, query, and fragment variants
- `@` in path (after `/`) is correctly not rejected
All 102 existing X509 tests pass.
By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license and the ISC license.1 parent 64d6586 commit 8476563
2 files changed
Lines changed: 106 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
686 | 686 | | |
687 | 687 | | |
688 | 688 | | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
689 | 704 | | |
690 | 705 | | |
691 | 706 | | |
| |||
698 | 713 | | |
699 | 714 | | |
700 | 715 | | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
701 | 745 | | |
702 | 746 | | |
703 | 747 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2640 | 2640 | | |
2641 | 2641 | | |
2642 | 2642 | | |
| 2643 | + | |
| 2644 | + | |
| 2645 | + | |
| 2646 | + | |
| 2647 | + | |
| 2648 | + | |
| 2649 | + | |
| 2650 | + | |
| 2651 | + | |
| 2652 | + | |
| 2653 | + | |
| 2654 | + | |
| 2655 | + | |
| 2656 | + | |
| 2657 | + | |
| 2658 | + | |
| 2659 | + | |
| 2660 | + | |
| 2661 | + | |
| 2662 | + | |
| 2663 | + | |
| 2664 | + | |
| 2665 | + | |
| 2666 | + | |
| 2667 | + | |
| 2668 | + | |
| 2669 | + | |
| 2670 | + | |
| 2671 | + | |
| 2672 | + | |
| 2673 | + | |
| 2674 | + | |
| 2675 | + | |
| 2676 | + | |
| 2677 | + | |
| 2678 | + | |
| 2679 | + | |
| 2680 | + | |
| 2681 | + | |
| 2682 | + | |
| 2683 | + | |
| 2684 | + | |
| 2685 | + | |
| 2686 | + | |
| 2687 | + | |
| 2688 | + | |
| 2689 | + | |
| 2690 | + | |
| 2691 | + | |
| 2692 | + | |
| 2693 | + | |
| 2694 | + | |
| 2695 | + | |
| 2696 | + | |
| 2697 | + | |
| 2698 | + | |
| 2699 | + | |
| 2700 | + | |
| 2701 | + | |
| 2702 | + | |
| 2703 | + | |
| 2704 | + | |
2643 | 2705 | | |
2644 | 2706 | | |
2645 | 2707 | | |
| |||
0 commit comments