What potential pitfalls can arise when using PHP_SELF in form action attributes?

Using PHP_SELF in form action attributes can be risky as it can make your application vulnerable to cross-site scripting (XSS) attacks. To mitigate this risk, it is recommended to use htmlspecialchars() function to sanitize the PHP_SELF variable before using it in the form action attribute.

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
  <!-- form fields go here -->
</form>