# Avoiding false-positives When you run Psalm's taint analysis for the first time you may see a bunch of false-positives. Nobody likes false-positives! There are a number of ways you can prevent them: ## Escaping tainted input Some operations remove taints from data – for example, wrapping `$_GET['name']` in an `htmlentities` call prevents cross-site-scripting attacks in that `$_GET` call. Psalm allows you to remove taints via a `@psalm-taint-escape ` annotation: ```php '], '', $str); echo $str; } echoVar($_GET["text"]); ``` ## Conditional escaping tainted input A slightly modified version of the previous example is using a condition to determine whether the return value is considered secure. Only in case function argument `$escape` is true, the corresponding annotation `@psalm-taint-escape` is applied for taint type `html` . ```php /** * @param string $str * @param bool $escape * @psalm-taint-escape ($escape is true ? 'html' : null) */ function processVar(string $str, bool $escape = true) : string { if ($escape) { $str = str_replace(['<', '>'], '', $str); } return $str; } echo processVar($_GET['text'], false); // detects tainted HTML echo processVar($_GET['text'], true); // considered secure ``` ## Specializing taints in functions For functions, methods and classes you can use the `@psalm-taint-specialize` annotation. ```php name = $name; } } /** * @psalm-taint-specialize */ function echoUserName(User $user) { echo $user->name; // Error, detected tainted input } $user1 = new User("Keith"); $user2 = new User($_GET["name"]); echoUserName($user1); ``` Adding `@psalm-taint-specialize` to the class fixes the issue. ```php name = $name; } } /** * @psalm-taint-specialize */ function echoUserName(User $user) { echo $user->name; // No error } $user1 = new User("Keith"); $user2 = new User($_GET["name"]); echoUserName($user1); ``` And, because it’s form of purity enforcement, `@psalm-immutable` can also be used: ```php name = $name; } } /** * @psalm-taint-specialize */ function echoUserName(User $user) { echo $user->name; // No error } $user1 = new User("Keith"); $user2 = new User($_GET["name"]); echoUserName($user1); ``` ## Avoiding files in taint paths You can also tell Psalm that you’re not interested in any taint paths that flow through certain files or directories by specifying them in your Psalm config: ```xml ```