spring-projects / spring-projects/spring-security

Spring security becomes unusable when OpenSAML is on the module path

Open Beginner friendly
#19,628 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage type: bug
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

Describe the bug
The Saml2LoginConfigurer checks the version of OpenSaml to be of version 5 via:

private static final boolean USE_OPENSAML_5 = Version.getVersion().startsWith("5");

Unfortunately, Version.getVersion() can be null, as it is even marked by annotation. OpenSaml implements by reading the implementation version from the package context. If OpenSAML is placed on the module path, this will be the case as one would need to read the version from the module info instead. I am filing this as a bug in OpenSAML.

As things stand, Spring Security will become unusable when OpenSAML is on the module path for this reason as the class initialization crashes and marks the class as unusable forever.

To Reproduce
Load OpenSAML on the module path and use Spring with it.

Expected behavior
The filter should null-guard the lookup and add a fallback to look up the module version of the OpenSAML module, if OpenSAML is loaded from the module path.

Suggestion:

private static String determineOpenSamlVersion() {
    String version = Version.class.getPackage().getImplementationVersion();
    if (version != null) {
        return version;
    }
    Module module = Version.class.getModule();
    return module.isNamed() ? module.getDescriptor().rawVersion().orElse(null) : null;
}

Note that this will still depend on the module following a naming pattern where the version is included, since OpenSAML is an automatic module, but it is better than failing as things stand.

Sample
Simply run existing tests with OpenSAML on the module path. They will already fail.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in config/src/main/java/org/springframework/security/config/annotation/web/configurers/saml2/Saml2LoginConfigurer.java at the USE_OPENSAML_5 version lookup. Read the existing tests and run them with OpenSAML on the module path to reproduce the class-initialization failure. Done means the lookup safely handles a missing package version, uses the module version when available, and the existing tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
authentication, security
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
82/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.