Konstantin,

On 4/16/24 13:16, Konstantin Kolinko wrote:
вт, 16 апр. 2024 г. в 18:17, Christopher Schultz <ch...@christopherschultz.net>:

All,

I'm not sure if this is the first time I've tried something like this,
but I was surprised by the behavior I observed today when trying to
configure a new Filter.

I have an existing Filter that looks at Cookies provided in a request.

I wanted to add a new Filter that takes request parameters and returns
them from request.getCookies() but only for a small number of URL
patterns which we handle only internally, both for security (?) and also
for performance, since this isn't a really common thing for us to do.

So I have these two filters:

<filter>
    <filter-name>cookieUserFilter</filter-name>
    <filter-class>...</filter-class>
</filter>

<filter>
    <filter-name>cookieParameterFilter</filter-name>
    <filter-class>...</filter-class>
</filter>

<filter-mapping>
    <filter-name>cookieParameterFilter</filter-name>
    <url-pattern>*.xml.do</url-pattern>
    <url-pattern>/some/specific/pattern</url-pattern>
<filter-pattern>

<filter-mapping>
    <filter-name>cookieUserFilter</filter-name>
    <url-pattern>*.do</url-pattern>
    <url-pattern>*.jsp</url-pattern>
<filter-pattern>

I have tested that both Filters work as expected when called. However,
when I configure them as above and request /foo.xml.do, only the
cookieUserFilter is being called. The cookieParameterFilter is not being
called.
[...]

What am I missing?

This is Tomcat 9.0.85 and everything is defined in WEB-INF/web.xml.

Hi, Chris!

The Servlet 4.0 specification (the one that applies to Tomcat 9) says:

1) ch. 12.2 Specification of Mappings

"A string beginning with a ‘ *. ’ prefix is used as an extension mapping."

searching for "extension" finds:
2) ch 12.1  Use of URL Paths

"3. If the last segment in the URL path contains an extension (e.g.
.jsp), the servlet
container will try to match a servlet that handles requests for the
extension. An
extension is defined as the part of the last segment after the last ’
. ’ character."

As it says "after the last '.' character" then by this design
<url-pattern>*.xml.do</url-pattern> cannot match anything.

Aw. I suppose anything else would be terrible for performance.

So the problem is that I was specifying an "extension" mapping that is not legal. I don't see anything in the log files, but this seems like a good thing to log. I'll check to see if such a thing could be added.

I now have two options:

1. Specify every individual url-pattern that I want to support (which is easy: there are a very small number of them)

2. Abort this stupid idea and do something else

I've already opted for #2 anyway because it's less-stupid than trying to use request parameters as a proxy for cookies. It also solves like 2 other problems at the same time, so I like my other solution better.

(You may look at how o.a.catalina.mapper.Mapper actually works.

Look for extensionWrappers and method internalMapExtensionWrapper().)

Thanks for the pointer.

-chris

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to