Repository navigation
fix: stop serving the OAuth client secret - #108
Conversation
The Swagger UI's OAuth configuration included the configured client secret, but the Swagger UI runs in the browser and is a public client. Leave the secret out, pass the standard parameter names to the token request endpoint, and deprecate tesk.api.swagger-oauth.client-secret: it is ignored, and a warning at startup says so. Refs #106 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes #106 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Before 1.2.0 the Swagger UI was always on, so the advice applies to all deployments with the auth profile and a configured secret. Say that the authorisation code grant needs a provider that allows public clients without PKCE, and mark the API description test as a regression guard. Refs #106 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideAPIUpdate the Swagger OAuth configuration served to clients so it omits the client secret and uses standard OAuth parameter names for the authorisation-code flow.
ConfigurationDeprecate and ignore the configured Swagger client secret, warn at startup without logging its value, and remove the placeholder secret default.
DocumentationExplain the Swagger UI public-client setup and grant limitations, deprecation of the secret setting, and upgrade steps including secret rotation.
TestsCover safe startup warnings and verify the Swagger security configuration and API description do not expose a configured client secret.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #108 +/- ##
==========================================
+ Coverage 57.45% 57.73% +0.27%
==========================================
Files 64 64
Lines 2186 2191 +5
Branches 245 245
==========================================
+ Hits 1256 1265 +9
+ Misses 790 786 -4
Partials 140 140 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/main/java/uk/ac/ebi/tsc/tesk/config/swagger/SwaggerConfigAuth.java" line_range="64" />
<code_context>
} else {
- TokenRequestEndpoint tokenRequestEndpoint = new TokenRequestEndpoint(properties.getAuthorizationEndpoint(), properties.getClientId(), properties.getClientSecret());
+ //the names of the client's parameters (OAuth 2.0), not their values: the Swagger UI is a public client
+ TokenRequestEndpoint tokenRequestEndpoint = new TokenRequestEndpoint(properties.getAuthorizationEndpoint(), "client_id", "client_secret");
TokenEndpoint tokenEndpoint = new TokenEndpoint(properties.getTokenEndpoint(), "access_token");
grantTypes.add(new AuthorizationCodeGrant(tokenRequestEndpoint, tokenEndpoint));
</code_context>
<issue_to_address>
**Authorization codes lack interception protection**
When operators select the authorization-code grant and their identity provider allows public clients to use it without PKCE, `TokenRequestEndpoint` configures the public client’s authorization-code flow without PKCE or client authentication, so an intercepted redirect code can be redeemed by an attacker for the user’s access token.
Add PKCE support, or disable the authorization-code grant until PKCE is available.
</issue_to_address>
### Comment 2
<location path="src/main/java/uk/ac/ebi/tsc/tesk/config/swagger/SwaggerConfigAuth.java" line_range="116" />
<code_context>
+ * Warns about the deprecated client secret setting, which is ignored.
+ */
+ @PostConstruct
+ public void warnAboutClientSecret() {
+ deprecatedClientSecretWarning(this.properties).ifPresent(logger::warn);
+ }
</code_context>
<issue_to_address>
**Deprecated secret goes unwarned**
When the deprecated secret is set while the noauth profile is active, `noauth` excludes `SwaggerConfigAuth`, so `warnAboutClientSecret()` never calls `deprecatedClientSecretWarning` or logs the setting, and operators receive no startup warning.
Register the startup warning in a configuration that is active for both `auth` and `noauth` profiles.
</issue_to_address>
### Comment 3
<location path="src/test/java/uk/ac/ebi/tsc/tesk/config/swagger/DeprecatedClientSecretWarningTest.java" line_range="20" />
<code_context>
+ private static Optional<String> warningFor(String clientSecret) {
+ OAuth2ClientProperties properties = new OAuth2ClientProperties();
+ properties.setClientSecret(clientSecret);
+ return SwaggerConfigAuth.deprecatedClientSecretWarning(properties);
+ }
+
</code_context>
<issue_to_address>
**Startup warning goes untested**
When the `@PostConstruct` logging call is removed or no longer sends the helper's result to the logger, `DeprecatedClientSecretWarningTest.set_warnsWithoutTheSecret` calls the warning helper directly at line 20 and checks only its returned string; removing the startup logging call still lets the test pass, while operators receive no warning.
Add a test that starts the configuration and verifies the startup log contains the warning without the secret.
</issue_to_address>Linked issues
#106 fix: stop serving the OAuth client secret · 4 of 4 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Keep the configured client secret out of /swagger-resources/configuration/security and /v2/api-docs. |
✅ Met | The security configuration no longer sets a client secret, and regression tests check both endpoints with a configured secret. |
| 2 | Deprecate and ignore the client-secret setting, use public-client OAuth configuration, and warn at startup without logging the secret. | ✅ Met | The property and accessors are deprecated, the secret is only read to produce a conditional startup warning, and authorization-code configuration uses the standard parameter names. |
| 3 | Tell operators to rotate the secret at their identity provider when it was configured while the Swagger UI was on. | ✅ Met | The upgrade notes advise rotation for deployments where the UI was on with a configured secret. |
| 4 | Add regression tests and update the configuration, access-control, and upgrade documentation. | ✅ Met | Tests cover secret absence and the conditional, secret-free warning; all three requested documentation files are updated. |
Sourcery assessment
Approval pending. 3 findings to address first.
Blocking findings: src/main/java/uk/ac/ebi/tsc/tesk/config/swagger/SwaggerConfigAuth.java:64, src/main/java/uk/ac/ebi/tsc/tesk/config/swagger/SwaggerConfigAuth.java:116, src/test/java/uk/ac/ebi/tsc/tesk/config/swagger/DeprecatedClientSecretWarningTest.java:20
Move the startup warning about the deprecated setting from the auth Swagger configuration to the properties, which every profile loads, and test that the startup check logs it without the secret. Refs #106 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
The Swagger UI runs in the browser, so it is a public client. This PR treats it as one.
/swagger-resources/configuration/security).client_id,client_secret). Before, it was passed the configured values.tesk.api.swagger-oauth.client-secret(TESK_API_SWAGGER_OAUTH_CLIENT_SECRET) is deprecated and ignored:@Deprecatedand has@DeprecatedConfigurationProperty;application.properties.configuration.md: the setting is deprecated.access-control.md: register the Swagger UI as a public client. Its authorisation code grant needs an identity provider that allows public clients without PKCE.upgrading.md("To 1.2.0"): remove the setting, and rotate the secret if it was configured while the Swagger UI was on (always the case before 1.2.0, with theauthprofile).PKCE: springfox 3.0.0 doesn't pass a PKCE option to the Swagger UI (
SecurityConfigurationhas none), so the docs say that the Swagger UI can't use PKCE yet. The implicit grant stays the default.Closes #106
Verification
Tests first:
SwaggerOAuthClientSecretTest.securityConfiguration_hasNoClientSecretfails ondevand passes now.apiDescription_hasNoClientSecretis a regression guard for/v2/api-docs.DeprecatedClientSecretWarningTestandstartupCheck_logsWarningWithoutSecretcover the startup warning: it is only logged when the setting is set, and never contains the value../mvnw verifyon Java 8 (Temurin 8.0.504): all unit and integration tests pass (after mergingdev). Every changed line is covered (JaCoCo, checked locally).mkdocs build --strictpasses.Full review (adversarial and quality reviewers), round 1 found no high findings. Fixed:
Sourcery: 3 threads. Two are fixed: the warning now comes with any profile, and the startup log is tested. One is answered: PKCE needs a newer Swagger UI integration than springfox 3.0.0; the authorisation code grant is opt-in and documented. All resolved.
Declined review findings
client_id/client_secretin the API description (low). springfox 3.0.0 doesn't serialise these names, so a test couldn't observe them.access-control.md(low, taste). Left as is.Open questions
None.
🤖 Generated with Claude Code
Summary by Sourcery
Treat the Swagger UI as a public OAuth client without serving or using a client secret.
Bug Fixes:
Enhancements:
Documentation:
Tests: