Performance: XSS prevention
XSS prevention affects page security and user trust, indirectly impacting user experience and interaction speed.
<?php echo esc_html($_GET['user_input']); ?><?php echo $_GET['user_input']; ?>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Direct output of user input | Potentially large if scripts manipulate DOM | Multiple if scripts cause layout changes | High if malicious scripts run | [X] Bad |
| Escaping user input with esc_html() | Minimal DOM impact | No extra reflows | No extra paint cost | [OK] Good |
| Allowing raw HTML input | High if scripts inject elements | Multiple reflows possible | High paint cost | [X] Bad |
| Filtering HTML with wp_kses_post() | Controlled DOM elements | Minimal reflows | Stable paint cost | [OK] Good |
<script>alert('XSS')</script>?
<?php echo esc_html($_GET['input']); ?>
<?php $user_input = $_POST['comment']; echo $user_input; ?>
<strong> and <a> in user comments but prevent scripts. Which WordPress function should you use?Pass the test and this pattern moves unknown