spring-projects / spring-projects/spring-security

Login fails when using char[] instead of String for password credentials

Open
#17,830 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

When using UsernamePasswordAuthenticationToken with a char[] password instead of a String, authentication fails.

From a security perspective, it is recommended to use char[] to avoid leaving password values in immutable String objects in memory. However, Spring Security seems to implicitly assume passwords are String values during credential comparison, which causes login to fail when char[] is provided.

To Reproduce

  1. Create an authentication attempt using UsernamePasswordAuthenticationToken("user", passwordCharArray), where passwordCharArray is a char[].

  2. Configure a standard DaoAuthenticationProvider with a UserDetailsService and password encoder.

  3. Attempt login.

  4. Authentication fails, even if the char[] contains the correct password.

Expected behavior
Spring Security should either:

Support char[] as password credentials in AuthenticationToken, or

Explicitly document that only String credentials are supported (and that callers must convert to String).

Supporting char[] would allow applications to follow secure coding practices and minimize the lifetime of passwords in memory.

Sample

char[] password = "password".toCharArray();
Authentication auth = new UsernamePasswordAuthenticationToken("user", password);
Authentication result = authenticationManager.authenticate(auth);

Result: Authentication fails.
If changed to String password = "password";, authentication succeeds.

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 at UsernamePasswordAuthenticationToken credential handling and follow the DaoAuthenticationProvider authentication path using the supplied char[] reproduction. Compare that behavior with String credentials and determine whether the issue should support char[] or document String-only credentials; done when the chosen behavior is covered by the relevant authentication checks.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.