← All writing

· 4 min read

What a static security review of a small B2B app actually found

A code review of CELE's web platform turned up nothing dramatic and several things worth fixing: Blob deletes, push subscriptions, mail hosts, login rate limits and a timing leak. Here is each finding and how it was closed.

CELE's platform has a public catalog, an admin panel and a dealer inbox, all in one Next.js app. In July the repo got a written security and quality review: static analysis and remediation of the code, configuration, data model, routes and dependencies. It was explicitly not a penetration test, and it says so in its first lines. The findings are a good sample of what goes wrong in a small business app that has grown real features.

The contact form, one of the BotID-protected entry points

The headline: nothing exotic

Every finding below is the ordinary kind: a missing ownership check, a setting that was too flexible, a place where a fast failure leaks information. That is the useful lesson. Small apps are rarely broken by clever attacks. They are broken by checks that were assumed.

Findings and fixes

Blob deletion trusted the client (P1). The upload flow accepted a previousUrl from the browser and deleted that file on completion. Anyone with upload permission and a known URL could delete another asset. The fix removed the field entirely: upload completion no longer deletes anything, and deletes now happen only in mutations that load the stored record first, such as manuals, messages and technical reviews. The accepted cost is some orphaned blobs from older editors, which is a better problem than deleting what you do not own.

Push subscriptions had no owner check (P2). Deleting a subscription needed only an endpoint. Now it requires the endpoint and the user, creating one for an endpoint already owned by another account is rejected, and logout removes the association on the server before the browser unsubscribes. Deletion stays idempotent and reveals nothing about other people's rows.

Mail host and port were editable (P2). The mailbox settings let an admin type any IMAP and SMTP host, which made the server a request forwarder to arbitrary infrastructure. Host and port are now fixed in server code and the form no longer asks for them. Removing a field was safer than validating it.

Login had no rate limit inside the app (P2). A firewall limits by source address, which does not help against one account being guessed from many addresses, the case that matters. Failed attempts are now counted per account and per IP in Redis, with a limit that returns 429, and emails are hashed before they form a key. The limit fails open if Redis is unreachable, on purpose: the firewall remains the first line and this control complements it.

Account enumeration by response time (P2). The endpoint only derived the password hash when the email existed, so an unknown address answered noticeably faster. Now the verification always runs, against a fixed unmatchable hash when there is no user, so both branches pay the same cost. The response text and status code were already identical.

A label that said the wrong thing (P2). A customer believed they had been registered as a dealer. The cause was not roles but wording: the only way back into the login modal was titled "dealer login". Self-registration only ever creates a client account and never reads a role from the request. The fix was copy: a neutral "Sign in", with the dealer note as a secondary hint. No permission changed.

Post-login redirects assumed the panel (P3). The login page defaulted to /admin and dropped the redirect for non-staff. One rule now decides: honor the requested destination only if the user's role can open it, otherwise go to that role's home. Asking for /admin gets nobody closer to it, since authorization stays on the server.

Legacy HTML in news (P2). One old field still held raw HTML. It now passes through an allowlist that keeps text, lists, links and images and removes scripts, iframes, event handlers, styles and unsafe URL schemes.

Dependencies and stack traces (P3). Two transitive dependencies carried moderate advisories and were pinned to fixed versions, bringing the audit to zero. Stack traces in the error screen are now visible only to the owner, and persisted traces have the checkout path and common sensitive query values redacted.

What was already right

The review also lists what it verified, which is as useful as the bugs:

  • Session cookies are httpOnly, Secure in production and SameSite=Lax. Tokens are validated against an auth version, and refresh tokens are random, hashed and rotated.
  • MFA secrets are encrypted, the challenge is a short-lived signed value, replay is blocked by tracking the last used time step, and enforcement sits behind a feature flag.
  • Permissions are checked in components, actions and handlers. The proxy is not the final authority.
  • Private product manuals need a permission, use a private store and respond with no-store and nosniff.
  • The scheduled cleanup job requires a bearer secret and fails closed.
  • The WebSocket authenticates before upgrade and limits payloads.
  • The content security policy sets default-src 'self', object-src 'none', base-uri 'self' and lists its origins explicitly.

One detail from the CSP is worth keeping: the bot-detection challenge opens a hidden same-origin iframe, so a strict frame-ancestors 'none' silently broke it and made real logins look like bots. The policy now allows 'self' only, which keeps clickjacking protection intact.

The quality half

Admin reads are paginated with a lookahead row instead of counting, request-local reads are deduplicated, and the build root is pinned so a stray lockfile higher up the tree stops confusing workspace detection. The tests cover blob policies, sanitization, pagination, redirects by role and the self-registration privileges, and the build and type check pass.

The remaining debt is written down too: a compressed admin page to refactor, an old role column that coexists with the RBAC tables, and a legacy HTML renderer that can go once those records move to blocks. A review that ends with an honest list of what is left is one you can trust the rest of.