Commit 05ca226
authored
dcr: support RFC 8414 §3.1 path-insertion in discovery-URL → issuer derivation (#5395)
* dcr: support RFC 8414 §3.1 path-insertion in discovery-URL → issuer derivation
`deriveExpectedIssuerFromDiscoveryURL` recovers the issuer the upstream is
expected to claim in its discovery document. It already handled the
suffix-append form (e.g. https://mcp.atlassian.com/.well-known/oauth-authorization-server
→ https://mcp.atlassian.com) and the issuer-suffix multi-tenant style
(.../tenants/acme/.well-known/openid-configuration → .../tenants/acme),
but the comment block explicitly opted out of the RFC 8414 §3.1
path-insertion form — operators on that pattern had to fall back to
`dcr_config.registration_endpoint` to bypass discovery entirely.
That gap rejects providers that publish a path-component issuer per the
letter of the RFC. Datadog's MCP authorization server is one such
provider: its discovery URL
`https://mcp.us5.datadoghq.com/.well-known/oauth-authorization-server/v1/mcp`
declares issuer `https://mcp.us5.datadoghq.com/v1/mcp`, and DCR
discovery aborts with:
issuer mismatch (RFC 8414 §3.3): expected
"https://mcp.us5.datadoghq.com", got "https://mcp.us5.datadoghq.com/v1/mcp"
Recognise the path-insertion form by checking for the well-known segment
as a path *prefix* followed by a tenant path (HasPrefix(path, suffix+"/")),
trimming just the well-known segment to recover origin + tenant path.
Disambiguated from the existing suffix-append case by position: the
well-known segment at the end of the path is suffix-append; at the start
with more path following is path-insertion. The two cases cannot both
match a single URL.
Tests cover the new branch for both the OAuth and OIDC suffix variants
plus a multi-segment tenant. All existing cases continue to pass.
Per RFC 8414 §3 (the well-known URI is formed by inserting the
well-known suffix between host and path of the issuer) and RFC 8615
(well-known URI conventions).
Signed-off-by: Juzer Patanwala <juzer.patanwala@project44.com>
* dcr: normalise trailing-slash bare well-known to origin (review feedback)
Per @tgrunnagle's review on #5395: the path-insertion arms introduced in
the previous commit accidentally regress one edge case. For an input
where the path ends `/.well-known/oauth-authorization-server/` (trailing
slash, no tenant), the suffix arms don't match (suffix test sees the
trailing "/"), so the HasPrefix arm fires and TrimPrefix leaves
`u.Path = "/"` → spurious issuer `https://host/` that fails the §3.3
byte-equality check against the upstream's declared `https://host`.
Before this PR the same input hit the `default` arm and produced
`https://host` correctly.
Fix: after TrimPrefix in each path-insertion arm, collapse a lone
`/` back to empty so the trailing-slash form converges on the same
origin issuer the bare-suffix and `default` arms produce.
Tightens the inline comment to describe both shapes that reach the
HasPrefix arm (real tenant suffix and trailing-slash). Adds two
table-driven cases — one each for the oauth and oidc trailing-slash
forms — to lock in the expected origin output.
Signed-off-by: Juzer Patanwala <juzer.patanwala@project44.com>
---------
Signed-off-by: Juzer Patanwala <juzer.patanwala@project44.com>1 parent 2d59159 commit 05ca226
2 files changed
Lines changed: 79 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
899 | 899 | | |
900 | 900 | | |
901 | 901 | | |
902 | | - | |
| 902 | + | |
903 | 903 | | |
904 | 904 | | |
905 | 905 | | |
906 | 906 | | |
907 | 907 | | |
908 | | - | |
909 | | - | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
910 | 911 | | |
911 | | - | |
912 | | - | |
913 | | - | |
914 | | - | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
915 | 923 | | |
916 | | - | |
917 | | - | |
918 | | - | |
919 | | - | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
920 | 927 | | |
921 | 928 | | |
922 | 929 | | |
| |||
932 | 939 | | |
933 | 940 | | |
934 | 941 | | |
| 942 | + | |
935 | 943 | | |
936 | 944 | | |
937 | 945 | | |
938 | 946 | | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
939 | 972 | | |
940 | 973 | | |
941 | 974 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
962 | 962 | | |
963 | 963 | | |
964 | 964 | | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
965 | 1000 | | |
966 | 1001 | | |
967 | 1002 | | |
| |||
0 commit comments