aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/Catalyst/Plugin/FixMyStreet/Session/RotateSession.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2019-11-21 21:21:21 +0000
committerMatthew Somerville <matthew@mysociety.org>2019-11-22 13:12:58 +0000
commit09026f609ce28860d555967e0f5d7cd833fb20d0 (patch)
tree46140d431cef35d461051092e20784085e6e6d89 /perllib/Catalyst/Plugin/FixMyStreet/Session/RotateSession.pm
parent199f90a375124b684f9d3e64299dbf3967fb1640 (diff)
Rotate session ID after successful login.
Diffstat (limited to 'perllib/Catalyst/Plugin/FixMyStreet/Session/RotateSession.pm')
-rw-r--r--perllib/Catalyst/Plugin/FixMyStreet/Session/RotateSession.pm26
1 files changed, 26 insertions, 0 deletions
diff --git a/perllib/Catalyst/Plugin/FixMyStreet/Session/RotateSession.pm b/perllib/Catalyst/Plugin/FixMyStreet/Session/RotateSession.pm
new file mode 100644
index 000000000..8da88721f
--- /dev/null
+++ b/perllib/Catalyst/Plugin/FixMyStreet/Session/RotateSession.pm
@@ -0,0 +1,26 @@
+package Catalyst::Plugin::FixMyStreet::Session::RotateSession;
+use Moose::Role;
+use namespace::autoclean;
+
+# After successful authentication, rotate the session ID
+after set_authenticated => sub {
+ my $c = shift;
+ $c->change_session_id;
+};
+
+# The below is necessary otherwise the rotation fails due to the delegate
+# holding on to the now-deleted old session. See
+# https://rt.cpan.org/Public/Bug/Display.html?id=112679
+
+after delete_session_data => sub {
+ my ($c, $key) = @_;
+
+ my ($field) = split(':', $key);
+ if ($field eq 'session') {
+ $c->_session_store_delegate->_session_row(undef);
+ } elsif ($field eq 'flash') {
+ $c->_session_store_delegate->_flash_row(undef);
+ }
+};
+
+1;