Platform · Search · Input Validation

When a Product Review Becomes a Search Query

Search was failing on one brand site, and the logs were full of a server error I'd never expected from a search box: 414, Request-URI Too Large. Someone's "search term" was an entire product review.

An error you don't expect from a search box

While digging into intermittent search problems, I found a pattern in the application logs: search requests failing with HTTP 414, Request-URI Too Large. That error means the URL itself was too long for the server to accept.

Search URLs aren't supposed to be long. You type a few words, the site asks the search service for suggestions, done. So what was making them huge?

Reading the actual request

The logged request answered it. The search term wasn't a few words. It was a full, marketplace-style product review, star rating and all, pasted into the search box (or sent there by a bot). Every word of it got packed into the URL of a GET request to the hosted search service.

The search service's front-end proxy has a limit on how long a URL can be. This one blew right past it, so the proxy rejected the request before the search engine ever saw it. The site's suggestion feature then failed instead of quietly returning nothing.

Visitor (or bot) pastes a whole review into search
        ↓
Site builds a GET request with the full text in the URL
        ↓
Search service's proxy: URL too long → 414
        ↓
Suggestion feature throws an error instead of returning nothing

Why this is really an input validation story

Nothing was wrong with the search service. It was doing exactly what it should do with an oversized request. The gap was on our side: the site passed whatever it received straight through, with no limit on length.

That's the same lesson as every "never trust user input" talk, just showing up as a reliability problem instead of a security one. Input you don't limit eventually becomes input that breaks something.

What I recommended

The fix we worked out was a length limit in two places. In the browser, cap the search box so normal visitors never send something absurd. On the server, enforce the limit again, because a browser limit does nothing against a bot or a hand-crafted request. We talked about a cap in the range of 100 to 150 characters, which is far longer than any real product search.

A server-side guard can be very small:

// Illustrative: cap the term before it ever reaches the search service
const int MaxSearchLength = 150;

if (!string.IsNullOrWhiteSpace(searchTerm) && searchTerm.Length > MaxSearchLength)
{
    searchTerm = searchTerm.Substring(0, MaxSearchLength);
}

Where it stands

To be clear about what I can and can't claim: I diagnosed the cause and recommended the fix. I don't have confirmation of when, or whether, the length limit was deployed, so I'm not going to tell you the errors went to zero.

The investigation is still the useful part. A confusing, intermittent search failure turned into one specific request, one specific limit, and a small, testable fix.

What I took away

  • Read the actual failing request. The answer was sitting right there in the URL.
  • An error from a downstream service doesn't mean that service is broken.
  • Validate input length on the server, not just in the browser.
  • Features that fail loudly on bad input should usually fail quietly instead.
  • Be precise about the difference between "diagnosed" and "fixed."