You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by "lprimak (via GitHub)" <gi...@apache.org> on 2026/05/21 03:05:04 UTC

[PR] Session fixation [shiro]

lprimak opened a new pull request, #2711:
URL: https://github.com/apache/shiro/pull/2711

   <!--
   For Security Vulnerabilities, please email: security@shiro.apache.org
   For more details on how to report a vulnerability see: https://www.apache.org/security/
   -->
   
   Following this checklist to help us incorporate your contribution quickly and easily:
   
    - [ ] Make sure there is a [GitHub issue](https://github.com/apache/shiro/issues) filed
          for the change (usually before you start working on it).  Trivial changes like typos do not
          require a GitHub issue.  Your pull request should address just this issue, without pulling in other changes.
    - [ ] Format the pull request title like `[#XXX] - Fixes bug in SessionManager`,
          where you replace `#XXX` with the appropriate GitHub issue. Best practice
          is to use the GitHub issue title in the pull request title and in the first line of the commit message.
    - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
    - [ ] add `fixes #XXX` if merging the PR should close a related issue.
    - [ ] Run `mvn verify` to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
    - [ ] Committers: Make sure a milestone is set on the PR
    - [ ] Committers: Use "Squash and Merge" to combine all commits into one when merging a PR when appropriate.
   
   Trivial changes like typos do not require a GitHub issue (javadoc, comments...).
   In this case, just format the pull request title like `[DOC] - Add javadoc in SessionManager`.
   
   If this is your first contribution, you have to read the [Contribution Guidelines](https://github.com/apache/shiro/blob/master/CONTRIBUTING.md)
   
   If your pull request is about ~20 lines of code you don't need to sign an [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf)
   if you are unsure please ask on the developers list.
   
   To make clear that you license your contribution under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   you have to acknowledge this by using the following check-box.
   
    - [ ] I hereby declare this contribution to be licenced under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
    - [ ] In any other case, please file an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#2704] [#2710] Fixed Session fixation-related regressions [shiro]

Posted by "lprimak (via GitHub)" <gi...@apache.org>.
lprimak merged PR #2711:
URL: https://github.com/apache/shiro/pull/2711


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#2704] [#2710] [3.x] Fixed Session fixation-related regressions [shiro]

Posted by "apupier (via GitHub)" <gi...@apache.org>.
apupier commented on PR #2711:
URL: https://github.com/apache/shiro/pull/2711#issuecomment-4507063136

   > @apupier see #2715
   
   with both fixes, the tests are passing for Apache Camel with the 3.x version of shiro


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#2704] [#2710] [3.x] Fixed Session fixation-related regressions [shiro]

Posted by "lprimak (via GitHub)" <gi...@apache.org>.
lprimak commented on PR #2711:
URL: https://github.com/apache/shiro/pull/2711#issuecomment-4506697009

   That is not going to be an issue as `subject` is the root of the object graph and there is only one session per subject
   
   > One question regarding the placement of the snapshot/restore in `beforeSuccessfulLogin()`: after `stopSession()` you call `subject.getSession()` to obtain the new session and restore the attributes into it — but `createSubject()` hasn't run yet at that point. Is there a guarantee that `createSubject()` will always reuse that intermediate session rather than creating another one? I'm wondering if snapshotting before `beforeSuccessfulLogin()` and restoring to the subject returned by `createSubject()` (i.e. directly in `login()`) would be more robust, since it operates on the final authenticated subject with no ambiguity about which session ends up in use.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#2704] [#2710] [3.x] Fixed Session fixation-related regressions [shiro]

Posted by "apupier (via GitHub)" <gi...@apache.org>.
apupier commented on PR #2711:
URL: https://github.com/apache/shiro/pull/2711#issuecomment-4506116962

   I backported the fix to 2.22.0 locally and tested with Apache Camel (the project which reported the issue initially). it is working fine on Camel side.
   
   I tried with main branch 3.x with Apache Camel but there is a differnt error:
   ```
   java.lang.IllegalArgumentException: URI is not absolute
   	at java.base/java.net.URL.of(URL.java:862)
   	at java.base/java.net.URI.toURL(URI.java:1172)
   	at org.apache.shiro.lang.io.ResourceUtils.getURLForPath(ResourceUtils.java:152)
   	at org.apache.shiro.lang.io.ResourceUtils.getInputStreamForPath(ResourceUtils.java:124)
   	at org.apache.shiro.config.Ini.loadFromPath(Ini.java:270)
   	at org.apache.camel.component.shiro.security.ShiroSecurityPolicy.<init>(ShiroSecurityPolicy.java:59)
   	at org.apache.camel.component.shiro.security.ShiroSecurityPolicy.<init>(ShiroSecurityPolicy.java:71)
   	at org.apache.camel.component.shiro.security.ShiroSecurityPolicy.<init>(ShiroSecurityPolicy.java:81)
   	at org.apache.camel.component.shiro.security.ShiroRolesAuthorizationTest$1.configure(ShiroRolesAuthorizationTest.java:135)
   ```
   
   The provided value for the Ini.loadFromPath is src/test/resources/securityconfig.ini
   
   A last note is that when backporting to 2.20, it is working fine for Camel as I mentioned but I have tests failures in Apache Shiro (but maybe I have not backported correctly?):
   ```
   [INFO] --- exec:3.6.3:exec (start-domain) @ shiro-its-jakarta-ee ---
   Waiting for domain1 to start .Error starting domain domain1.
   The server exited prematurely with exit code 1.
   Before it died, it produced the following output:
   
   Launching Payara Server on Felix platform
   ERROR: Error parsing system bundle statement.
   ERROR: Bundle org.glassfish.hk2.osgi-resource-locator [1] Error starting file:/home/apupier/git/shiro/integration-tests/jakarta-ee/target/dependency/payara5/glassfish/modules/osgi-resource-locator.jar (org.osgi.framework.BundleException: Unable to resolve org.glassfish.hk2.osgi-resource-locator [1](R 1.0): missing requirement [org.glassfish.hk2.osgi-resource-locator [1](R 1.0)] osgi.wiring.package; (&(osgi.wiring.package=org.osgi.framework)(version>=1.8.0)(!(version>=2.0.0))) Unresolved requirements: [[org.glassfish.hk2.osgi-resource-locator [1](R 1.0)] osgi.wiring.package; (&(osgi.wiring.package=org.osgi.framework)(version>=1.8.0)(!(version>=2.0.0)))])
   ERROR: Bundle org.glassfish.hk2.utils [2] Error starting file:/home/apupier/git/shiro/integration-tests/jakarta-ee/target/dependency/payara5/glassfish/modules/hk2-utils.jar (org.osgi.framework.BundleException: Unable to resolve org.glassfish.hk2.utils [2](R 2.0): missing requirement [org.glassfish.hk2.utils [2](R 2.0)] osgi.wiring.package; (osgi.wiring.package=javax.xml.namespace) Unresolved requirements: [[org.glassfish.hk2.utils [2](R 2.0)] osgi.wiring.package; (osgi.wiring.package=javax.xml.namespace)])
   ERROR: Bundle org.glassfish.hk2.api [3] Error starting file:/home/apupier/git/shiro/integration-tests/jakarta-ee/target/dependency/payara5/glassfish/modules/hk2-api.jar (org.osgi.framework.BundleException: Unable to resolve org.glassfish.hk2.api [3](R 3.0): missing requirement [org.glassfish.hk2.api [3](R 3.0)] osgi.wiring.package; (&(osgi.wiring.package=org.glassfish.hk2.utilities.reflection)(version>=2.6.0)(!(version>=3.0.0))) [caused by: Unable to resolve org.glassfish.hk2.utils [2](R 2.0): missing requirement [org.glassfish.hk2.utils [2](R 2.0)] osgi.wiring.package; (&(osgi.wiring.package=javax.inject)(version>=1.0.0)(!(version>=2.0.0))) [caused by: Unable to resolve org.glassfish.hk2.external.jakarta.inject [311](R 311.0): missing requirement [org.glassfish.hk2.external.jakarta.inject [311](R 311.0)] osgi.ee; (&(osgi.ee=JavaSE)(version=1.8))]] Unresolved requirements: [[org.glassfish.hk2.api [3](R 3.0)] osgi.wiring.package; (&(osgi.wiring.package=org.glassfish.hk2.utilities.r
 eflection)(version>=2.6.0)(!(version>=3.0.0)))])
   ERROR: Bundle org.objectweb.asm.util [40] Error starting file:/home/apupier/git/shiro/integration-tests/jakarta-ee/target/dependency/payara5/glassfish/modules/asm-util.jar (org.osgi.framework.BundleException: Unable to resolve org.objectweb.asm.util [40](R 40.0): missing requirement [org.objectweb.asm.util [40](R 40.0)] osgi.wiring.package; (&(osgi.wiring.package=org.objectweb.asm.signature)(version>=9.7.0)) [caused by: Unable to resolve org.objectweb.asm [75](R 75.0): missing requirement [org.objectweb.asm [75](R 75.0)] osgi.ee; (&(osgi.ee=JavaSE)(version=1.5.0))] Unresolved requirements: [[org.objectweb.asm.util [40](R 40.0)] osgi.wiring.package; (&(osgi.wiring.package=org.objectweb.asm.signature)(version>=9.7.0))])
   ERROR: Bundle org.objectweb.asm [75] Error starting file:/home/apupier/git/shiro/integration-tests/jakarta-ee/target/dependency/payara5/glassfish/modules/asm.jar (org.osgi.framework.BundleException: Unable to resolve org.objectweb.asm [75](R 75.0): missing requirement [org.objectweb.asm [75](R 75.0)] osgi.ee; (&(osgi.ee=JavaSE)(version=1.5.0)) Unresolved requirements: [[org.objectweb.asm [75](R 75.0)] osgi.ee; (&(osgi.ee=JavaSE)(version=1.5.0))])
   ERROR: Bundle org.objectweb.asm.commons [106] Error starting file:/home/apupier/git/shiro/integration-tests/jakarta-ee/target/dependency/payara5/glassfish/modules/asm-commons.jar (org.osgi.framework.BundleException: Unable to resolve org.objectweb.asm.commons [106](R 106.0): missing requirement [org.objectweb.asm.commons [106](R 106.0)] osgi.wiring.package; (&(osgi.wiring.package=org.objectweb.asm.signature)(version>=9.7.0)) [caused by: Unable to resolve org.objectweb.asm [75](R 75.0): missing requirement [org.objectweb.asm [75](R 75.0)] osgi.ee; (&(osgi.ee=JavaSE)(version=1.5.0))] Unresolved requirements: [[org.objectweb.asm.commons [106](R 106.0)] osgi.wiring.package; (&(osgi.wiring.package=org.objectweb.asm.signature)(version>=9.7.0))])
   ERROR: Bundle fish.payara.server.internal.hk2.config [154] Error starting file:/home/apupier/git/shiro/integration-tests/jakarta-ee/target/dependency/payara5/glassfish/modules/hk2-config.jar (org.osgi.framework.BundleException: Unable to resolve fish.payara.server.internal.hk2.config [154](R 154.0): missing requirement [fish.payara.server.internal.hk2.config [154](R 154.0)] osgi.wiring.package; (osgi.wiring.package=javax.management) Unresolved requirements: [[fish.payara.server.internal.hk2.config [154](R 154.0)] osgi.wiring.package; (osgi.wiring.package=javax.management)])
   ERROR: Bundle org.glassfish.hk2.osgi-adapter [174] Error starting file:/home/apupier/git/shiro/integration-tests/jakarta-ee/target/dependency/payara5/glassfish/modules/osgi-adapter.jar (org.osgi.framework.BundleException: Unable to resolve org.glassfish.hk2.osgi-adapter [174](R 174.0): missing requirement [org.glassfish.hk2.osgi-adapter [174](R 174.0)] osgi.wiring.package; (&(osgi.wiring.package=org.osgi.framework)(version>=1.5.0)(!(version>=2.0.0))) Unresolved requirements: [[org.glassfish.hk2.osgi-adapter [174](R 174.0)] osgi.wiring.package; (&(osgi.wiring.package=org.osgi.framework)(version>=1.5.0)(!(version>=2.0.0)))])
   ERROR: Bundle fish.payara.server.internal.hk2.config-types [197] Error starting file:/home/apupier/git/shiro/integration-tests/jakarta-ee/target/dependency/payara5/glassfish/modules/config-types.jar (org.osgi.framework.BundleException: Unable to resolve fish.payara.server.internal.hk2.config-types [197](R 197.0): missing requirement [fish.payara.server.internal.hk2.config-types [197](R 197.0)] osgi.wiring.package; (&(osgi.wiring.package=org.glassfish.hk2.utilities)(version>=2.6.0)(!(version>=3.0.0))) [caused by: Unable to resolve org.glassfish.hk2.api [3](R 3.0): missing requirement [org.glassfish.hk2.api [3](R 3.0)] osgi.wiring.package; (&(osgi.wiring.package=javax.inject)(version>=1.0.0)(!(version>=2.0.0))) [caused by: Unable to resolve org.glassfish.hk2.external.jakarta.inject [311](R 311.0): missing requirement [org.glassfish.hk2.external.jakarta.inject [311](R 311.0)] osgi.ee; (&(osgi.ee=JavaSE)(version=1.8))]] Unresolved requirements: [[fish.payara.server.internal.hk2.config
 -types [197](R 197.0)] osgi.wiring.package; (&(osgi.wiring.package=org.glassfish.hk2.utilities)(version>=2.6.0)(!(version>=3.0.0)))])
   ERROR: Bundle org.objectweb.asm.tree [205] Error starting file:/home/apupier/git/shiro/integration-tests/jakarta-ee/target/dependency/payara5/glassfish/modules/asm-tree.jar (org.osgi.framework.BundleException: Unable to resolve org.objectweb.asm.tree [205](R 205.0): missing requirement [org.objectweb.asm.tree [205](R 205.0)] osgi.wiring.package; (&(osgi.wiring.package=org.objectweb.asm.signature)(version>=9.7.0)) [caused by: Unable to resolve org.objectweb.asm [75](R 75.0): missing requirement [org.objectweb.asm [75](R 75.0)] osgi.ee; (&(osgi.ee=JavaSE)(version=1.5.0))] Unresolved requirements: [[org.objectweb.asm.tree [205](R 205.0)] osgi.wiring.package; (&(osgi.wiring.package=org.objectweb.asm.signature)(version>=9.7.0))])
   ERROR: Bundle org.glassfish.hk2.class-model [270] Error starting file:/home/apupier/git/shiro/integration-tests/jakarta-ee/target/dependency/payara5/glassfish/modules/class-model.jar (org.osgi.framework.BundleException: Unable to resolve org.glassfish.hk2.class-model [270](R 270.0): missing requirement [org.glassfish.hk2.class-model [270](R 270.0)] osgi.wiring.package; (&(osgi.wiring.package=org.objectweb.asm.signature)(version>=9.4.0)(!(version>=10.0.0))) [caused by: Unable to resolve org.objectweb.asm [75](R 75.0): missing requirement [org.objectweb.asm [75](R 75.0)] osgi.ee; (&(osgi.ee=JavaSE)(version=1.5.0))] Unresolved requirements: [[org.glassfish.hk2.class-model [270](R 270.0)] osgi.wiring.package; (&(osgi.wiring.package=org.objectweb.asm.signature)(version>=9.4.0)(!(version>=10.0.0)))])
   ERROR: Bundle org.glassfish.hk2.runlevel [272] Error starting file:/home/apupier/git/shiro/integration-tests/jakarta-ee/target/dependency/payara5/glassfish/modules/hk2-runlevel.jar (org.osgi.framework.BundleException: Unable to resolve org.glassfish.hk2.runlevel [272](R 272.0): missing requirement [org.glassfish.hk2.runlevel [272](R 272.0)] osgi.ee; (&(osgi.ee=JavaSE)(version=1.8)) Unresolved requirements: [[org.glassfish.hk2.runlevel [272](R 272.0)] osgi.ee; (&(osgi.ee=JavaSE)(version=1.8))])
   ERROR: Bundle org.glassfish.hk2.locator [297] Error starting file:/home/apupier/git/shiro/integration-tests/jakarta-ee/target/dependency/payara5/glassfish/modules/hk2-locator.jar (org.osgi.framework.BundleException: Unable to resolve org.glassfish.hk2.locator [297](R 297.0): missing requirement [org.glassfish.hk2.locator [297](R 297.0)] osgi.wiring.package; (&(osgi.wiring.package=org.glassfish.hk2.api.messaging)(version>=2.6.0)(!(version>=3.0.0))) [caused by: Unable to resolve org.glassfish.hk2.api [3](R 3.0): missing requirement [org.glassfish.hk2.api [3](R 3.0)] osgi.wiring.package; (&(osgi.wiring.package=javax.inject)(version>=1.0.0)(!(version>=2.0.0))) [caused by: Unable to resolve org.glassfish.hk2.external.jakarta.inject [311](R 311.0): missing requirement [org.glassfish.hk2.external.jakarta.inject [311](R 311.0)] osgi.ee; (&(osgi.ee=JavaSE)(version=1.8))]] Unresolved requirements: [[org.glassfish.hk2.locator [297](R 297.0)] osgi.wiring.package; (&(osgi.wiring.package=org.gl
 assfish.hk2.api.messaging)(version>=2.6.0)(!(version>=3.0.0)))])
   ERROR: Bundle org.glassfish.hk2.external.jakarta.inject [311] Error starting file:/home/apupier/git/shiro/integration-tests/jakarta-ee/target/dependency/payara5/glassfish/modules/jakarta.inject.jar (org.osgi.framework.BundleException: Unable to resolve org.glassfish.hk2.external.jakarta.inject [311](R 311.0): missing requirement [org.glassfish.hk2.external.jakarta.inject [311](R 311.0)] osgi.ee; (&(osgi.ee=JavaSE)(version=1.8)) Unresolved requirements: [[org.glassfish.hk2.external.jakarta.inject [311](R 311.0)] osgi.ee; (&(osgi.ee=JavaSE)(version=1.8))])
   ERROR: Bundle fish.payara.server.internal.core.glassfish [363] Error starting file:/home/apupier/git/shiro/integration-tests/jakarta-ee/target/dependency/payara5/glassfish/modules/glassfish.jar (org.osgi.framework.BundleException: Unable to resolve fish.payara.server.internal.core.glassfish [363](R 363.0): missing requirement [fish.payara.server.internal.core.glassfish [363](R 363.0)] osgi.wiring.package; (&(osgi.wiring.package=org.osgi.framework)(version>=1.9.0)(!(version>=2.0.0))) Unresolved requirements: [[fish.payara.server.internal.core.glassfish [363](R 363.0)] osgi.wiring.package; (&(osgi.wiring.package=org.osgi.framework)(version>=1.9.0)(!(version>=2.0.0)))])
   ERROR: Bundle org.objectweb.asm.tree.analysis [376] Error starting file:/home/apupier/git/shiro/integration-tests/jakarta-ee/target/dependency/payara5/glassfish/modules/asm-analysis.jar (org.osgi.framework.BundleException: Unable to resolve org.objectweb.asm.tree.analysis [376](R 376.0): missing requirement [org.objectweb.asm.tree.analysis [376](R 376.0)] osgi.wiring.package; (&(osgi.wiring.package=org.objectweb.asm.signature)(version>=9.7.0)) [caused by: Unable to resolve org.objectweb.asm [75](R 75.0): missing requirement [org.objectweb.asm [75](R 75.0)] osgi.ee; (&(osgi.ee=JavaSE)(version=1.5.0))] Unresolved requirements: [[org.objectweb.asm.tree.analysis [376](R 376.0)] osgi.wiring.package; (&(osgi.wiring.package=org.objectweb.asm.signature)(version>=9.7.0))])
   WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
   WARNING: sun.misc.Unsafe::staticFieldOffset has been called by org.apache.felix.framework.util.SecureAction (file:/home/apupier/git/shiro/integration-tests/jakarta-ee/target/dependency/payara5/glassfish/osgi/felix/bin/felix.jar)
   WARNING: Please consider reporting this to the maintainers of class org.apache.felix.framework.util.SecureAction
   WARNING: sun.misc.Unsafe::staticFieldOffset will be removed in a future release
   org.osgi.framework.BundleException: Exported package names cannot be zero length.
   	at org.apache.felix.framework.util.manifestparser.ManifestParser.normalizeExportClauses(ManifestParser.java:902)
   	at org.apache.felix.framework.util.manifestparser.ManifestParser.<init>(ManifestParser.java:254)
   	at org.apache.felix.framework.ExtensionManager$ExtensionManagerRevision.update(ExtensionManager.java:1015)
   	at org.apache.felix.framework.ExtensionManager$ExtensionManagerRevision.access$000(ExtensionManager.java:918)
   	at org.apache.felix.framework.ExtensionManager.updateRevision(ExtensionManager.java:390)
   	at org.apache.felix.framework.Felix.init(Felix.java:760)
   	at org.apache.felix.framework.Felix.init(Felix.java:648)
   	at com.sun.enterprise.glassfish.bootstrap.osgi.OSGiFrameworkLauncher$1.run(OSGiFrameworkLauncher.java:99)
   May 21, 2026 10:07:51 AM com.sun.enterprise.glassfish.bootstrap.osgi.BundleProvisioner createBundleProvisioner
   INFO: Create bundle provisioner class = class com.sun.enterprise.glassfish.bootstrap.osgi.BundleProvisioner.
   org.osgi.framework.BundleException: Unable to resolve org.glassfish.hk2.osgi-resource-locator [1](R 1.0): missing requirement [org.glassfish.hk2.osgi-resource-locator [1](R 1.0)] osgi.wiring.package; (&(osgi.wiring.package=org.osgi.framework)(version>=1.8.0)(!(version>=2.0.0))) Unresolved requirements: [[org.glassfish.hk2.osgi-resource-locator [1](R 1.0)] osgi.wiring.package; (&(osgi.wiring.package=org.osgi.framework)(version>=1.8.0)(!(version>=2.0.0)))]
   	at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4398)
   	at org.apache.felix.framework.Felix.startBundle(Felix.java:2308)
   	at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1566)
   	at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:297)
   	at java.base/java.lang.Thread.run(Thread.java:1474)
   ```
   
   here is the branch I used for the backport: https://github.com/apupier/shiro/pull/new/backport-session-fixation
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#2704] [#2710] Fixed Session fixation-related regressions [shiro]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #2711:
URL: https://github.com/apache/shiro/pull/2711#discussion_r3293734275


##########
core/src/main/java/org/apache/shiro/mgt/DefaultSecurityManager.java:
##########
@@ -302,7 +305,17 @@ public Subject login(Subject subject, AuthenticationToken token) throws Authenti
      * @param subject Subject
      */
     protected void beforeSuccessfulLogin(Subject subject) {
-        stopSession(subject);
+        Session session = subject.getSession(false);
+        if (session != null) {
+            Map<Object, Object> attributes = new HashMap<>();
+            session.getAttributeKeys().forEach(key -> attributes.put(key, session.getAttribute(key)));
+            stopSession(subject);

Review Comment:
   The attribute snapshot logic calls session.getAttribute(key) for every key returned by getAttributeKeys(). When the Session is a DelegatingSession (the default exposed session for native session management), each getAttribute call re-loads the session via the SessionManager, resulting in an N+1 pattern during login. Consider adding a bulk attribute snapshot mechanism (e.g., a SessionManager method that returns a copy of the underlying attributes map in one lookup) or otherwise avoiding repeated sessionManager lookups here.



##########
core/src/test/java/org/apache/shiro/subject/DelegatingSubjectTest.java:
##########
@@ -223,6 +226,36 @@ void testRunAs() {
         LifecycleUtils.destroy(sm);
     }
 
+    @Test
+    void sessionAttributesSurviveLoginSessionRotation() {
+        Ini ini = new Ini();
+        Ini.Section users = ini.addSection("users");
+        users.put("user1", "user1,role1");
+        users.put("user2", "user2,role2");
+        users.put("user3", "user3,role3");
+        SecurityManager sm = new BasicIniEnvironment(ini).getSecurityManager();
+        Subject subject = new Subject.Builder(sm).buildSubject();
+
+        subject.login(new UsernamePasswordToken("user1", "user1"));
+        subject.logout();
+
+        Session preLoginSession = subject.getSession(true);
+        preLoginSession.setAttribute("tenantId", "ACME");
+        Serializable preLoginSessionId = preLoginSession.getId();
+
+        subject.login(new UsernamePasswordToken("user1", "user1"));
+        assertThat(subject.isAuthenticated()).isTrue();
+
+        Session postLoginSession = subject.getSession(false);
+        assertThat(postLoginSession).isNotNull();
+
+        assertThat(preLoginSessionId).as("session ID should change on login (session fixation protection)")
+                .isNotEqualTo(postLoginSession.getId());
+        assertThat(postLoginSession.getAttribute("tenantId"))
+                .as("session attributes set before login must survive session rotation")
+                .isEqualTo("ACME");

Review Comment:
   This test creates a SecurityManager via BasicIniEnvironment but does not destroy it. Other tests in this class call LifecycleUtils.destroy(sm) to avoid leaking resources across tests; consider adding similar cleanup (ideally in a try/finally) here as well.
   



##########
core/src/main/java/org/apache/shiro/mgt/DefaultSecurityManager.java:
##########
@@ -302,7 +305,17 @@ public Subject login(Subject subject, AuthenticationToken token) throws Authenti
      * @param subject Subject
      */
     protected void beforeSuccessfulLogin(Subject subject) {
-        stopSession(subject);
+        Session session = subject.getSession(false);
+        if (session != null) {
+            Map<Object, Object> attributes = new HashMap<>();
+            session.getAttributeKeys().forEach(key -> attributes.put(key, session.getAttribute(key)));
+            stopSession(subject);
+            var newSession = subject.getSession();
+            var keys = newSession.getAttributeKeys();

Review Comment:
   beforeSuccessfulLogin() now calls subject.getSession() after stopping the existing session. If the Subject has sessionCreationEnabled=false but still has an existing session (e.g., resolved from an incoming session id), DelegatingSubject.getSession(true) will throw DisabledSessionException and break login. Consider guarding this by only recreating/restoring when session creation is enabled (if detectable) or catching DisabledSessionException and skipping the restore in that case.



##########
core/src/main/java/org/apache/shiro/mgt/DefaultSecurityManager.java:
##########
@@ -603,6 +616,9 @@ protected void stopSession(Subject subject) {
         Session s = subject.getSession(false);
         if (s != null) {
             s.stop();
+            if (subject instanceof DelegatingSubject) {
+                ((DelegatingSubject) subject).sessionStopped();
+            }

Review Comment:
   stopSession() now depends on DelegatingSubject.sessionStopped() and forces that method to be public. DelegatingSubject already wraps sessions in StoppingAwareProxiedSession, whose stop() implementation calls owner.sessionStopped(), so this extra cast/call is redundant and expands the public API surface. Consider removing the DelegatingSubject dependency here and keeping sessionStopped non-public (or otherwise documenting/isolating it as an internal hook).



##########
core/src/main/java/org/apache/shiro/subject/support/DelegatingSubject.java:
##########
@@ -379,7 +379,7 @@ public void logout() {
         }
     }
 
-    private void sessionStopped() {
+    public void sessionStopped() {

Review Comment:
   sessionStopped() was changed from private to public, but it appears to be an internal lifecycle callback (it is invoked by the internal StoppingAwareProxiedSession on Session.stop()). Exposing it publicly makes it easy for callers to put a Subject into an inconsistent state. Consider keeping it non-public and adjusting DefaultSecurityManager.stopSession() to avoid needing direct access to this method.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#2704] [#2710] [3.x] Fixed Session fixation-related regressions [shiro]

Posted by "lprimak (via GitHub)" <gi...@apache.org>.
lprimak commented on PR #2711:
URL: https://github.com/apache/shiro/pull/2711#issuecomment-4506703441

   @apupier see #2715 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org