8000 Only allow email parameter in UpdateEmail.requiredActionChallenge is forced by rmartinc · Pull Request #55532 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static boolean isVerifyEmailEnabled(RealmModel realm) {
}

public static void forceEmailVerification(KeycloakSession session) {
session.setAttribute(FORCE_EMAIL_VERIFICATION, true);
session.setAttribute(FORCE_EMAIL_VERIFICATION, Boolean.TRUE);
}

private static boolean isVerifyEmailEnabled(RealmModel realm, RequiredActionConfigModel config) {
Expand Down Expand Up @@ -161,7 +161,7 @@ public void requiredActionChallenge(RequiredActionContext context) {
MultivaluedMap<String, String> formData = new MultivaluedHashMap<>(context.getHttpRequest().getDecodedFormParameters());
String newEmail = formData.getFirst(UserModel.EMAIL);

if (newEmail != null) {
if (newEmail != null && Boolean.TRUE.equals(context.getSession().removeAttribute(FORCE_EMAIL_VERIFICATION))) {
// Remove VERIFY_EMAIL to ensure UPDATE_EMAIL takes precedence when both realm verification and forced verification are enabled.
user.removeRequiredAction(UserModel.RequiredAction.VERIFY_EMAIL);
sendEmailUpdateConfirmation(context, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void processAction(RequiredActionContext context) {
UserProfile profile = provider.create(UserProfileContext.UPDATE_PROFILE, formData, user);

if (isForceEmailVerification) {
UpdateEmail.forceEmailVerification(context.getSession());
user.addRequiredAction(UserModel.RequiredAction.UPDATE_EMAIL);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public void changeEmail(String newEmail) {
submitButton.click();
}

public String getEmail() {
return emailInput.getAttribute("value");
}

public void cancel() {
cancelAIAButton.click();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
Expand Down Expand Up @@ -286,4 +287,25 @@ public void updateEmailWithVerificationBackToApplicationInCleanBrowserShouldTrig
managedRealm.admin().clients().get(client.getId()).update(client);
}
}

@Test
public void updateEmailNoExcutionCode() throws Exception {
doAIA();
loginPage.login("test-user@localhost", "password");

emailUpdatePage.assertCurrent();
assertEquals("test-user@localhost", emailUpdatePage.getEmail());
assertTrue(emailUpdatePage.isCancelDisplayed());
((JavascriptExecutor) driver).executeScript(
"""
const form = document.getElementById("kc-update-email-form");
const url = new URL(form.action);
url.searchParams.delete("session_code");
url.searchParams.delete("execution");
form.action = url.toString();
""");
emailUpdatePage.changeEmail("new@localhost");
emailUpdatePage.assertCurrent();
assertEquals("test-user@localhost", emailUpdatePage.getEmail());
}
}
Loading
0