Skip to content

Commit

Permalink
Create DetectWeakReferrerPolicy.bambda
Browse files Browse the repository at this point in the history
It ensures there is a response and scans the headers for either the absence of the Referrer-Policy header or the presence of policies that may expose sensitive referrer information.
  • Loading branch information
ctflearner authored Dec 18, 2024
1 parent e1154e5 commit 76a5d38
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Filter/Proxy/HTTP/DetectWeakReferrerPolicy.bambda
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Bambda Script to Detect "Weak or Missing Referrer-Policy" Header in HTTP Response
* @author ctflearner
* This script checks if the HTTP response lacks the "Referrer-Policy" header or uses a weak policy,
* such as "no-referrer-when-downgrade" or "unsafe-url".
* It ensures there is a response and scans the headers for either the absence of the Referrer-Policy header
* or the presence of policies that may expose sensitive referrer information.
**/


return requestResponse.hasResponse() && (
// No Referrer-Policy header
requestResponse.response().headers().stream()
.noneMatch(header -> header.name().equalsIgnoreCase("Referrer-Policy")) ||

// Check for potentially weak referrer policies
requestResponse.response().headers().stream()
.filter(header -> header.name().equalsIgnoreCase("Referrer-Policy"))
.anyMatch(header -> {
String value = header.value().toLowerCase().trim();
return value.equals("no-referrer-when-downgrade") ||
value.equals("unsafe-url");
})
);

0 comments on commit 76a5d38

Please sign in to comment.