Created
January 17, 2020 01:43
-
-
Save afzafri/73abed3dbc9c208eacf717ec0a25b3ed to your computer and use it in GitHub Desktop.
Replace all occurrences of JS script tags in string. Quick way but not the best to prevent XSS
This file contains hidden or 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
<?php | |
$attack = "<script>alert('boom');</script>"; | |
$sanitized = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $attack); | |
echo $sanitized; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment