@Override
    protected Optional<ErrorResponse> filter(DiscFilterRequest request) {
        InetAddress remoteAddr = InetAddresses.forString(request.getRemoteAddr());
        if (!remoteAddr.isLoopbackAddress() && !request.getRemoteAddr().equals(request.getLocalAddr())) {
            return Optional.of(new ErrorResponse(
                    Response.Status.UNAUTHORIZED,
                    String.format("%s %s denied for %s: Unauthorized host", request.getMethod(),
                                  request.getUri().getPath(), request.getRemoteAddr())));
        }
        return Optional.empty();
    }
A security filter that only allows self-originating requests.

@author mpolden
@author bjorncs
jdisc-security-filters/src/main/java/com/yahoo/jdisc/http/filter/security/misc/LocalhostFilter.java