Forum Discussion
Host Header Validation
- Jul 28, 2016
A data-group is a convenience rather than a necessity.
I tried the following on 11.5.4:
when HTTP_REQUEST { if { [HTTP::host] ne "xyz.com" } { reject } }
I tried all of the following combinations:
- HTTP/1.1 Host header xyz.com;
- HTTP/1.1 Host header foo.com;
- HTTP/1.0 no Host header;
- HTTP/1.1 Host header xyz.com followed by HTTP/1.0 no Host header;
- HTTP/1.1 Host header xyz.com followed by HTTP/1.1 Host header foo.com
Case 1: allowed;
Case 2: rejected (i.e., TCP RST);
Case 3: rejected;
Case 4: allowed then rejected;
Case 5: allowed then rejected.
Incidentally, if a pool is assigned to the VS, then the else clause isn't needed (it's the default anyway).
Having said all of that, your issue may be relate to this note, found in the reject explanation:
Subsequent code in the current event in the current iRule or other iRules on the VS are still executed prior to the reset being sent.
I recommend putting a return after the reject.
You need an datagroup that is essentially a whitelist. Host headers are user submitted, so the user can manipulate what is sent in. Try something like this..
datagroup would be a string type and would contain something like this:
www.example.com := www.example.com_pool
when HTTP_REQUEST {
set hostpool [class match -value [string tolower [HTTP::host]] equals datagroup_name
if { $hostpool ne "" } {
pool $hostpool
HTTP::header replace Host [HTTP::host]
} else {
discard
}
}
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com