Skip to content

fix(security): do not redirect a remember-me login that is not a GET, or is an Ajax call - #16971

Draft
borinquenkid wants to merge 12 commits into
7.0.xfrom
fix/remember-me-redirect-7.0.x
Draft

borinquenkid wants to merge 12 commits into
7.0.xfrom
fix/remember-me-redirect-7.0.x

Conversation

@borinquenkid

@borinquenkid borinquenkid commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Draft: offered to the team. I am not working on this one any more. If you take it, start from the latest commit of this branch on a new branch from 7.0.x, open your own pull request, and tell me in Slack. This one stays as the reference for the history.

Fixes #15879, #15873 and #15874 (a merge to 7.0.x does not close them, so they are closed by hand once the merge-ups land). #15877 and #15875 describe related redirects and are checked after this.

Cause, read in the bytecode of Spring Security 7.1.1: when a successHandler is set, RememberMeAuthenticationFilter.doFilter calls it after a successful remember-me login and returns, so the filter chain does not run. The plugin sets the authentication success handler on its remember-me filter on purpose, and GrailsRememberMeAuthenticationFilter saves the request so that an autologin lands on the page that was asked for. That is right for a page fetched with a GET. For a POST, PUT, PATCH or DELETE the redirect turns the request into a GET and the action never runs (#15879); for an Ajax request the handler redirects to the Ajax success URL instead of answering (#15873, #15874).

Change: GrailsRememberMeAuthenticationFilter keeps the success handler itself instead of handing it to Spring's filter, and uses it, and saves the request, only for a GET that is not an Ajax call (SpringSecurityUtils.isAjax). The handler runs where Spring would have called it, after the success event. Any other request goes on down the filter chain as the remembered user, and nothing is saved in the request cache for it. The wiring in SpringSecurityCoreGrailsPlugin is unchanged. The page of the remember-me cookie in the guide says what happens to each kind of request.

Tests: GrailsRememberMeAuthenticationFilterSpec (7 features): a GET is redirected to through the handler and the chain stops, as today (it passed before the change); POST, PUT, PATCH and DELETE, and an Ajax GET, continue down the chain with the remembered user in the security context, with no call to the handler and nothing saved (these five failed before the change, as run in the repo); and without a handler a GET continues. All 180 unit tests of the plugin pass; CodeNarc, Checkstyle and rat are clean. CI is off (no ci).

Not covered: a running application with a real remember-me cookie. No functional test in the examples depends on the old redirect.

Two of the three reviewers (matrei, codeconsole, jdaugherty), as 7.0.x is released.

https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL

… or is an Ajax call

Spring Security's RememberMeAuthenticationFilter hands every request that logs in through remember-me to the authentication
success handler, which redirects, and then does not run the rest of the filter chain. A POST, PUT, PATCH or DELETE became a GET
and its action never ran, and an Ajax request was redirected to the Ajax success url.

GrailsRememberMeAuthenticationFilter keeps the success handler and uses it, and saves the request, only for a GET that is not an
Ajax call. Any other request goes on down the filter chain as the remembered user.

GrailsRememberMeAuthenticationFilterSpec covers a GET (unchanged), POST, PUT, PATCH and DELETE, Ajax, and no handler. The guide
says what happens to a remember-me request.

Fixes #15879
Fixes #15873
Fixes #15874

Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
Copilot AI balanced review requested due to automatic review settings November 13, 2026 13:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

jamesfredley
jamesfredley previously approved these changes Nov 13, 2026

@jamesfredley jamesfredley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A remember-me login that is not a GET, or that is an Ajax call, is not redirected. A browser GET that should redirect still does.

jamesfredley
jamesfredley previously approved these changes Nov 13, 2026

@jamesfredley jamesfredley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A remember-me login that is not a GET, or that is an Ajax call, is not redirected. A browser GET that should redirect still does.

…t after it does not loop

Spring Security 6 and later saves the authentication of a remember-me login in the request only, unless the filter is given
a security context repository. The page the success handler redirects to then found no user, logged in through the cookie
again and redirected again; with a page that needs a full login the browser bounced between it and /login/auth. The
remember-me filter now uses the plugin's session-backed securityContextRepository.

Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
… cookie logs the user in

A page that needs a full login sends a remembered user to /login/auth, which the entry point does after clearing the
security context. The cookie logged the user in again on that request and the success handler redirected back to the page,
which sent the user to /login/auth again, and so on. The request for the login form now goes on down the filter chain, so
the login controller can send a remembered user to the full login page.

Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
@borinquenkid

Copy link
Copy Markdown
Member Author

Two more commits (385fc4f259, 1cee0772b9) and a docs line, after ianroberts reported on #16973 that a remember-me user still loops.

I reproduced it first, in a functional spec on #16973 that follows each redirect by hand. With a remember-me cookie and no session, a request for a page that needs a full login went /secureNamespaced -> /secureNamespaced?continue -> /login/auth -> /secureNamespaced?continue -> /login/auth -> ... until the browser gave up.

Two causes, both in GrailsRememberMeAuthenticationFilter:

  • Spring Security 6 and later saves a remember-me login in the request only, unless the filter is given a security context repository. The page redirected to found no user and logged in again. The filter now uses the plugin's session-backed securityContextRepository.
  • The entry point clears the security context before it sends the user to /login/auth, so the cookie logs in again there, and the success handler redirected back to the page. The request for the login form (auth.loginFormUrl) is no longer redirected; it goes on to LoginController, which sends a remembered user to the full login page (fix(security): show the full login page to a remember-me user sent to /login/auth #16973).

Unit: GrailsRememberMeAuthenticationFilterSpec has two more features (the login is kept in the session; the login form request is not redirected), 9 in all, all plugin tests pass. With both PRs together the chain is /secureNamespaced -> ?continue -> /login/auth -> /login/full.

@jamesfredley
jamesfredley dismissed their stale review November 13, 2026 21:00

The approval no longer holds: a login form URL written as an absolute address is not recognized, so that request is redirected.

@jamesfredley jamesfredley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not approving. A non-GET and an Ajax login are still not redirected, and a browser GET that should redirect still does. A login form URL written as an absolute address is not recognized, so that request is redirected.

…e login is not redirected

Answers the review of #16971: the filter compared the request path with the configured login form url, so an absolute url such as https://example.test/login/auth never matched and the request for the login form was redirected. An absolute url is now compared by scheme, host, port and path, which includes the context path. The spec tries each url shape against each request shape.

Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
@borinquenkid

Copy link
Copy Markdown
Member Author

Answers the absolute login-form URL case. isLoginForm now handles both forms Spring Security's login entry point accepts: a path, compared with the context path as before, and an absolute http or https URL, compared by scheme, host (any letter case), port (80 and 443 by default) and path, which includes the context path. A URL that does not parse is not the login form.

GrailsRememberMeAuthenticationFilterSpec has a table of login-form URL shapes against request shapes, run through doFilter: a path, an absolute https and http URL, an explicit port, a context path, a host in other letter case, a query string, and the ones that must still be redirected (another host, scheme, port or path); 6 of its 22 rows fail without the change. The security plugin module: 195 tests, 0 failures; codeStyle clean.

Not tried: a proxy that changes the scheme or host the request reports; a forwarded-header filter is expected to correct them before this filter runs.

@jamesfredley jamesfredley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The items this review found have been addressed. An absolute login form URL is recognised. A non-GET and an Ajax login are still not redirected.

@jdaugherty jdaugherty left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main change is right: keeping the success handler in the Grails filter and using it only for a GET that is not an Ajax call matches what Spring Security's filter does in 6.5.11, and the spec covers it.

Not approving yet, for the login form matching: the loop is still reachable with an absolute login form URL behind a proxy, and with a path that has a query string. The reason given for the securityContextRepository wiring is also not what happens in Spring Security, and the changes in behavior need an upgrade note. Details inline.

return false
}
int formPort = form.port != -1 ? form.port : ('https'.equalsIgnoreCase(form.scheme) ? 443 : 80)
form.scheme.equalsIgnoreCase(request.scheme) && form.host?.equalsIgnoreCase(request.serverName) &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An absolute login form URL is matched on scheme, host and port as the request reports them. Behind a proxy that does not forward them, they differ from the public URL: with the form at https://example.test/login/auth and the request arriving as http://app-internal:8080/login/auth, the request is not recognised as the login form, it is redirected, and the loop is back.

The request has already reached this application, so the path is enough to tell whether it is the login form. Please compare only the path of an absolute URL (which includes the context path) and drop the scheme, host and port checks. The rows of the spec that expect another host, scheme or port to be redirected then change to the login form.

if (loginFormUrl.toLowerCase(Locale.ROOT).startsWith('http://') || loginFormUrl.toLowerCase(Locale.ROOT).startsWith('https://')) {
return isAbsoluteLoginForm(request)
}
request.requestURI == request.contextPath + loginFormUrl

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A login form URL given as a path with a query string never matches: with auth.loginFormUrl = '/login/auth?lang=en', a GET of /login/auth is still redirected, so the loop remains for that configuration. The absolute branch ignores the query (the spec has a row for https://example.test/login/auth?x=1), the path branch does not.

Please take the path out of the configured URL the same way for both forms, so there is one comparison, and add a row for a path with a query string.

Comment on lines +308 to +309
// Spring Security 6 and later saves a remember-me login only in the request unless told where; saved in the session,
// the page the success handler redirects to finds the remembered user and does not log in and redirect again

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is not right for the versions we use. In Spring Security 6.5.11 (7.0.x) and 7.1.x, RememberMeAuthenticationFilter defaults to its own HttpSessionSecurityContextRepository, so the login was already saved in the session. In the default filter chain that default repository also saves through the response wrapper of the securityContextRepository bean, because securityContextPersistenceFilter runs first, so the scr.* settings were already applied.

Using the bean here is fine, but it is not what stops the loop; the login form exclusion is. Please correct the comment to say what the line does: the filter uses the plugin's repository and its scr.* settings, also in a chain without securityContextPersistenceFilter.

}

@Issue('#15877')
void 'the remembered login is kept in the session, so the page redirected to does not log in again and loop'() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feature passes without the change it is meant to cover: with no repository given to the filter, the login is still in the session under the same key, because of Spring Security's default repository. Please either drop it, or make it fail without the wiring, for example a repository with its own springSecurityContextKey and an assertion on that key.


Spring Security supports creating a remember-me cookie so that users are not required to log in with a username and password for each session. This is optional and is usually implemented as a checkbox on the login form; the default `auth.gsp` supplied by the plugin has this feature.

When a request arrives with a remember-me cookie and no session, the user is logged in from the cookie. A page that is fetched with a GET is then redirected to, through the authentication success handler, so that the browser lands on the page it asked for, except the request for the login form (`auth.loginFormUrl`): a page that needs a full login sends a remembered user there, and redirecting back to the page would bounce between the two. Any other request, that is a POST, PUT, PATCH or DELETE, or a request that comes from Ajax (see <<core-ajax>>), is not redirected: redirecting it would turn it into a GET, or into the Ajax success URL, and its action would not run. It goes on to the controller as the remembered user instead.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are changes in behavior for an application that upgrades, so they need an entry in the upgrade guide (upgrading60x.adoc) as well as this page:

  • a remember-me login on a POST, PUT, PATCH, DELETE, HEAD or Ajax request is no longer redirected, and nothing is saved in the request cache for it;
  • a remember-me login on the request for the login form now reaches LoginController;
  • setAuthenticationSuccessHandler no longer sets Spring Security's handler, and the redirect is decided in onSuccessfulAuthentication, so a subclass that overrides that method without calling super no longer redirects at all.

The note should say how to keep the old result, for example by overriding redirects(request).

Separately, this sentence is hard to follow ("is then redirected to, through the authentication success handler, ..., except the request for the login form"). A short list, one item per kind of request, would read better.

…the changes of remember-me are in the upgrade guide

The request for the login form is recognised by its path alone, for a path and for an absolute url
of auth.loginFormUrl: the query and the fragment of the configured url are left out, and the scheme,
host and port the request reports are not compared, as behind a proxy that does not forward them
they differ from the public url and the redirect loop was back. A configured url with a query string,
such as /login/auth?lang=en, never matched before.

The spec row for the session now gives the filter a repository with a key of its own and looks under
that key, so it fails when the filter is not given the repository. The comment on the wiring says
what it does, and the upgrade guide has a section on the requests that are no longer redirected and
on how to keep the old result.

Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
@borinquenkid

Copy link
Copy Markdown
Member Author

@jdaugherty All five points are addressed in the new commit.

  • Login form behind a proxy. Only the path of auth.loginFormUrl is compared now, for a path and for an absolute URL; the scheme, host and port that the request reports are not. The three rows that expected another host, scheme or port to be redirected now expect the login form, and there is a row for your example: the form at https://example.test/login/auth, the request arriving as http://app-internal:8080/login/auth.
  • Login form with a query string. The query and the fragment of the configured URL are left out for both forms, so there is one comparison. auth.loginFormUrl = '/login/auth?lang=en' matches a GET of /login/auth, also with a context path, and the spec has rows for that, for a fragment, and for a path that does not match.
  • The comment on the securityContextRepository wiring. It says what the line does now: the filter saves through the plugin's repository and its scr.* settings, also in a chain without securityContextPersistenceFilter. It no longer claims that the line stops the loop.
  • The session row. It gives the filter a repository with its own springSecurityContextKey and looks under that key, and also checks that nothing is under the default key, so it fails when the filter is not given the repository.
  • Upgrade guide. A new section of upgrading60x.adoc lists the three changes, what each did before, and how to keep the old result (override redirects(request) in a subclass registered as rememberMeAuthenticationFilter). Its heading is UPGRADE-NUMBER, to be replaced with the next free number when the pull request is merged: the 7.0.x pull requests that add a section would otherwise all take 22 and collide. The merge script refuses a diff that still has the marker. The sentence on the remember-me page is a list, one item per kind of request.

The plugin module (199 tests) and codeStyle pass.

Branch policy: this commit adds no public type and no throw. Where the PR belongs is still open; I have not moved it.

If you find another shape that does not reproduce first time, a failing spec on a throwaway branch, or the few lines you ran, would help me a lot.

@github-actions
github-actions Bot dismissed jamesfredley’s stale review November 18, 2026 19:24

Dismissed automatically: the pull request changed after this approval, from 8be2381 to 1b146bc.

A login form address whose path has a dot segment, https://example.test/app/../login/auth or /app/../login/auth,
never matched the request, which the browser sends without that segment, so a remembered user was redirected from
the form. The configured path is normalized before it is compared.

Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
@borinquenkid

Copy link
Copy Markdown
Member Author

@jamesfredley @jdaugherty: the configured login form address is compared without its dot segments now. https://example.test/app/../login/auth and /app/../login/auth never matched the request, which the browser sends without the segment, so a remembered user was redirected from the form. The path is normalized before it is compared, in the absolute and the relative form; GrailsRememberMeAuthenticationFilterSpec has four more rows, three of which fail without the change.

https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL

@jamesfredley jamesfredley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requested changes. A login address with an encoded dot segment still misses the form.

return false
}
// the path the browser sends has no dot segments, so the configured one has none either
return request.requestURI == (form.normalize().rawPath ?: '/')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The login address has an encoded dot segment. The browser asks for the path without that segment. This still compares the encoded path, so a remember-me user misses the form. Compare the path the browser sends.

