Skip to content

fix(security)!: deny requests when no auth mode is enabled and validate JWT iss/aud - #193

Merged
evebrnd merged 2 commits into
mainfrom
fix/security-default-deny-and-jwt-claims
Nov 18, 2026
Merged

evebrnd merged 2 commits into
mainfrom
fix/security-default-deny-and-jwt-claims

Conversation

@mmornati

Copy link
Copy Markdown
Contributor

PR Description

What this PR Provides

Two authentication hardening fixes. They are in one PR because they touch the same configuration area; the two parts are independent and can be reviewed separately.

1. Fail closed when no authentication mode is enabled

  • Problem: only the public chain and the webhook chain declare a request matcher. Every authenticated chain (jwt, oauth2-login, api-key, mock) is conditional on its own flag. With all flags false, as in application-local.yml, /api/v1/** matched no filter chain and was served with no authentication and no authorization.
  • Fix: new FallbackDenyAllFilterChainConfig. It is registered only when none of the four modes is enabled, has the lowest precedence, denies every remaining request, and logs a warning at startup.
  • Why conditional instead of always present: the authenticated chains already match any request, and Spring Security rejects a chain declared after an any-request chain as unreachable.

Checked on a running instance with every mode disabled, no token:

Request Before After
GET /api/v1/entity-templates 200 403
POST /api/v1/entity-templates 201 (template created) 403
GET /actuator/health 200 200
GET /v3/api-docs 200 200
POST /webhooks/unknown 404 404

2. Validate the JWT issuer and audience

  • Problem: JwtConfiguration built the decoder with the JWKS URI only, so tokens were checked for signature and timestamps. Any token signed by the identity provider was accepted, including tokens issued for other applications.
  • Fix: two optional settings, validated when present.
Property Env var Effect when set
app.security.authentication.jwt.issuer-uri OAUTH_ISSUER_URI iss must match
app.security.authentication.jwt.audiences OAUTH_AUDIENCES (comma-separated) aud must contain at least one value
  • When either is unset, behaviour is unchanged and a warning is logged at startup. This keeps existing deployments working; I recommend making both mandatory in a follow-up once environments are configured.

Breaking change

  • A deployment or local profile that runs with every authentication mode disabled now gets 403 on the API instead of open access. For local development, enable app.security.authentication.mock.enabled=true.

Tests

  • FallbackDenyAllFilterChainConfigTest: chain present with no property, present with all modes explicitly off, absent when any one mode is on (6 cases).
  • JwtConfigurationTest: nothing configured, expired token, wrong issuer, wrong audience, missing audience (5 cases).
  • ./mvnw verify: 1,690 tests, 0 failures.
  • docs/src/concepts/authentication.md updated.

Not covered here

  • oauth2-login.enabled=true without a ClientRegistrationRepository bean: the OAuth2 chain is skipped by @ConditionalOnBean while the fallback sees the flag as enabled. I did not reproduce this case; it deserves its own test.
  • Identity is still taken from the email claim without email_verified; the admin allow-list is not issuer-scoped. Separate change.
  • Two modes enabled at once (for example jwt and oauth2-login, both @Order(2) and any-request) is not addressed.

Fixes

Found during the idp-core audit of 2026-11-17.

Review

The reviewer must double-check these points:

  • The reviewer has tested the feature
  • The reviewer has reviewed the implementation of the feature
  • The documentation has been updated
  • The Pull Request title has a ! after the type/scope to identify the breaking change

…te JWT iss/aud

Fail-closed fallback
- Only the public and webhook filter chains declare a request matcher. When
  jwt, oauth2-login, api-key and mock are all disabled, /api/v1/** matched no
  chain and was served without authentication or authorization.
- Add FallbackDenyAllFilterChainConfig: registered only when no mode is
  enabled, lowest precedence, denies every remaining request and logs a
  warning at startup.

JWT issuer and audience
- The decoder validated signature and timestamps only, so any token signed by
  the identity provider was accepted, including tokens issued for other
  applications.
- Add optional app.security.authentication.jwt.issuer-uri (OAUTH_ISSUER_URI)
  and .audiences (OAUTH_AUDIENCES). When set, iss and aud are validated. When
  unset, behaviour is unchanged and a warning is logged.

BREAKING CHANGE: a deployment or local profile that runs with every
authentication mode disabled now gets 403 on the API instead of open access.
@github-code-quality

github-code-quality Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Java

Java / code-coverage/jacoco

main 38620a2 fix/security-default... 8f454d0 +/-
91% 91% 0%
View coverage of the 2 most impacted files.
File main 38620a2 fix/security-default... 8f454d0 +/-
com/decathlon/i...figuration.java 75% 86% +11%
com/decathlon/i...hainConfig.java 0% 67% +67%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated November 18, 2026 09:54 UTC

@mmornati
mmornati marked this pull request as ready for review November 17, 2026 06:52
@mmornati mmornati self-assigned this Nov 17, 2026
@mmornati mmornati added the enhancement New feature or request label Nov 17, 2026
@sonarqubecloud

Copy link
Copy Markdown

@evebrnd
evebrnd merged commit 465cfb5 into main Nov 18, 2026
20 of 21 checks passed
@evebrnd
evebrnd deleted the fix/security-default-deny-and-jwt-claims branch November 18, 2026 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants