Skip to content

Commit

Permalink
PRESIDECMS-2953 prevent browser prefetches from performing actions
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicWatson committed Oct 14, 2024
1 parent ac116c9 commit f8330ef
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions system/coldboxModifications/RequestContextDecorator.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,10 @@ component accessors=true extends="preside.system.coldboxModifications.RequestCon
return IsBoolean( request._sessionSettings.statelessRequest ?: "" ) && request._sessionSettings.statelessRequest;
}

public boolean function isPrefetchRequest() {
return getHTTPHeader( "sec-purpose" ) == "prefetch";
}

public void function setXFrameOptionsHeader( string value ) {
if ( !StructKeyExists( arguments, "value" ) ) {
var setting = getPageProperty( propertyName="iframe_restriction", cascading=true );
Expand Down
9 changes: 9 additions & 0 deletions system/handlers/General.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ component {
_reloadChecks( argumentCollection = arguments );
_recordUserVisits( argumentCollection = arguments );
_setLocale( argumentCollection = arguments );
_prefetchCheck( argumentCollection = arguments );
}

public void function requestEnd( event, rc, prc ) {
Expand Down Expand Up @@ -217,6 +218,14 @@ component {
SetLocale( getModel( "i18n" ).getFwLocale() );
}

private void function _prefetchCheck( event, rc, prc ) {
if ( event.isActionRequest() && event.isPrefetchRequest() ) {
content reset=true;
header statuscode="400" statustext="Not allowed";
abort;
}
}

private void function _performDbMigrations() {
coreDatabaseMigrationService.migrate();
appDatabaseMigrationService.doMigrations();
Expand Down

0 comments on commit f8330ef

Please sign in to comment.