-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add request parameter filtering to avoid XSS attacks
- Loading branch information
1 parent
a3cf57b
commit 40b578e
Showing
5 changed files
with
95 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
package TgUtils; | ||
|
||
/** | ||
* An interface for not filtering string at all. | ||
*/ | ||
public class DummyStringFilter implements StringFilter { | ||
|
||
public static $INSTANCE = new DummyStringFilter(); | ||
|
||
public __construct() { | ||
} | ||
|
||
/** | ||
* Filters the given string and returns sanitized value. | ||
* @param string $s - string to sanitize (can be null) | ||
* @return the sanitized string. | ||
*/ | ||
public filter($s) { | ||
return $s; | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
package TgUtils; | ||
|
||
/** | ||
* An interface for filter strings from any HTML tags. | ||
*/ | ||
public class NoHtmlStringFilter implements StringFilter { | ||
|
||
public static $INSTANCE = new NoHtmlStringFilter(); | ||
|
||
public __construct() { | ||
} | ||
|
||
/** | ||
* Filters the given string and returns sanitized value. | ||
* @param string $s - string to sanitize (can be null) | ||
* @return the sanitized string. | ||
*/ | ||
public filter($s) { | ||
if ($s == NULL) return $s; | ||
return strip_tags($s); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
package TgUtils; | ||
|
||
/** | ||
* An interface for filter strings from evil input. | ||
*/ | ||
public interface StringFilter { | ||
|
||
/** | ||
* Filters the given string and returns sanitized value. | ||
* @param string $s - string to sanitize (can be null) | ||
* @return the sanitized string. | ||
*/ | ||
public filter($s); | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
package TgUtils; | ||
|
||
/** | ||
* Provides default string filters. | ||
*/ | ||
public class StringFilters { | ||
|
||
public static $DUMMY = DummyStringFilter::$INSTANCE; | ||
public static $NO_HTML = NoHtmlStringFilter::$INSTANCE; | ||
|
||
} | ||
|