spring-projects / spring-projects/spring-security

Using equalsConstantTime consistently across

Open
#12,832 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Expected Behavior

Reviewing this library, noticed that the method equalsConstantTime wasn't adopted everywhere.

https://github.com/spring-projects/spring-security/blob/3b447b938cfcb82e31e1bb744ff59ce52427749b/web/src/main/java/org/springframework/security/web/csrf/CsrfFilter.java#L122

Locations where they are not adopted yet

https://github.com/spring-projects/spring-security/blob/3b447b938cfcb82e31e1bb744ff59ce52427749b/core/src/main/java/org/springframework/security/authentication/AbstractAuthenticationToken.java#L141-L142

Below is a cpgql query that could be used to identify the locations with joern (joern.io)

cpg.call("equals").where(_.argument(1).code(".*((?i)cred|pass|token|secret).*")).location.map(l => (l.className, l.filename, l.lineNumber, l.node)).l
joern> cpg.call("equals").where(_.argument(1).code(".*((?i)cred|pass|token|secret).*")).location.map(l => (l.className, l.filename, l.lineNumber, l.node)).l
res83: List[(String, String, Option[Integer], Option[AbstractNode])] = List(
  (
    "org.springframework.security.web.authentication.www.DigestAuthenticationFilter$DigestData",
    "/Volumes/Work/threatr/spring-security/web/src/main/java/org/springframework/security/web/authentication/www/DigestAuthenticationFilter.java",
    Some(value = 397),
    Some(
      value = Call(
        id = 11568L,
        argumentIndex = 1,
        argumentName = None,
        code = "expectedNonceSignature.equals(nonceTokens[1])",
        columnNumber = Some(value = 9),
        dispatchType = "DYNAMIC_DISPATCH",
        dynamicTypeHintFullName = ArraySeq(),
        lineNumber = Some(value = 397),
        methodFullName = "java.lang.String.equals:boolean(java.lang.Object)",
        name = "equals",
        order = 1,
        signature = "boolean(java.lang.Object)",
        typeFullName = "boolean"
      )
    )
  ),
  (
    "org.springframework.security.crypto.password.LdapShaPasswordEncoder",
    "/Volumes/Work/threatr/spring-security/crypto/src/main/java/org/springframework/security/crypto/password/LdapShaPasswordEncoder.java",
    Some(value = 150),
    Some(
      value = Call(
        id = 43131L,
        argumentIndex = 1,
        argumentName = None,
        code = "PasswordEncoderUtils.equals(encodedPassword, rawPassword)",
        columnNumber = Some(value = 11),
        dispatchType = "STATIC_DISPATCH",
        dynamicTypeHintFullName = ArraySeq(),
        lineNumber = Some(value = 150),
        methodFullName = "org.springframework.security.crypto.password.PasswordEncoderUtils.equals:boolean(java.lang.String,java.lang.String)",
        name = "equals",
        order = 1,
        signature = "boolean(java.lang.String,java.lang.String)",
        typeFullName = "boolean"
      )
    )
  ),

...

Current Behavior

equals method is used for comparing tokens and passwords.

Context

Secure coding.

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 with the equalsConstantTime usage in web/src/main/java/org/springframework/security/web/csrf/CsrfFilter.java and the comparison in core/src/main/java/org/springframework/security/authentication/AbstractAuthenticationToken.java. Use the provided Joern query to locate other equals calls involving credentials, passwords, tokens, or secrets, including the examples in DigestAuthenticationFilter.java and LdapShaPasswordEncoder.java. Done means the applicable sensitive comparisons consistently use the constant-time approach.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.