@borinquenkid

Copy link
Copy Markdown
Member Author

@jamesfredley: a login address with an encoded dot segment, /app/%2e%2e/login/auth, matches the form now. A browser reads %2e as a dot, in either case and mixed with a plain dot (.%2E), so the path it asks for has no such segment. The comparison used URI.normalize, which knows only plain dots, and which keeps a .. at the root. It now removes the dot segments itself, the way RFC 3986 section 5.2.4 does, with %2e read as a dot, a .. at the root staying at the root, and a dot segment at the end leaving the trailing slash.

Before asking for another look, I ran 30 spellings: .., ., %2e%2e, %2E%2E, .%2e, %2e. in the middle, at the end and above the root, several in a row, with the context path, with a query or a fragment, as a path and as a full address, and the ones that must not match (a segment that leads away from the form, another context path, %2f.., which is no separator). 61 rows in the spec, 22 fail without this change.

https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL

@borinquenkid
borinquenkid marked this pull request as draft November 23, 2026 01:41
# Conflicts:
#	grails-doc/src/en/guide/upgrading/upgrading60x.adoc
@testlens-app

testlens-app Bot commented Nov 24, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: 5b91fff
▶️ Tests: 54309 executed
⚪️ Checks: 58/58 completed


Learn more about TestLens at testlens.app/docs.

@borinquenkid borinquenkid added no ci and removed run ci labels Nov 26, 2026
…rect-7.0.x

# Conflicts:
#	grails-doc/src/en/guide/upgrading/upgrading60x.adoc

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants