PHP › Static Analysis (PHPStan & Psalm)
How does Psalm's concept of taint analysis help detect potential security vulnerabilities like SQL injection or cross site scripting during static analysis?
IntermediateAnswer
Taint analysis tracks how data flows through an application starting from an untrusted source, such as user submitted form input, following that data through every function call and variable assignment it passes through, and flags a potential security issue if that tainted, untrusted data ever reaches a sensitive destination, called a sink, such as being directly concatenated into a raw SQL query or echoed directly into HTML output, without first being properly sanitized or escaped somewhere along that path.
vendor/bin/psalm --taint-analysisReal-world example A security conscious team runs Psalm's taint analysis feature as part of their continuous integration pipeline, automatically catching a case where a developer accidentally passed raw, unescaped user input directly into an HTML template without first sanitizing it.