Notes

Web Security: From Green Tests to a Simulated Attack

339 green tests do not guarantee that nobody can get in. An external suite of 27 web attack tests and a project closeout checklist.

2 min read

A few days ago, I wrapped up a review of the core website: 37 bugs found and fixed, and 339 unit tests passing. At that point, you could say the website worked. But a green test only proves that the code does what it is supposed to do, not that nobody can do what they are not supposed to do. So I took the next step: a suite of tests in the form of an attack, from the outside, just as someone trying to get in would.

The attack suite

I ran 27 tests from the outside, never touching the database or sending anything destructive. The idea is simple: to test exactly what a real attacker would try.

  • Authentication: accessing the administration API without a token, with an invented token, with malformed headers, and trying to delete articles without permission.
  • Injection: classic SQL injection in the search boxes, scripts injected into parameters, and directory traversal via slugs and files.
  • Leaks: files such as .env, .git, backups, and the API endpoint map.
  • Private content: trying to extract drafts and unpublished articles through the public API.

The result

Nothing serious. No unauthorized access, no injection, no leak. The drafts could not be extracted by any route. What did emerge were five HTTP header issues: HSTS was missing, as were a content policy, anti-clickjacking, and nosniff, and unencrypted HTTP served content without redirecting to HTTPS. None of it exposed any data whatsoever, but these are the kinds of locks a serious server should have.

I added them to the gateway, after taking a backup beforehand, and reran the entire suite: 27 out of 27. Only two switches remain in the Cloudflare panel, which the account owner has to enable: Always Use HTTPS and edge HSTS.

When you close a project

This review made clear what needs to be done before considering a project closed, beyond functional testing:

  1. Tests in the real environment. My 339 tests passed locally with seven exceptions due to environment limitations; in the container, in production, all 339 pass. It is worth running them where the code will live.
  2. An external suite. Authentication, injection, leaks, drafts. Even if the unit tests are green.
  3. Security headers. HSTS, CSP, X-Frame-Options, nosniff. Five minutes of configuration that an automated scanner always flags.
  4. Zero secrets. No tokens or passwords in the repository, logs, or reports. The attack suite derives credentials without ever printing them.
  5. Tested backup and rollback. Every configuration change with a prior backup and a clear path back.
  6. How everything is reproduced. If, in a year, nobody knows how to rerun the tests, half the work has been lost.

The suite is saved as a script and can be rerun whenever I want. A green test is the starting point, not the end.