Skip to content

Fix false duplicate-Host detection from Bloom filter collisions - #1975

Open
abu-tahir-0 wants to merge 1 commit into
uNetworking:masterfrom
abu-tahir-0:fix/1967-host-dup-collision
Open

abu-tahir-0 wants to merge 1 commit into
uNetworking:masterfrom
abu-tahir-0:fix/1967-host-dup-collision

Conversation

@abu-tahir-0

Copy link
Copy Markdown

Fixes #1967

The parser's duplicate-header detection for Host consults a Bloom filter of header names. A Bloom collision — for example hxsst appearing before Host — was treated as a duplicate Host and the request was rejected with err=3.

Change

After the Bloom filter reports a possible duplicate, confirm against the actual stored header names before rejecting, so collisions no longer cause false positives while genuine duplicate Host headers are still rejected.

Tests

  • New cases in tests/HttpParser.cpp: a colliding header before Host is accepted, the reverse ordering is accepted, and an actual duplicate Host is still rejected.
  • Baseline (new tests only): fails with err=3 for the collision ordering.
  • Patched: the complete HttpParser test executable passes in the Docker build.

The duplicate-header check trusted the header-name Bloom filter, so a
collision (e.g. "hxsst" followed by "Host") was rejected as a duplicate.
Confirm duplicates against the actual stored header names.
Comment thread src/HttpParser.h
bool seenHost = false;
for (HttpRequest::Header *h = req->headers; (++h)->key.length(); ) {
if (req->bf.mightHave(h->key)) [[unlikely]] {
if (h->key == "host") [[unlikely]] {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check needs to be faster. I'm not sure comparison with C-string is fast in the false case. If you do it like h->key == std::string_view("host", 4) I guess it's guaranteed to be fast since it knows the size always. Maybe even add if (h->key.length() == 4 && .....) to be sure.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Host header dup check false positive

2 participants