Skip to content

Handle an unknown HTTP method instead of raising IllegalArgumentException - #2043

Open
M0nd0R wants to merge 1 commit into
apache:mainfrom
M0nd0R:httpmethod-unknown-method-500
Open

M0nd0R wants to merge 1 commit into
apache:mainfrom
M0nd0R:httpmethod-unknown-method-500

Conversation

@M0nd0R

@M0nd0R M0nd0R commented Oct 19, 2026

Copy link
Copy Markdown

An unknown HTTP method reaches HttpMethodInterceptor and produces a 500.

HttpMethod.parse() is valueOf(method.toUpperCase()) with no fallback, and the interceptor calls it with the raw request method for any HttpMethodAware action — before the allow-checks, and with no try/catch:

HttpMethod method = HttpMethod.parse(request.getMethod());

The enum has nine constants, so PROPFIND, MKCOL, REPORT or any invented token raises IllegalArgumentException instead of being treated as "not allowed". When http-method is configured the code already knows how to answer that case — 405 with an Allow header — it just never gets there.

HttpMethod.parseOrNull() returns null for an unrecognised method; the interceptor leaves the method unset and falls through to the existing isAllowed() check. Both parse() and parseOrNull() use toUpperCase(Locale.ROOT) — the bare call is locale-sensitive, and XmlDocConfigurationProvider already uses Locale.ROOT for the same lookup.

Repro: any action with http-method set, request PROPFIND /that-action → 500 before, 405 + Allow after.

Tests: four added to HttpMethodTest. mvn -pl core -Dtest=HttpMethodTest test → BUILD SUCCESS, 6 tests, 0 failures (JDK 21).

Two process notes, so you can redirect me:

  • There is no WW-XXXX ticket for this yet, and the contributing guide requires one. Tell me the key to use and I will update the title and commit message to match.
  • This is an error-handling bug rather than a vulnerability in the sense of SECURITY.md. If you would rather it went through security@struts.apache.org, close this and I will send it there instead.

HttpMethodInterceptor calls HttpMethod.parse() with the request method for
any action implementing HttpMethodAware. HttpMethod is an enum whose parse()
is valueOf(method.toUpperCase()) with no fallback, and the interceptor has no
try/catch, so any method outside its nine constants - PROPFIND, MKCOL,
REPORT, or any invented token - raises IllegalArgumentException before the
allow-checks run and reaches the client as a 500.

Add HttpMethod.parseOrNull(), a total function returning null for an
unrecognised method, and use it in the interceptor, leaving the method unset
so the request falls through to the existing isAllowed() check. With
http-method configured that answers 405 with an Allow header, which is the
response the code already produces for a disallowed method.

Both parse() and parseOrNull() also use toUpperCase(Locale.ROOT); the bare
call is locale-sensitive, and XmlDocConfigurationProvider already uses
Locale.ROOT for the same lookup.

Tests added to HttpMethodTest.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant