Skip to content

fix ippeveprinter Host check accepting names that start with a digit - #225

Closed
tanjiroK-coder wants to merge 1 commit into
OpenPrinting:masterfrom
tanjiroK-coder:ippeveprinter-host-digit
Closed

tanjiroK-coder wants to merge 1 commit into
OpenPrinting:masterfrom
tanjiroK-coder:ippeveprinter-host-digit

Conversation

@tanjiroK-coder

Copy link
Copy Markdown
Contributor

process_http in tools/ippeveprinter.c rejects requests whose Host header is not the printer's hostname, localhost, a .local name or an IP address, which is what keeps a DNS-rebinding web page from talking to the printer through a victim's browser. The IP address case is detected by looking only at the first character, so any DNS name that starts with a digit is accepted: on current master Host: attacker.example gets 400 Bad Request while Host: 1.attacker.example and Host: 9evil.com get 200, for the web interface and for IPP requests alike. A page served from a name like 1.attacker.example that rebinds to the printer (or to 127.0.0.1) can therefore send IPP operations and read the responses, and Get-Printer-Attributes echoes the name back in printer-uri-supported and printer-more-info (ipp://1.attacker.example:8631/ipp/print). I reproduced it by running ippeveprinter -p 8631 and sending curl requests and a raw Get-Printer-Attributes request with each Host value. The fix keeps the numeric shortcut only when the whole value is digits and dots, which is how browsers send an IPv4 host, so IPv4 and bracketed IPv6 literals, localhost, the printer hostname and .local names behave as before while 1.attacker.example and 9evil.com now get 400. The vcnet build and run-tests.ps1 pass with the change.

@michaelrsweet michaelrsweet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This won't work since the Host:field can contain :port on the end...

@michaelrsweet

Copy link
Copy Markdown
Member

Actually, looking at the code closer it strips the trailing ":port", if present. But we still need to limit the numbers to exactly four sets of numbers from 0-255...

@michaelrsweet

Copy link
Copy Markdown
Member

Thought for a minute we'd be able to use the inet_addr function, but it allows CIDR (N, N.N, N.N.N) values.

@michaelrsweet

Copy link
Copy Markdown
Member

[master a9e7398] Fix IPv4 validation of Host: header (Issue #225)

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.

2 participants