Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 193f5fe

Browse files
protichJediKev
authored andcommitted
Sanitize query to prevent SQL injection via parameter markers
The previous implementation used the regex `/:(\d+)/i` to remove a single colon preceding digits. However, this approach did not handle cases with multiple colons (e.g., "::1"), which could potentially allow for injection attempts. This commit updates the regex to `/:+(\d+)/` to match one or more colons before the digits and replaces them with just the captured number. This change ensures that all leading colons are removed, effectively neutralizing any parameter marker injection while preserving the intended numeric value.
1 parent bb4c27d commit 193f5fe

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

include/class.search.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,11 @@ function find($query, QuerySet $criteria, $addRelevance=true) {
371371
#elseif (count(explode(' ', $query)) == 1)
372372
# $mode = ' WITH QUERY EXPANSION';
373373

374-
// Strip colon (:num) to avoid possible params injection
375-
$query = preg_replace('/:(\d+)/i', '$1', $query);
374+
// Sanitize query to avoid possible SQL injection via parameter markers
375+
// This regex matches one or more colons followed by one or more digits,
376+
// and then replaces the match with only the digits (i.e. stripping the colon(s)).
377+
$query = preg_replace('/:+(\d+)/', '$1', $query);
378+
376379
// escape query and using it as search
377380
$search = 'MATCH (Z1.title, Z1.content) AGAINST ('.db_input($query).$mode.')';
378381

0 commit comments

Comments
 (0)