@@ -7,9 +7,6 @@ namespace CIMD.IdentityServer;
77/// CIMD policy that ensures all CIMD clients receive the scopes needed to
88/// access our protected resources. CIMD documents (e.g., VS Code's) typically
99/// don't declare any scopes, so this policy adds them server-side.
10- ///
11- /// Also validates that redirect URIs share the same origin as the client_id,
12- /// as recommended by CIMD spec section 6.1.
1310/// </summary>
1411internal sealed class McpCimdPolicy : ICimdPolicy
1512{
@@ -29,16 +26,22 @@ public Task<CimdPolicyResult> ValidateDocumentAsync(
2926 CancellationToken ct ) =>
3027 Task . FromResult ( CimdPolicyResult . Allow ) ;
3128
32- public Task < CimdPolicyResult > ValidateRedirectUriAsync ( Uri redirectUri , CimdRequestContext context , CancellationToken ct )
33- {
34- var clientUri = context . ClientUri ;
29+ public Task < CimdPolicyResult > ValidateRedirectUriAsync ( Uri redirectUri , CimdRequestContext context , CancellationToken ct ) =>
30+ // Per CIMD section 6.1, the authorization server MAY restrict
31+ // redirect URIs to the same origin as the client_id. This sample allows
32+ // all redirect URIs so that loopback-based clients (e.g., VS Code) work
33+ // out of the box. To enable same-origin enforcement, uncomment below:
34+ //
35+ // var clientUri = context.ClientUri;
36+ // var sameOrigin = string.Equals(redirectUri.Scheme, clientUri.Scheme, StringComparison.OrdinalIgnoreCase)
37+ // && string.Equals(redirectUri.Host, clientUri.Host, StringComparison.OrdinalIgnoreCase)
38+ // && redirectUri.Port == clientUri.Port;
39+ //
40+ // if (!sameOrigin)
41+ // {
42+ // return Task.FromResult(
43+ // CimdPolicyResult.Deny($"Redirect URI '{redirectUri}' does not share the same origin as the client_id '{clientUri}'."));
44+ // }
3545
36- var sameOrigin = string . Equals ( redirectUri . Scheme , clientUri . Scheme , StringComparison . OrdinalIgnoreCase )
37- && string . Equals ( redirectUri . Host , clientUri . Host , StringComparison . OrdinalIgnoreCase )
38- && redirectUri . Port == clientUri . Port ;
39-
40- return Task . FromResult ( sameOrigin
41- ? CimdPolicyResult . Allow
42- : CimdPolicyResult . Deny ( $ "Redirect URI '{ redirectUri } ' does not share the same origin as the client_id '{ clientUri } '.") ) ;
43- }
46+ Task . FromResult ( CimdPolicyResult . Allow ) ;
4447}
0 commit comments