Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security Update: XSS URL parameter sanitisation #91

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Requests containing URL parameters are now sanitised to prevent XSS a…
…ttacks
mballantinegcd committed May 20, 2024
commit 6045be87ec1f470e2dc3525eb7cf3c996a7c524e
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change log

### 1.7.8

* Updated: Requests containing URL parameters are now sanitised to prevent XSS attacks

### 1.7.7
* Fixed: More deprecated required parameter follows optional parameter warnings

15 changes: 15 additions & 0 deletions src/UrlHandlers/UrlHandler.php
Original file line number Diff line number Diff line change
@@ -266,6 +266,17 @@ protected function getAbsoluteHandledUrl()
return $request->server("REQUEST_SCHEME") . "://" . $request->server("SERVER_NAME") . $this->handledUrl;
}

private function sanitizeRequest($request) {
foreach ($request as $key => $value) {
if (is_string($value)) {
$request->$key = filter_var($value, FILTER_SANITIZE_STRING);
} elseif (is_array($value)) {
$request->$key = filter_var_array($value, FILTER_SANITIZE_STRING);
}
}
return $request;
}

/**
* Return the response when appropriate or false if no response could be generated.
*
@@ -277,6 +288,10 @@ protected function getAbsoluteHandledUrl()
*/
public function generateResponse($request = null, $currentUrlFragment = false)
{
if ($request !== null) {
$request = $this->sanitizeRequest($request);
}

if ($currentUrlFragment === false) {
$currentUrlFragment = $request->urlPath;
}