Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Server Development
Habbo Retros
Habbo Releases
CMS Releases
HylibCMS - All Emulators
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="BIOS" data-source="post: 466723" data-attributes="member: 15674"><p>[URL unfurl="true"]https://github.com/TheLaxus/Hylib/blob/63190a08d52eaecd286a52f9c04c07ddb5d8d461/configuration/class/class.functions.php#L41-L69[/URL]</p><p>[CODE=php] static function Filter($type, $string) {</p><p> if ($type == 'XSS' || $type == 'xss') {</p><p> $value = htmlspecialchars_decode($string);</p><p> $value = trim($value);</p><p></p><p> # 18</p><p> $search = [</p><p> "<script", "/script>",</p><p> "<div", "/div>",</p><p> "<a", "/a>",</p><p> "<button", "/button>",</p><p> "<?php", "?>",</p><p> "<?=", "?>",</p><p> "<svg", "/svg>",</p><p> "<link", "<?xml"</p><p> ];</p><p></p><p> $replace = [</p><p> "", "",</p><p> "", "",</p><p> "", "",</p><p> "", "",</p><p> "", "",</p><p> "", "",</p><p> "", "",</p><p> "", "",</p><p> "", ""</p><p> ];</p><p> </p><p> $value = str_replace($search, $replace, $value);[/CODE]</p><p></p><p>Don't do this to prevent XSS, it's the least effective way to go about it. What about img tags? Or literally any invalid character tag? There's too many permutations to be able to "replace" known-bad.</p><p></p><p>Instead use an actual template engine like Twig which has built in escaping: <a href="https://twig.symfony.com/doc/2.x/filters/escape.html" target="_blank">https://twig.symfony.com/doc/2.x/filters/escape.html</a></p><p></p><p>Or if you want to stick to vanilla PHP, use htmlentities for 99% of cases, and htmlspecialchars. That entire code block can pretty much be replaced with a one line htmlentities($string) and do a much better job.</p></blockquote><p></p>
[QUOTE="BIOS, post: 466723, member: 15674"] [URL unfurl="true"]https://github.com/TheLaxus/Hylib/blob/63190a08d52eaecd286a52f9c04c07ddb5d8d461/configuration/class/class.functions.php#L41-L69[/URL] [CODE=php] static function Filter($type, $string) { if ($type == 'XSS' || $type == 'xss') { $value = htmlspecialchars_decode($string); $value = trim($value); # 18 $search = [ "<script", "/script>", "<div", "/div>", "<a", "/a>", "<button", "/button>", "<?php", "?>", "<?=", "?>", "<svg", "/svg>", "<link", "<?xml" ]; $replace = [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" ]; $value = str_replace($search, $replace, $value);[/CODE] Don't do this to prevent XSS, it's the least effective way to go about it. What about img tags? Or literally any invalid character tag? There's too many permutations to be able to "replace" known-bad. Instead use an actual template engine like Twig which has built in escaping: [URL]https://twig.symfony.com/doc/2.x/filters/escape.html[/URL] Or if you want to stick to vanilla PHP, use htmlentities for 99% of cases, and htmlspecialchars. That entire code block can pretty much be replaced with a one line htmlentities($string) and do a much better job. [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Server Development
Habbo Retros
Habbo Releases
CMS Releases
HylibCMS - All Emulators
Top