Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] deny access based on user agent

The built-in rules do not generally respond with an error.
Most of them just modify paths or headers.

The exceptions to the above statement would be.
* `InvalidURIRule` - if the URI has invalid characters, it's rejected with a 400 response status.
* `ResponsePatternRule` - if the target path is of the specified pattern, then a configurable status code is returned.

For a rule that acts on a request header, and then performs a response with configurable status, none exists in Jetty at this point in time.
Surprisingly you are the first one to ask for it.
At this point in time, if you need it, then it would be a custom rule and/or handler.

If you want to see what it would look like, check out the rewrite example.
https://github.com/jetty/jetty-examples/tree/12.0.x/embedded/rewrite

The specific example https://github.com/jetty/jetty-examples/blob/12.0.x/embedded/rewrite/src/main/java/examples/RejectUserAgentRuleExample.java

On Tue, Aug 13, 2024 at 6:45 PM Paul B. Henson via jetty-users <jetty-users@xxxxxxxxxxx> wrote:
There's a broken web crawler ignoring the site robots.txt which is
pounding a webapp I'm running under jetty and generating a ton of noise
in the application logs.

I'd like to deny access to it based on user agent, as it is consistently
identifying itself at least.

What is the best way to do that with jetty? With Apache, I could use a
rewrite rule to match against the user agent and return a 403.

I don't initially see a similar way to do that with jetty's rewrite
engine; the ResponsePatternRule appears to allow overriding a specific
response code, but it looks like you can only look at the URL to match
against, not headers like the user agent?

There is a HeaderRule that looks like it would match against the user
agent header, but it is marked as abstract.

The Apache syntax would simply be:

        RewriteCond %{HTTP_USER_AGENT} "=blackboardally"
        RewriteRule ^ - [F]

Am I missing a way to do this with jetty rewrite? Or is there an
alternative module/mechanism that could accomplish this?

Thanks much…
_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jetty-users

Back to the top