spring-projects / spring-projects/spring-security-samples

Multi-factor authentication: The second factor can be skipped

Open
#143 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
1.8k
Forks
797
Avg merge
3m
Merged PRs (30d)
5

Description

Simply remove the second factor part from mfaWhenWrongCodeThenRedirects and the test fails:

@Test
void mfaWhenSecondFactorSkippedThenRedirects() throws Exception {
	// @formatter:off
	MvcResult result = this.mockMvc.perform(formLogin()
					.user("user@example.com")
					.password("password"))
			.andExpect(redirectedUrl("/second-factor"))
			.andReturn();

	HttpSession session = result.getRequest().getSession();

	// skip the second factor

	this.mockMvc.perform(post("/third-factor")
					.session((MockHttpSession) session)
					.param("answer", "smith")
					.with(csrf()))
			.andExpect(redirectedUrl("/login?error"));
	// @formatter:on
}

Test output:

Redirected URL expected:</login?error> but was:</>
Expected :/login?error
Actual   :/

Contributor guide

No contributing guide indexed for this repository

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 by locating the test containing mfaWhenWrongCodeThenRedirects and mfaWhenSecondFactorSkippedThenRedirects, then run the latter to reproduce the failure. Trace the /third-factor request after formLogin() redirects to /second-factor. Done means the skipped second-factor submission redirects to /login?error rather than /.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.