java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.ContainerLifeCycle
org.eclipse.jetty.server.handler.AbstractHandler
org.klomp.snark.standalone.HostCheckHandler
- All Implemented Interfaces:
Handler, Container, Destroyable, Dumpable, LifeCycle
Block certain Host headers to prevent DNS rebinding attacks.
Unlike in the console, this is an AbstractHandler, not a HandlerWrapper.
Nested Class Summary
Nested classes/interfaces inherited from class AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListenerNested classes/interfaces inherited from interface Container
Container.InheritedListener, Container.ListenerNested classes/interfaces inherited from interface LifeCycle
LifeCycle.ListenerField Summary
FieldsModifier and TypeFieldDescriptionprivate final I2PAppContextSupplies the configuration and the log.Host names the service will answer for.private static final StringProperty listing the hosts that may use the service.Fields inherited from class AbstractLifeCycle
FAILED, RUNNING, STARTED, STARTING, STOP_ON_FAILURE, STOPPED, STOPPINGConstructor Summary
ConstructorsConstructorDescriptionCreates a new HostCheckHandler using the global I2P application context.Creates a new HostCheckHandler with the specified application context.Method Summary
Modifier and TypeMethodDescriptionprivate booleanShould we allow a request with this Host header?private static StringStrip [] and port from a host header.voidhandle(String pathInContext, Request baseRequest, HttpServletRequest httpRequest, HttpServletResponse httpResponse) Block by Host header, redirect HTTP to HTTPS, pass everything else to the delegate.voidsetListenHosts(Set<String> hosts) Unused, we can't get here fromRunStandalone.Methods inherited from class AbstractHandler
destroy, doStart, doStop, dumpThis, getServer, setServerMethods inherited from class ContainerLifeCycle
addBean, addBean, addBean, addEventListener, addManaged, contains, dump, dump, dump, dump, dump, dumpBeans, dumpObject, dumpStdErr, getBean, getBeans, getBeans, isManaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeansMethods inherited from class AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
Field Details
_context
Supplies the configuration and the log._listenHosts
PROP_ALLOWED_HOSTS
Property listing the hosts that may use the service.- See Also:
Constructor Details
HostCheckHandler
public HostCheckHandler()Creates a new HostCheckHandler using the global I2P application context.HostCheckHandler
Creates a new HostCheckHandler with the specified application context.- Parameters:
ctx- the I2P application context
Method Details
setListenHosts
Unused, we can't get here fromRunStandalone.- Parameters:
hosts- contains hostnames or IPs. But we allow all IPs anyway.
handle
public void handle(String pathInContext, Request baseRequest, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException Block by Host header, redirect HTTP to HTTPS, pass everything else to the delegate.- Throws:
IOExceptionServletException
allowHost
Should we allow a request with this Host header?ref: https://en.wikipedia.org/wiki/DNS_rebinding
- Parameters:
host- the HTTP Host header, null ok- Returns:
- true if OK
getHost