Skip to content

Disabling security still end up with empty auth handler and failing requests #2747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
thced opened this issue May 27, 2025 · 2 comments · May be fixed by #2751
Open

Disabling security still end up with empty auth handler and failing requests #2747

thced opened this issue May 27, 2025 · 2 comments · May be fixed by #2751
Labels

Comments

@thced
Copy link
Contributor

thced commented May 27, 2025

Version

5.0.0

Context

We use web-openapi-router to manage our endpoints, and we use a sidecar that handles all authentication. This means that we want to disable the OpenAPI security features. Using the RouterBuilders setDoSecurity(false) solved the first issue that prevented creation.
Now the bug appears (as I see it), when a request is sent through the Router. The ChainAuthHandler is empty as a result of disabling security, but a ChainAuthHandler is not allowed to be empty (ChainAuthHandlerImpl) without throwing an exception.

This leads me to believe the solution is a simple check, either via introducing isEmpty on the ChainAuthHandler interface, or the somewhat smaller fix, to adjust the AuthenticationHandlers class with small boolean:

    final ChainAuthHandler authHandler;
    boolean emptyAuthHandler = true;

    switch (securityRequirements.size()) {
      [....]
      default:
        authHandler = ChainAuthHandler.any();
        securityRequirements
          .stream()
          .map(securityRequirement -> and(route, securityRequirement, failOnNotFound))
          .filter(Objects::nonNull)
          .forEach(handler -> {
              authHandler.add(handler);
              emptyAuthHandler = false;
          });
    }

    if (emptyAuth || emptyAuthHandler) {
      authHandler
        .add(ANONYMOUS_SUCCESS_AUTH_HANDLER);
    }

    return authHandler;
@thced thced added the bug label May 27, 2025
@thced thced linked a pull request Jun 4, 2025 that will close this issue
@tsegismont
Copy link
Contributor

@thced @pk-work is this a 5.0.0 specific problem? Or is 4.x affected?

@pk-work
Copy link
Contributor

pk-work commented Jun 6, 2025

@tsegismont In 4.x we don't have support for "security", so this is only a problem in 5.x.

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

Successfully merging a pull request may close this issue.

3 participants