Sample report

Security report: example-app

This is a sample. The application, its code and the findings are invented. It shows what a CrimsonLock report contains and how much detail to expect.

Application
example-app, a fictional order management API
Scope
Source code of the backend API
Stack
Node.js (Express), PostgreSQL
Findings
  • Critical1
  • High2
  • Medium1
  • Low1

Executive summary

We reviewed the source code of example-app’s backend API and found five vulnerabilities: one critical, two high, one medium and one low.

The most urgent is a live payment provider key stored in the repository (CL-01). Treat it as compromised and revoke it today: anyone who can read the repository, or has ever cloned it, can use it.

Two high-severity findings let one customer reach another customer’s data: a database query that can be manipulated (CL-02) and an export endpoint that never checks who is asking (CL-03).

None of the five needs a redesign. Each is a contained change, and a proposed fix is included with every finding.

What to fix first

  1. CL-01: revoke and replace the exposed key.
  2. CL-02 and CL-03: close the two ways into other customers’ data.
  3. CL-04: switch password reset tokens to a secure random source.
  4. CL-05: stop returning stack traces.

Findings at a glance

Findings in detail

findings / CL-01 Fix proposed
Critical

Production API key committed to the repository

config/payments.js:4

What we found

The live key for the payment provider is written directly into a source file. It has been there since the file was first committed, so it is also in the Git history.

Impact

Anyone who can read the repository can act as example-app towards the payment provider, for example to issue refunds or read customer payment records. That includes former contractors and every laptop or build server that holds a clone.

Proposed fix

  1. Revoke this key at the payment provider and issue a new one. Deleting it from the file is not enough, because it stays in the Git history.
  2. Load the new key from the environment or a secrets manager, never from source.
  3. Add secret scanning to your build pipeline, so a committed key is caught before it is merged.
2 module.exports = {
3 baseUrl: 'https://api.payments.example',
4- apiKey: '[live key, redacted in this report]',
4+ apiKey: process.env.PAYMENTS_API_KEY,
5 };
findings / CL-02 Fix proposed
High

SQL injection in order lookup

src/api/orders.js:40

What we found

The order ID from the query string is joined straight into a SQL statement. Nothing checks the value first, so the caller controls part of the query.

Impact

Anyone who can call this endpoint can read every order in the database by sending a crafted ID such as 1 OR 1=1. Because the statement is sent without parameters, a second statement can be appended to it, so orders can be changed or deleted as well.

Proposed fix

Pass the ID as a bound parameter. The database then treats it as a value and never as part of the statement.

38 const { id } = req.query;
39 const rows = await db.query(
40- "SELECT * FROM orders WHERE id = " + id
40+ "SELECT * FROM orders WHERE id = $1",
41+ [id]
42 );
43 res.json(rows);
findings / CL-03 Fix proposed
High

Missing authorization check on export endpoint

src/api/export.js:18

What we found

The export endpoint checks that the caller is logged in, but not that the account in the URL is their own. The account ID is taken from the path and used as it is.

Impact

Any logged-in customer can download the complete order history of any other account by changing the number in the URL. Account IDs are sequential, so every account can be walked through one by one.

Proposed fix

Take the account from the logged-in session, not from the URL. After this change the account ID in the path is no longer used: either remove it from the route, or keep it and answer with “not found” when it does not match the session.

16 // GET /accounts/:accountId/export
17 async function exportOrders(req, res) {
18- const { accountId } = req.params;
18+ const { accountId } = req.user;
19 const orders = await db.query(
20 'SELECT * FROM orders WHERE account_id = $1',
21 [accountId]
22 );
23 res.json(orders);
24 }
findings / CL-04 Fix proposed
Medium

Predictable password reset tokens

src/auth/reset.js:12

What we found

Password reset tokens are generated with Math.random(), which is not a cryptographic random source. Its internal state can be reconstructed from a handful of observed values.

Impact

An attacker who requests a few reset tokens for an account they control can work out the generator’s state, predict the token issued for someone else’s reset, and take over that account. This takes skill and careful timing, which is why it is rated medium and not high.

Proposed fix

Generate tokens with Node’s built-in crypto module. Two related steps are worth doing in the same change: store only a hash of the token, and let it expire after a short time.

11 function createResetToken() {
12- return Math.random().toString(36).slice(2);
12+ return crypto.randomBytes(32).toString('hex');
13 }
findings / CL-05 Fix proposed
Low

Stack traces returned in error responses

src/app.js:58

What we found

The global error handler sends the full error, including the stack trace, back to whoever made the request.

Impact

Stack traces reveal file paths, library versions and fragments of SQL. None of that is a breach on its own, but it tells an attacker exactly where to look, and it made CL-02 quicker to confirm.

Proposed fix

Log the error on the server and return a generic message. If support needs to match a user’s report to a log entry, add a request ID to both.

57 app.use((err, req, res, next) => {
58- res.status(500).json({
59- error: err.message,
60- stack: err.stack,
61- });
58+ console.error(err);
59+ res.status(500).json({ error: 'Internal error' });
62 });

Remediation options

Your team can apply every fix in this report as written. If you would rather have CrimsonLock implement them, each finding is quoted separately and you choose which ones we take on.