Basic injection checks for every API endpoint

Injection bugs are older than most APIs, and they still turn up: a search parameter concatenated into SQL, a filter object passed straight to MongoDB, a filename handed to a shell. A scanner finds some. A handful of payloads in your own collection, run on every push, catches the regression when someone writes a new query by hand.

This isn't a penetration test. It's a smoke alarm.

The payloads

injection.csv
name,payload
sql quote,'
sql tautology,' OR '1'='1
sql comment,admin'--
sql union,' UNION SELECT NULL--
sql sleep,' OR pg_sleep(5)--
nosql operator,{"$ne": null}
nosql where,{"$where": "sleep(5000)"}
command,; sleep 5
command backticks,`sleep 5`
template erb,<%= 7*7 %>
template dollar,${7*7}
template hash,#{7*7}
path traversal,../../../../etc/passwd
long input,AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

Add payloads for the database and template engine you actually use. Leave out payloads with double curly braces: Requestarium would read them as a variable.

One request, every payload

Duplicate a request that takes user input and put {{payload}} where a user would type:

Output
GET {{baseUrl}}/products?search={{payload}}

or in the body:

JSON
{ "name": "{{payload}}", "email": "{{$randomEmail}}" }

In a JSON body, a payload with quotes breaks the JSON itself. Escape it in a pre-request script and use {{payloadJson}} in the body instead:

JavaScript
pm.variables.set('payloadJson', JSON.stringify(pm.iterationData.get('payload')).slice(1, -1));

What a safe answer looks like

JavaScript
const name = pm.iterationData.get('name');
const body = pm.response.text();

pm.test(`${name}: no server error`, () => {
  pm.expect(pm.response.code).to.be.below(500);
});

pm.test(`${name}: no database or stack trace in the response`, () => {
  pm.expect(body).to.not.match(/SQL syntax|syntax error at or near|ORA-\d+|SQLSTATE|MongoError|Traceback|at [\w.]+\(.*:\d+\)/i);
});

pm.test(`${name}: answered quickly`, () => {
  pm.expect(pm.response.responseTime).to.be.below(3000);
});

pm.test(`${name}: template not evaluated`, () => {
  pm.expect(body).to.not.include('49');
});
  • 500 often means the payload reached somewhere it shouldn't.
  • Database error text in the response is an information leak even when nothing else happened (see error responses).
  • A slow answer to a sleep payload means it ran. That's the most reliable signal you'll get from outside.
  • 49 in the response to ${7*7} or <%= 7*7 %> means a template engine evaluated user input. (Check the field doesn't contain 49 for another reason.)

The template test is a heuristic. Tune it to the response you expect.

Run it

Terminal
requestarium run-collection "Shop API" --folder "Security/Injection" --env Staging --data injection.csv

Each payload becomes an iteration, and the report names the payload in every failed test.

Where to point it

Not every field is worth it. Prioritize:

  • search and filter parameters, sorting (?sort=name;DROP…),
  • anything used in a file path or a shell command (exports, image processing, imports),
  • fields that end up in emails or PDFs (template injection),
  • JSON bodies passed to a NoSQL query.