Skip to content

Normalize hop-by-hop header parsing per RFC 9110 OWS rules in HTTPProxyServer - #232

Open
oyesanyf wants to merge 1 commit into
ruby:masterfrom
oyesanyf:rfc9110-hop-by-hop-cleanup
Open

oyesanyf wants to merge 1 commit into
ruby:masterfrom
oyesanyf:rfc9110-hop-by-hop-cleanup

Conversation

@oyesanyf

Copy link
Copy Markdown

Summary

This PR updates HTTPProxyServer#split_field in lib/webrick/httpproxy.rb to conform with RFC 9110 §5.6.1.2 and §7.6.1 optional whitespace (OWS) rules.

Context & Motivation

In WEBrick::HTTPProxyServer, hop-by-hop headers listed in the Connection header (or related fields) are extracted via split_field:

def split_field(f) f ? f.split(/,\s+/).collect{|i| i.downcase } : [] end

The regex ,\s+ required at least one whitespace character after each comma. Under RFC 9110 (and earlier RFC 7230 §3.2.2), comma-separated list syntax allows optional whitespace before and after commas:

  • Connection: close,keep-alive (zero whitespace)
  • Connection: close , keep-alive (whitespace before comma)
  • Connection: close\t,\tkeep-alive (tab characters)

When an intermediary or client sends Connection: close,keep-alive without spaces, split_field would fail to tokenize the header into individual tokens, leaving "close,keep-alive" as an unseparated token and preventing matching hop-by-hop headers from being stripped.

Changes

  • Updated split_field to split on commas (','), strip leading and trailing whitespace on each token (.strip.downcase), and reject empty elements.
  • Added unit tests in test/webrick/test_httpproxy.rb covering standard whitespace variants (tabs, spaces before/after, zero spaces, trailing commas).

Previously, HTTPProxyServer#split_field used f.split(/,\s+/), which
assumed at least one space character after each comma. Under RFC 9110
Section 5.6.1.2 and Section 7.6.1, comma-separated list values allow
optional whitespace (OWS = *( SP / HTAB )) before and after the comma,
including zero whitespace (e.g. 'Connection: close,keep-alive') or
spaces before commas ('Connection: close , keep-alive').

This change splits on commas directly, strips surrounding whitespace,
and discards empty tokens, correctly normalizing all compliant
hop-by-hop header tokens.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant