All notes
Security audit7 min read

I audited my own platform against OWASP. Here is what I found.

It is uncomfortable to go looking for holes in code you wrote yourself. It is a lot more uncomfortable when somebody else finds them first.

For most of the last two years I have been building a multi-tenant certification platform: one ASP.NET Core API, SQL Server underneath, and three Next.js portals for administrators, auditors and customers. It worked. Customers used it every day. And for a long time I assumed that "it works and nobody has complained" was close enough to "it is secure".

It was not. When I finally sat down and audited the whole thing against the OWASP Top 10, I wrote up 32 findings in the API and 45 in the front ends. Four of the API findings were critical. This note is about how I ran that audit and what it taught me. I have left out the client, every host name and every key on purpose. The lessons travel. The details should not.

How I ran it

There was no budget for an external penetration test, so I treated the audit like any other engineering job: a checklist, evidence for every claim, and a re-check after every fix.

  • Static review, category by category. I walked the OWASP Top 10 (2021) one category at a time and read every controller, service, stored procedure, route handler and server action with that single question in mind. Reading for one kind of bug is far more effective than reading for "anything wrong".
  • Live checks against staging. For each access-control finding I sent the request that should be refused, before and after the fix, and kept the status codes as evidence.
  • Tools for the boring parts. npm audit, dotnet list package --vulnerable, a search of the full git history for secrets, a security-header scan and SonarQube. Tools are good at finding known patterns. They found almost none of the critical issues.
  • A rescan by finding class. Once a bug was fixed, I searched both repositories for the same pattern, not the same line. This step turned up more than I expected (more on that below).

Every finding got an ID, an OWASP category, a severity, the root cause in one sentence, and the fix. That tracker became the most useful document in the project.

Access control was the real story

If I had to sum up the audit in one line: authentication was mostly fine, and authorization was everywhere and nowhere. Users had to log in, and roles were checked on controllers. But many endpoints accepted an ID from the request and simply trusted it.

// Before: the route says which company. Nobody asks whether it is yours.
[HttpGet("{customerId}/documents")]
public async Task<IActionResult> GetDocuments(int customerId)
    => Ok(await _documents.ListAsync(customerId));

A logged-in customer could change one number in the URL and read, or delete, another company's documents. Nothing about this is exotic. It is the most common bug in the OWASP list for a reason: every endpoint has to get it right, and it only takes one that does not.

The fix had two layers. In the API, a shared check on the base controller compares the requested company with the one in the caller's token. In the database, the stored procedures take the caller's identity as a parameter and filter on it, so even a future endpoint that forgets the first check cannot leak data.

-- One question, asked in one place: can this auditor reach this assignment?
CREATE FUNCTION dbo.fn_CanReachAssignment(@AuditorId INT, @AssignmentId INT)
RETURNS TABLE AS RETURN
  SELECT 1 AS ok FROM ...  -- internal auditors: everything, external: own assignments only

That small function closed four separate findings at once. This was the first lesson that stuck with me: fix the choke point, not the symptom. When I HTML-encoded values in the one shared function that fills e-mail templates, instead of the single field the finding named, it covered three more raw fields nobody had reported yet.

NULL is not false

My favourite bug of the whole audit was one I introduced while fixing another one. The new guard said: "if this auditor is external, limit them to their own certifications".

-- Looks right. Is not.
WHERE (@IsInternal = 1 OR c.AuditorId = @AuditorId)

Now delete that auditor's row while their token is still valid. @IsInternal comes back NULL, the comparison is neither true nor false, and depending on how the condition is written the restriction quietly disappears. A deleted user became less restricted than a live one.

WHERE (ISNULL(@IsInternal, 0) = 1 OR c.AuditorId = @AuditorId)  -- unknown means "no"

Then the embarrassing part. My first sweep for the same pattern missed six places, because I had piped the search through head -20 and never looked at what was cut off. The second, untruncated sweep caught them. I now treat "I searched for it" as a claim that needs the same evidence as any other.

Rule I keep nowEvery security check has to fail closed on missing data. Write the guard, then ask: what happens if this value is NULL, empty, or the row is gone?

The fix that broke login

The client login page asked for the e-mail address first, and the API answered differently for an unknown address, an inactive account and an active one. That is a textbook enumeration bug: with a list of e-mail addresses, anyone could learn who is a customer.

So I made the API return the same answer for every address. Clean, correct, done. Then I noticed the login page used those three answers to decide what to show next, including the "resend activation e-mail" button. With one uniform answer, every customer who had not activated their account yet had no way in at all. I reverted it the same day.

The real fix needed both sides: the login page now asks for e-mail and password together, and "resend activation" lives on its own page that always shows the same message. Only then could the API stop leaking. The lesson is one I keep relearning: a security fix is a product change, and it has to be designed with the screens that depend on the old behaviour.

Fail-open defaults hide in plain sight

Three of the findings were not really code at all. They were defaults:

  • The malware scanner accepted uploads when it could not find its scanning engine.
  • A middleware passed the request through when it hit an exception.
  • A cache of "is this account still active?" answered yes when the database was unreachable.

Each one was a single line, and each one was written by someone (often me) who was thinking about uptime, not attackers. Failing closed has a real cost too: in the cache case, it would turn a short database blip into a full outage for every user. So the cache now falls back to the last known state, and users who were already known to be blocked stay blocked. The point is not that failing closed is always right. The point is that it should be a decision, written down, not an accident.

Security in the wrong order

The password-reset flow revoked every session for the account, and then checked the MFA code. So anyone who knew a user's e-mail address could log them out of every device, without ever passing the second factor. Every individual step was correct. Their order was the bug. Swapping two blocks fixed it, and I found a sibling service that already did it the right way, which told me the knowledge was in the codebase, just not everywhere.

The front end is not a safe place

The single most dangerous chain in the front ends was two findings that were only medium on their own:

  1. Customer comments were rendered as HTML in the auditor's browser, cleaned by a regex "sanitizer" with Safe in its name.
  2. The session endpoint returned both the access token and the refresh token to JavaScript.

Together: one malicious comment, and an attacker walks away with a long-lived session as an auditor. The fixes were boring on purpose. Render as text by default, use DOMPurify with a strict allow-list where HTML is truly needed, and keep tokens out of anything JavaScript can read. A regex sanitizer named Safe is worse than none, because it convinces the next developer not to look.

What I would do differently

If I started again tomorrow
  • Put authorization in the data layer from day one. Every query that touches tenant data takes the caller as a parameter.
  • Never bind request bodies straight to database entities. A request DTO is a field allow-list for free; without one, a customer could set their own MFA status.
  • Keep secrets out of the repository from the first commit. Removing them from git history later is far harder than it sounds, and pull-request references cannot be force-pushed away.
  • Write the negative test first: the request that must be refused.

The audit took weeks, and fixing what it found took longer. But it changed how I read code. I no longer ask "does this work?" first. I ask "who else can call this, and what happens if they do?"