Skip to content

Commit c3f86d1

Browse files
committed
Issuer should not support path component
Closes spring-projectsgh-1435
1 parent 5286aff commit c3f86d1

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/config/annotation/web/configurers/OAuth2AuthorizationServerConfigurer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2022 the original author or authors.
2+
* Copyright 2020-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,6 +48,7 @@
4848
import org.springframework.security.web.util.matcher.OrRequestMatcher;
4949
import org.springframework.security.web.util.matcher.RequestMatcher;
5050
import org.springframework.util.Assert;
51+
import org.springframework.util.StringUtils;
5152

5253
/**
5354
* An {@link AbstractHttpConfigurer} for OAuth 2.0 Authorization Server support.
@@ -331,6 +332,9 @@ private static void validateAuthorizationServerSettings(AuthorizationServerSetti
331332
} catch (Exception ex) {
332333
throw new IllegalArgumentException("issuer must be a valid URL", ex);
333334
}
335+
if (StringUtils.hasText(issuerUri.getPath())) {
336+
throw new IllegalArgumentException("Path component for issuer ('" + issuerUri.getPath() + "') is currently not supported");
337+
}
334338
// rfc8414 https://datatracker.ietf.org/doc/html/rfc8414#section-2
335339
if (issuerUri.getQuery() != null || issuerUri.getFragment() != null) {
336340
throw new IllegalArgumentException("issuer cannot contain query or fragment component");

oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/config/annotation/web/configurers/OidcProviderConfigurationTests.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ public void loadContextWhenIssuerNotValidUriThenThrowException() {
161161
);
162162
}
163163

164+
@Test
165+
public void loadContextWhenIssuerWithPathThenThrowException() {
166+
assertThatThrownBy(
167+
() -> this.spring.register(AuthorizationServerConfigurationWithIssuerPath.class).autowire()
168+
);
169+
}
170+
164171
@Test
165172
public void loadContextWhenIssuerWithQueryThenThrowException() {
166173
assertThatThrownBy(
@@ -182,6 +189,13 @@ public void loadContextWhenIssuerWithQueryAndFragmentThenThrowException() {
182189
);
183190
}
184191

192+
@Test
193+
public void loadContextWhenIssuerWithEmptyPathThenThrowException() {
194+
assertThatThrownBy(
195+
() -> this.spring.register(AuthorizationServerConfigurationWithIssuerEmptyPath.class).autowire()
196+
);
197+
}
198+
185199
@Test
186200
public void loadContextWhenIssuerWithEmptyQueryThenThrowException() {
187201
assertThatThrownBy(
@@ -299,6 +313,15 @@ AuthorizationServerSettings authorizationServerSettings() {
299313
}
300314
}
301315

316+
@EnableWebSecurity
317+
static class AuthorizationServerConfigurationWithIssuerPath extends AuthorizationServerConfiguration {
318+
319+
@Bean
320+
AuthorizationServerSettings authorizationServerSettings() {
321+
return AuthorizationServerSettings.builder().issuer(ISSUER_URL + "/issuer1").build();
322+
}
323+
}
324+
302325
@EnableWebSecurity
303326
static class AuthorizationServerConfigurationWithIssuerQuery extends AuthorizationServerConfiguration {
304327

@@ -326,6 +349,15 @@ AuthorizationServerSettings authorizationServerSettings() {
326349
}
327350
}
328351

352+
@EnableWebSecurity
353+
static class AuthorizationServerConfigurationWithIssuerEmptyPath extends AuthorizationServerConfiguration {
354+
355+
@Bean
356+
AuthorizationServerSettings authorizationServerSettings() {
357+
return AuthorizationServerSettings.builder().issuer(ISSUER_URL + "/").build();
358+
}
359+
}
360+
329361
@EnableWebSecurity
330362
static class AuthorizationServerConfigurationWithIssuerEmptyQuery extends AuthorizationServerConfiguration {
331363

0 commit comments

Comments
 (0)