Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
30 changes: 15 additions & 15 deletions extension.driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,44 +57,44 @@ public function appendEventFilter(array $context) {
public function eventPreSaveFilter(array $context) {
if(!in_array('xss-fail', $context['event']->eParamFILTERS) && !in_array('validate-xsrf', $context['event']->eParamFILTERS)) return;

$contains_xss = FALSE;
$contains_xss = false;

// Loop over the fields to check for XSS, this loop will
// break as soon as XSS is detected
foreach($context['fields'] as $field => $value) {
if(is_array($value)) {
if(self::detectXSSInArray($value) === FALSE) continue;
if(self::detectXSSInArray($value) === false) continue;

$contains_xss = TRUE;
$contains_xss = true;
break;
}
else {
if(self::detectXSS($value) === FALSE) continue;
if(self::detectXSS($value) === false) continue;

$contains_xss = TRUE;
$contains_xss = true;
break;
}
}

// Detect XSS filter
if(in_array('xss-fail', $context['event']->eParamFILTERS) && $contains_xss === TRUE) {
if(in_array('xss-fail', $context['event']->eParamFILTERS) && $contains_xss === true) {
$context['messages'][] = array(
'xss', FALSE, __("Possible XSS attack detected in submitted data")
'xss', false, __("Possible XSS attack detected in submitted data")
);
}

// Validate XSRF token filter
if(in_array('validate-xsrf', $context['event']->eParamFILTERS)) {
if(Symphony::Engine()->isXSRFEnabled() && is_session_empty() === false && XSRF::validateRequest(true) === false) {
$context['messages'][] = array(
'xsrf', FALSE, __("Request was rejected for having an invalid cross-site request forgery token.")
'xsrf', false, __("Request was rejected for having an invalid cross-site request forgery token.")
);
}
}
}

public static function FrontendParamsResolve(array &$context) {
Frontend::Page()->registerPHPFunction(array(
Frontend::Page()->Proc->registerPHPFunction(array(
'htmlContextCleaner',
'scriptContextCleaner',
'attributeContextCleaner',
Expand All @@ -119,11 +119,11 @@ public static function detectXSSInArray(array $array) {
return self::detectXSSInArray($value);
}
else {
if(self::detectXSS($value) === TRUE) return TRUE;
if(self::detectXSS($value) === true) return true;
}
}

return FALSE;
return false;
}

/**
Expand All @@ -136,7 +136,7 @@ public static function detectXSSInArray(array $array) {
* True if the given `$string` contains XSS, false otherwise.
*/
public static function detectXSS($string) {
$contains_xss = FALSE;
$contains_xss = false;

// Skip any null or non string values
if(is_null($string) || !is_string($string)) {
Expand Down Expand Up @@ -182,12 +182,12 @@ public static function detectXSS($string) {
foreach($patterns as $pattern) {
// Test both the original string and clean string
if(preg_match($pattern, $string) || preg_match($pattern, $orig)){
$contains_xss = TRUE;
$contains_xss = true;
}
if ($contains_xss === TRUE) return TRUE;
if ($contains_xss === true) return true;
}

return FALSE;
return false;
}

}
6 changes: 5 additions & 1 deletion extension.meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
</author>
</authors>
<releases>
<release version="2.0.0" date="TBA" min="4.0.0" max="4.x.x" php-min="5.6.x" php-max="7.x.x">
- Update for Symphony 4.x
- PHP7 Compatibility
</release>
<release version="1.5.0" date="2017-04-05" min="2.4" max="2.x.x">
- Replaced deprecated preg_replace /e in extension.driver.php
- Added German translation
Expand Down Expand Up @@ -46,4 +50,4 @@
</release>
<release version="1.0" date="2010-10-08" min="2.0.3"/>
</releases>
</extension>
</extension>