Overview
Affected Versions
N/A (Java Spring AI CVE) / Node.js implementations not tied to a specific version in the provided CVE
Code Fix Example
Vulnerable:
const express = require('express');
const jsonpath = require('jsonpath');
const app = express();
// Example in-memory document store
const docStore = {
documents: [
{ id: 1, owner: 'alice', metadata: { tag: 'private' } },
{ id: 2, owner: 'bob', metadata: { tag: 'public' } }
]
};
app.get('/docs', (req, res) => {
const owner = req.query.owner; // user-controlled input
// Vulnerable: user input is embedded directly into JSONPath expression
const pathExpr = "$.documents[?(@.owner == '" + owner + "')]";
const results = jsonpath.query(docStore, pathExpr);
res.json(results);
});
app.listen(3000, () => console.log('Server started'));
Fixed (safer approach):
const express = require('express');
const jsonpath = require('jsonpath');
const app = express();
const docStore = {
documents: [
{ id: 1, owner: 'alice', metadata: { tag: 'private' } },
{ id: 2, owner: 'bob', metadata: { tag: 'public' } }
]
};
app.get('/docs', (req, res) => {
const owner = req.query.owner; // user input
// Safe approach: avoid embedding user input into JSONPath. Retrieve candidates then filter.
const candidates = jsonpath.query(docStore, '$.documents');
const filtered = candidates.filter(d => d.owner === owner);
res.json(filtered);
});
app.listen(3000, () => console.log('Server started'));