Skip to content

Commit

Permalink
Item14150: Recompute validation keys on cached pages
Browse files Browse the repository at this point in the history
Fix provided by MichaelDaum. Cached pages were keeping their original
cached validation keys.  Once they expired, it was impossible to submit
forms on cached pages without refreshing the cache.
  • Loading branch information
gac410 committed Aug 31, 2016
1 parent e6426cf commit 377070f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core/lib/Foswiki/PageCache.pm
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,14 @@ sub _handleDirtyArea {
$prefs->popTopicContext();
};

my $request = $session->{request};
my $context = $request->url( -full => 1, -path => 1, -query => 1 ) . time();
my $cgis = $session->{users}->getCGISession();
my $usingStrikeOne = $Foswiki::cfg{Validation}{Method} eq 'strikeone';

$text =~
s/<input type='hidden' name='validation_key' value='(\?.*?)' \/>/Foswiki::Validation::updateValidationKey($cgis, $context, $usingStrikeOne, $1)/gei;

#Foswiki::Func::writeDebug("out text='$text'") if TRACE;
return $text;
}
Expand Down
9 changes: 9 additions & 0 deletions core/lib/Foswiki/Validation.pm
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ sub addValidationKey {
return "<input type='hidden' name='validation_key' value='?$nonce' />";
}

sub updateValidationKey {
my ( $cgis, $context, $strikeone, $oldKey ) = @_;

# expire old key
expireValidationKeys( $cgis, $oldKey );

return addValidationKey( $cgis, $context, $strikeone );
}

=begin TML
---++ StaticMethod generateValidationKey( $cgis, $context, $strikeone ) -> $nonce
Expand Down

0 comments on commit 377070f

Please sign in to comment.