public class RequestValidator extends Object
This class encapsulates all request validation logic for I2PTunnelHTTPServer, including hostname validation (detecting attempts to access localhost/loopback), inproxy rejection, referer validation, and user-agent filtering.
Validations are performed based on configuration options set in the tunnel's client options properties.
| Modifier and Type | Class and Description |
|---|---|
static class |
RequestValidator.ValidationResult
Encapsulates the result of hostname validation.
|
| Constructor and Description |
|---|
RequestValidator(Log log,
String peerB32,
Properties opts,
BlocklistManager blocklistManager)
Creates a new RequestValidator.
|
| Modifier and Type | Method and Description |
|---|---|
String |
buildInproxyRejectLog(Map<String,List<String>> headers)
Builds a detailed log message for inproxy rejection.
|
String |
getRefererForLog(Map<String,List<String>> headers)
Extracts the referer URL for logging purposes.
|
String |
getUserAgentForCheck(Map<String,List<String>> headers)
Extracts the user agent for blacklisting checks.
|
boolean |
shouldRejectInproxy(Map<String,List<String>> headers)
Checks if the request should be rejected based on inproxy headers.
|
boolean |
shouldRejectReferer(Map<String,List<String>> headers)
Checks if the request should be rejected based on referer header.
|
boolean |
shouldRejectUserAgent(Map<String,List<String>> headers)
Checks if the request should be rejected based on user-agent header.
|
RequestValidator.ValidationResult |
validateHostname(String hostname,
StringBuilder command)
Validates a hostname from an HTTP request.
|
public RequestValidator(Log log, String peerB32, Properties opts, BlocklistManager blocklistManager)
log - the Log instance for logging validation eventspeerB32 - the Base32-encoded peer destination for loggingopts - the tunnel client options for validation configurationblocklistManager - the BlocklistManager for logging blocked destinations; may be nullpublic String buildInproxyRejectLog(Map<String,List<String>> headers)
This method extracts all relevant headers for logging purposes when an inproxy request is rejected.
headers - the HTTP request headerspublic String getRefererForLog(Map<String,List<String>> headers)
Strips the "Referer: " prefix from the header value.
headers - the HTTP request headerspublic String getUserAgentForCheck(Map<String,List<String>> headers)
headers - the HTTP request headerspublic boolean shouldRejectInproxy(Map<String,List<String>> headers)
When the OPT_REJECT_INPROXY option is enabled, requests containing X-Forwarded-For, X-Forwarded-Server, Forwarded, or X-Forwarded-Host headers are rejected to prevent proxy abuse.
headers - the HTTP request headerspublic boolean shouldRejectReferer(Map<String,List<String>> headers)
When the OPT_REJECT_REFERER option is enabled, requests with absolute URIs (starting with http:// or https://) in the Referer header are rejected to prevent information leakage.
headers - the HTTP request headerspublic boolean shouldRejectUserAgent(Map<String,List<String>> headers)
When the OPT_REJECT_USER_AGENTS option is enabled, requests with blacklisted user agents are rejected. The blacklist is configured via the OPT_USER_AGENTS option as a comma-separated list.
A special case is made for user agents starting with "MYOB" which are always allowed. Also, if the blacklist contains "none", requests without a User-Agent header are rejected.
headers - the HTTP request headerspublic RequestValidator.ValidationResult validateHostname(String hostname, StringBuilder command)
This method checks for several security issues:
Valid hostnames ending in .i2p or .onion are passed through without validation, as these are expected I2P/eepSite or Tor addresses.
hostname - the Host header value from the request; may be nullcommand - the full request command for blocklist checking