Repository navigation
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An unknown HTTP method reaches
HttpMethodInterceptorand produces a 500.HttpMethod.parse()isvalueOf(method.toUpperCase())with no fallback, and the interceptor calls it with the raw request method for anyHttpMethodAwareaction — before the allow-checks, and with no try/catch:The enum has nine constants, so
PROPFIND,MKCOL,REPORTor any invented token raisesIllegalArgumentExceptioninstead of being treated as "not allowed". Whenhttp-methodis configured the code already knows how to answer that case — 405 with anAllowheader — it just never gets there.HttpMethod.parseOrNull()returnsnullfor an unrecognised method; the interceptor leaves the method unset and falls through to the existingisAllowed()check. Bothparse()andparseOrNull()usetoUpperCase(Locale.ROOT)— the bare call is locale-sensitive, andXmlDocConfigurationProvideralready usesLocale.ROOTfor the same lookup.Repro: any action with
http-methodset, requestPROPFIND /that-action→ 500 before, 405 +Allowafter.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:
WW-XXXXticket 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.SECURITY.md. If you would rather it went through security@struts.apache.org, close this and I will send it there instead.