DEV Community

Daniel Pertu
Daniel Pertu

Posted on

Three of our pages answer DELETE with the whole document, and the sweep that found it got my own client challenged by our edge

Notifio has a 38-page website and eight API routes behind it: seven that only export POST and one that only exports GET. I have counted the status codes those routes return from the source before. What I had never done is ask the pages and the routes about methods nobody wrote a handler for.

The sweep was nine methods over the 38 URLs in the sitemap: GET, HEAD, OPTIONS, POST, PUT, DELETE, PATCH, TRACE, and BREW, which exists in a joke RFC and is a good stand-in for a method no framework has heard of. On the API routes I used everything except POST, because POST on those routes is the thing that sends email and creates checkout sessions, and a measurement is not allowed to charge anybody.

What 38 pages answer

Method 35 prerendered pages /, /pricing, /download
GET 200, full document 200, full document
HEAD 200, zero bytes 200, zero bytes
OPTIONS 204, zero bytes 200, full document
POST 405, zero bytes 200, full document
PUT 405, zero bytes 200, full document
DELETE 405, zero bytes 200, full document
PATCH 405, zero bytes 200, full document
TRACE 405, 72 bytes 405, 72 bytes

DELETE https://notifio.app/ returns 93,725 bytes of HTML and a 200. So does PATCH, and so does OPTIONS, which is the one that surprised me most, because OPTIONS is supposed to be about the resource and not of the resource.

The reason is the same reason those three pages cannot be cached: they are the three with a price on, so they render per request instead of at build time. A prerendered route in Next.js is a file, and a file has exactly one method that makes sense, which is why 35 of our pages answer 405 without being asked to. A dynamically rendered page is a function, and that function never looks at request.method, so it does the only thing it knows how to do: render the page.

Nothing is broken here. A 200 with a document is a harmless answer to DELETE on a page with nothing to delete. It is worth knowing anyway, for two reasons. Monitoring tools and security scanners read "200 to DELETE" as a finding and will file it. And it means those three URLs are the only ones on the site where the response does not depend on the method at all, which is a difference in behaviour nobody chose and nothing in the repository mentions.

The one real defect in that table is a header that is not in it. Every 405 on this site arrives without an Allow header, and RFC 9110 says a 405 must send one. Thirty-five pages times four methods is 140 responses that tell a client it used the wrong method and refuse to say which method is right.

I confirmed both halves in a real browser afterwards, since fetch can send most of these:

await (await fetch("/help", { method: "OPTIONS" })).status   // 204
await (await fetch("/",     { method: "DELETE"  })).status   // 200, 93,642 bytes
Enter fullscreen mode Exit fullscreen mode

And then the edge joined in

The sweep is 342 requests at the pages and 64 at the API routes, run back to back. Somewhere around request 380, the answers stopped coming from our application:

HTTP/2 403
cache-control: private, no-store, max-age=0
content-type: text/html; charset=utf-8
retry-after: 30
x-vercel-challenge-token: 2.1795779461.60.Nzk3ZmY5OTE1...
x-vercel-mitigated: challenge
server: Vercel
Enter fullscreen mode Exit fullscreen mode

Every API route and most of the remaining pages answered with a 25,153-byte HTML document instead. That document is not ours: it is the platform's challenge page, built with Astro, and the data-astro-cid- attributes in the markup are how you can tell at a glance that you are reading the host's page and not your own.

It also contains this, which I enjoyed more than I should have:

<meta name="theme-color" content="#000">
Enter fullscreen mode Exit fullscreen mode

I spent a post earlier today noting that none of our 38 pages sends a theme-color. The one page in front of our domain that does is the one that tells you to go away.

The part worth measuring was what happened next. retry-after says 30 seconds. Half an hour later, the same client was still being challenged, and a browser on the same machine and the same IP was not:

11:41:21  curl https://notifio.app/help                          403
11:41:22  headless Chromium, fresh context, no cookies            200
11:41:23  curl again                                             403
11:41:23  curl with a current Chrome User-Agent string           403
Enter fullscreen mode Exit fullscreen mode

So the mitigation is not reading the User-Agent, and the browser is not getting through on a cookie it was handed earlier, because the context was new. I cannot see from the outside what the distinguishing signal is, and the honest summary is the observation: two clients, one IP, two seconds apart, 403 and 200.

This is the protection doing its job to a client that behaved like a scanner, which is what my client was. It is still a useful thing to have seen, because of who else talks to those routes.

The desktop app is a client too

The app posts to /api/validate to check a licence and to /api/notify to send an alert. Here is how the licence check reads a failure:

if (!res.ok) {
  // Only a considered "no" from the server counts as one.
  //
  // A 429 used to land here and be recorded as an invalid licence, which
  // it plainly is not: the endpoint is rate limited per IP, so a burst of
  // checks (or a shared office address) could switch someone's working
  // licence off. Anything that is not the server having looked the licence
  // up and refused is "we do not know".
  if (res.status >= 500 || res.status === 408 || res.status === 429) return null;
  return { valid: false, autoReply: false };
}
Enter fullscreen mode Exit fullscreen mode

That comment is the summary of an earlier post where our own rate limiter answered 429 and the app believed it meant "invalid". The list of statuses that mean "we do not know" was written from that incident: 500 and up, 408, 429.

403 is not on the list. An edge challenge never reaches the route, never looks a licence up, and never refuses one, and it would be recorded as valid: false. The whole point of the comment is that only a considered no counts as a no, and the sweep found a second status with exactly the shape the comment describes.

The fix is two edits, neither of them clever: add 403 to that list, and treat any response whose content-type is not JSON as unknown regardless of status, because a 25 KB HTML document is the server failing to answer the question rather than answering it badly.

The alert path has a smaller version of the same problem:

if (!res.ok) {
  const body = await res.text();
  throw new Error(`Server returned ${res.status}: ${body}`);
}
Enter fullscreen mode Exit fullscreen mode

res.text() on a challenge response is 25,153 characters of someone else's HTML, and that string goes into the error message and from there into the log file you are told to read when something goes wrong. An error body is worth logging when it is a sentence. Truncating it at a couple of hundred characters is the whole fix.

Takeaways

  • Prerendered and dynamically rendered pages do not agree about HTTP methods. A static route answers 405 for free; a dynamic one renders the page for any method, because the handler never looks at the verb.
  • If your framework writes your 405s, check whether they carry Allow. Ours do not, and nothing in the application has the information to add it.
  • OPTIONS is the method to probe first. It is the one most likely to be answered by infrastructure rather than your code, and the difference between 204 and a full document tells you which.
  • Any client that speaks to your own API can be challenged by your own edge, and a challenge is not a verdict. Make sure your client distinguishes "the server refused" from "the server never saw it", by content type as well as by status.
  • A sweep of a few hundred requests is enough to find out what your protection does. Run it against your own site, and expect to be in the penalty box for the rest of the afternoon.

The pages in the table are live if you want to try the harmless half yourself: the help page and the alerts hub answer 405, while pricing and download will hand you the whole document whatever you ask them. Please be gentler with it than I was.

Top comments (0)