Overview
Affected Versions
Vendure Shop Admin API vulnerable in 1.7.4 and earlier; 2.3.3 and earlier; 3.5.6 and earlier; 3.6.1 and earlier. Patched in 2.3.4, 3.5.7, and 3.6.2.
Code Fix Example
Vulnerable and fixed Node.js (Express) code using PostgreSQL (pg) as example
// Run with: node app.js
const express = require('express');
const { Pool } = require('pg');
const app = express();
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
// Vulnerable pattern: string interpolation leads to SQL injection
app.get('/search-vulnerable', async (req, res) => {
const name = req.query.name;
// DO NOT DO THIS: vulnerable to SQL injection via name parameter
const sql = "SELECT id, email FROM users WHERE name = '" + name + "'";
try {
const result = await pool.query(sql);
res.json(result.rows);
} catch (err) {
console.error(err);
res.status(500).send('Error');
}
});
// Fixed pattern: use parameterized queries and input validation
app.get('/search-safe', async (req, res) => {
const name = req.query.name;
// Basic input validation (defense in depth). Adjust pattern to your domain.
if (typeof name !== 'string' || !/^[\\w\\s-]+$/.test(name)) {
return res.status(400).send('Invalid input');
}
// Use parameterized query with placeholder to prevent injection
const sql = 'SELECT id, email FROM users WHERE name = $1';
try {
const result = await pool.query(sql, [name]);
res.json(result.rows);
} catch (err) {
console.error(err);
res.status(500).send('Error');
}
});
app.listen(3000, () => console.log('Server running on port 3000'));