Skip to content

fix: stop serving the OAuth client secret - #108

Merged
uniqueg merged 5 commits into
devfrom
fix/swagger-client-secret
Nov 7, 2026
Merged

uniqueg merged 5 commits into
devfrom
fix/swagger-client-secret

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Summary

The Swagger UI runs in the browser, so it is a public client. This PR treats it as one.

  • TESK API stops serving the client secret in the Swagger UI's OAuth configuration (/swagger-resources/configuration/security).
  • The token request endpoint gets the standard parameter names (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:
    • it is marked @Deprecated and has @DeprecatedConfigurationProperty;
    • TESK API logs a warning at startup if it is set, without the value, with any profile;
    • the placeholder default is removed from application.properties.
  • Docs:
    • 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 the auth profile).

PKCE: springfox 3.0.0 doesn't pass a PKCE option to the Swagger UI (SecurityConfiguration has 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_hasNoClientSecret fails on dev and passes now.
    • apiDescription_hasNoClientSecret is a regression guard for /v2/api-docs.
    • DeprecatedClientSecretWarningTest and startupCheck_logsWarningWithoutSecret cover the startup warning: it is only logged when the setting is set, and never contains the value.
  • ./mvnw verify on Java 8 (Temurin 8.0.504): all unit and integration tests pass (after merging dev). Every changed line is covered (JaCoCo, checked locally).

  • mkdocs build --strict passes.

  • Full review (adversarial and quality reviewers), round 1 found no high findings. Fixed:

    • the medium finding: the rotation advice now covers every deployment before 1.2.0, not only those that had turned the Swagger UI on;
    • the lows: the note on public clients without PKCE, and the test described as a regression guard.
  • 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

  • Assert client_id/client_secret in the API description (low). springfox 3.0.0 doesn't serialise these names, so a test couldn't observe them.
  • Shared constants for the test secret and the parameter names; split the long paragraph in 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:

  • Stop exposing the Swagger UI OAuth client secret through its security configuration and API description.
  • Use standard OAuth parameter names for authorization-code token requests instead of configured secret values.

Enhancements:

  • Deprecate and ignore the Swagger UI client-secret setting, with a startup warning that omits the configured secret.
  • Document the Swagger UI as a public client, including its grant and PKCE limitations and required secret rotation during upgrade.

Documentation:

  • Update configuration, access-control, and upgrade documentation for the public Swagger UI OAuth client behavior.

Tests:

  • Add regression coverage ensuring client secrets are absent from Swagger endpoints and startup warnings.

uniqueg and others added 3 commits November 7, 2026 15:48
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]>
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]>
@uniqueg uniqueg added this to the v1.2.0 milestone Nov 7, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Update the Swagger OAuth configuration served to clients so it omits the client secret and uses standard OAuth parameter names for the authorisation-code flow.

  • src/main/java/uk/ac/ebi/tsc/tesk/config/swagger/SwaggerConfigAuth.java L57-58, L94-97, L102 (removed lines)

Configuration

Deprecate and ignore the configured Swagger client secret, warn at startup without logging its value, and remove the placeholder secret default.

  • src/main/java/uk/ac/ebi/tsc/tesk/config/swagger/OAuth2ClientProperties.java L4-14, L117-138 (+4 small edits)
  • src/main/resources/application.properties L63 (removed lines)

Documentation

Explain the Swagger UI public-client setup and grant limitations, deprecation of the secret setting, and upgrade steps including secret rotation.

  • docs/access-control.md L32
  • docs/configuration.md L35
  • docs/upgrading.md L73-82

Tests

Cover safe startup warnings and verify the Swagger security configuration and API description do not expose a configured client secret.

  • src/test/java/uk/ac/ebi/tsc/tesk/config/swagger/DeprecatedClientSecretWarningTest.java L1-37
  • src/test/java/uk/ac/ebi/tsc/tesk/config/swagger/SwaggerOAuthClientSecretTest.java L1-75

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 57.73%. Comparing base (caa53a3) to head (80ef640).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review November 7, 2026 15:22

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

uniqueg and others added 2 commits November 7, 2026 16:40
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]>
@uniqueg
uniqueg merged commit c569334 into dev Nov 7, 2026
29 of 34 checks passed
@uniqueg
uniqueg deleted the fix/swagger-client-secret branch November 7, 2026 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: stop serving the OAuth client secret

1 participant