Re: Unexpected behavior of filters

2024-04-16 Thread Konstantin Kolinko
вт, 16 апр. 2024 г. в 22:42, Christopher Schultz :
>
> [...]
>
> 2. Abort this stupid idea and do something else

URLs that end with ".do" always remind me about this old page:

https://www.w3.org/Provider/Style/URI
Cool URIs don't change
(c)1998 Tim BL

Though you might have already seen it.

Best regards,
Konstantin Kolinko

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



Re: Unexpected behavior of filters

2024-04-16 Thread Christopher Schultz

Konstantin,

On 4/16/24 13:16, Konstantin Kolinko wrote:

вт, 16 апр. 2024 г. в 18:17, Christopher Schultz :


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:


cookieUserFilter
...



cookieParameterFilter
...



cookieParameterFilter
*.xml.do
/some/specific/pattern



cookieUserFilter
*.do
*.jsp


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
*.xml.do 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



Re: Unexpected behavior of filters

2024-04-16 Thread Konstantin Kolinko
вт, 16 апр. 2024 г. в 18:17, Christopher Schultz :
>
> 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:
>
> 
>cookieUserFilter
>...
> 
>
> 
>cookieParameterFilter
>...
> 
>
> 
>cookieParameterFilter
>*.xml.do
>/some/specific/pattern
> 
>
> 
>cookieUserFilter
>*.do
>*.jsp
> 
>
> 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
*.xml.do cannot match anything.

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

Look for extensionWrappers and method internalMapExtensionWrapper().)

Best regards,
Konstantin Kolinko

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



Unexpected behavior of filters

2024-04-16 Thread Christopher Schultz

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:


  cookieUserFilter
  ...



  cookieParameterFilter
  ...



  cookieParameterFilter
  *.xml.do
  /some/specific/pattern



  cookieUserFilter
  *.do
  *.jsp


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. I'm explicitly defining them in that order to ensure that the 
cookieParameterFilter is called /first/ to ensure that the parameters 
are converted into Cookies before the cookieUserFilter is called.


In order to get the cookieParameterFilter to be called, I have to 
configure it like this in my filter-mapping:



  cookieParameterFilter
  *.do
  *.xml.do

  /some/specific/pattern


This means it will apply to all requests, which isn't what I want.

The only thing I can think of is that *.xml.do isn't mapped to any 
specific servlet, while *.do /is/. Will s only apply to URL 
patterns that are explicitly-mapped to a specific servlet?


That doesn't sound right to me. I have other mappings that only map to a 
URL space and not anything that has a specific servlet mapping.


What am I missing?

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

-chris

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