Skip to content

Authorization Server and Data Custodian: H2 console settings (web-allow-others: true on the AS; no console module; DC permitAll) #271

Open

Description

@dfcoffin

Summary

While fixing the Third Party's H2 console in #270, I found that the Authorization Server's and Data Custodian's console settings are unsafe or do nothing. None of this can be exploited today, because no console exists in either module (see 1). It becomes exploitable as soon as someone adds the console dependency to restore it.

Findings

  1. No module has the H2 console. Spring Boot 4 moved the console's auto-configuration into org.springframework.boot:spring-boot-h2console. The AS and the DC don't depend on it, so their spring.h2.console.* settings do nothing since the Boot 4 migration. fix(thirdparty): address the #268 review of Third Party form login (#249) #270 adds it to the Third Party only.
  2. AS local allows remote access: openespi-authserver/src/main/resources/application-local.yml sets spring.h2.console.web-allow-others: true. Once the console exists, any machine that can reach the AS's port can open it. The console runs any SQL, and H2's CREATE ALIAS runs Java code. The AS database also holds the OAuth client secrets, authorizations and tokens.
  3. AS has no rule for /h2-console. Whatever the AS's default rule allows applies to it, and nothing exempts it from CSRF, which the console needs to work.
  4. DC allows it with no sign-in: openespi-datacustodian/.../config/SecurityConfiguration.java lists /h2-console/** under permitAll(). DC local sets web-allow-others: false (localhost only), which is good. But with no sign-in required, any web page open in the developer's browser could send requests to localhost and reach the console.

Proposed fix

Follow the Third Party's final design from #270 in each module that keeps a console:

  • A development-only chain: a configuration with its own filter chain for /h2-console/**, loaded only when spring.h2.console.enabled=true. The module's main chain denies /h2-console/** (the DC's permitAll() goes), so the console stays shut in every other profile.
  • In that chain:
    • Require a signed-in administrator (DC: ROLE_CUSTODIAN from the form-login session; AS: its admin login).
    • Require that requests come from the console itself, as the TP's SameOriginFetchAuthorizationManager does (it could move to a shared module). The entry page (a parameterless GET) may be Sec-Fetch-Site: same-origin or none. Every other request must be same-origin and carry a Referer from a console page.
    • Save only the entry page for the redirect back after sign-in, with no ?continue marker.
    • Turn off CSRF tokens for the console only, send anonymous users to the login page, and allow same-origin frames.
    • Build the path from spring.h2.console.path with trailing slashes removed. /h2-console/ + /** would match nothing.
    • Why all of this: session cookies don't stop other pages, because every localhost port is the same site, so SameSite=Lax still sends the cookie from a page on another local port. Sec-Fetch-Site alone doesn't stop the sign-in redirect either, because the redirect after the login POST arrives as same-origin. Unchecked, an attacker's console action could be saved as the interrupted request, or passed as a return_to, and run after sign-in. All of this was verified in Chrome on the TP in fix(thirdparty): address the #268 review of Third Party form login (#249) #270.
  • web-allow-others: false on every profile that enables the console (fix the AS's local).
  • server.servlet.session.cookie.same-site: lax on every profile. Not strict, because cross-site redirects in the OAuth flow must carry the session.
  • Add spring-boot-h2console (runtime) only if developers want the console in that module. Otherwise remove the dead spring.h2.console.* settings.
  • Tests like the TP's H2ConsoleSecurityTest (console enabled) and the console-disabled check in FormLoginTest.

References

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions