1

I'm trying to use Psalm to detect SQL Injections. I have the following code :

$pdo = new PDO("mysql:host=db;dbname=tp;port=3306", "user", "password");;
// VULNERABLE CODE - direct string concatenation in query
$userId = $_GET['id']; // User input from URL parameter
// Vulnerable query without parameterization
$query = "SELECT * FROM users WHERE id = " . $userId;
$result = $pdo->query($query);
echo "<pre>";
var_dump($result->fetchAll());
echo "</pre>";
die();

And I run the following command to scan (I have no config file)

vendor/bin/psalm --taint-analysis ./src/index.php 

But no error is found...

Your Common Sense
158k42 gold badges226 silver badges374 bronze badges
asked Mar 13, 2025 at 20:10
2

1 Answer 1

2

I edited the config file psalm.xml

  • On psalm tag I added the attribute runTaintAnalysis="true"

  • I enabled the pdo extension (<enableExtensions><extension name="pdo" /></enableExtensions>

<?xml version="1.0"?>
<!-- Add runTaintAnalysis -->
<psalm
 errorLevel="1" 
 resolveFromConfigFile="true"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns="https://getpsalm.org/schema/config"
 xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
 findUnusedBaselineEntry="true"
 findUnusedCode="true"
 runTaintAnalysis="true" 
>
 <projectFiles>
 <directory name="src" />
 <ignoreFiles>
 <directory name="vendor" />
 </ignoreFiles>
 </projectFiles>
 <!-- Important -->
 <enableExtensions>
 <extension name="pdo" />
 </enableExtensions>
</psalm>

And now I just run the commande like so

vendor/bin/psalm 

Found randomly in the config file reference https://psalm.dev/docs/running_psalm/configuration/#enableextensions

answered Mar 13, 2025 at 21:10
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.