spring-projects / spring-projects/spring-security
Login fails when using char[] instead of String for password credentials
Nobody has claimed this yet.
- 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
-
Create an authentication attempt using UsernamePasswordAuthenticationToken("user", passwordCharArray), where passwordCharArray is a char[].
-
Configure a standard DaoAuthenticationProvider with a UserDetailsService and password encoder.
-
Attempt login.
-
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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