[ 
https://issues.apache.org/jira/browse/HADOOP-20004?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18139274#comment-18139274
 ] 

ASF GitHub Bot commented on HADOOP-20004:
-----------------------------------------

joseluisll opened a new pull request, #8946:
URL: https://github.com/apache/hadoop/pull/8946

   ### Description of PR
   
   AuthenticationFilter, RestCsrfPreventionFilter and KMSAuthenticationFilter 
refuse a request with a message the caller acts on. That message travels in the 
reason phrase and in the error page sendError writes, but Jetty writes that 
page for GET, POST and HEAD only. A refusal of a PUT or a DELETE has nothing 
but the phrase, which HTTP/2 does not have and later Jetty releases do not send.
   
   The filters now mark their refusals with the new request attribute 
AuthenticationFilter.ERROR_MESSAGE_FOR_ANY_METHOD_ATTRIBUTE. HttpServer2 
installs ReasonBodyErrorHandler on its webapp, /logs and /static contexts, 
which writes the error page for a marked error whatever the method. It extends 
ErrorPageErrorHandler, so web.xml <error-page> mappings keep working, and 
unmarked errors get the answer they get today.
   
   The CSRF and KMS filters replace the cast to Jetty's Response and 
setStatusWithReason with the Servlet API's setStatus(int, String), which Jetty 
9.4 sends as the phrase. It also reaches the container through a response 
wrapper, where the cast did not. AuthenticationFilter already called it.
   
   TestRestCsrfPreventionFilter checks the phrase and the marker. 
TestHttpServer checks that a marked PUT or DELETE error has a body and an 
unmarked one does not.
   
   ### How was this patch tested?
   
   The changed modules' tests, run by the Yetus precommit and the fork's CI on 
this branch.
   
   ### For code changes:
   
   - [x] Does the title of this PR start with the corresponding JIRA issue id?
   - [ ] Object storage: not applicable, no object store integration touched.
   - [ ] If adding new dependencies to the code: not applicable, no new 
dependency.
   - [ ] If applicable, have you updated the LICENSE files: not applicable.
   
   ### AI Tooling
   
   If an AI tool was used:
   
   - [x] The PR includes the phrase "Contains content generated by <tool>" 
where <tool> is the name of the AI tool used.
   - [x] My use of AI contributions follows the ASF legal policy 
https://www.apache.org/legal/generative-tooling.html
   
   Contains content generated by Claude Code.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   




> Send a filter's refusal reason in the response body for every HTTP method
> -------------------------------------------------------------------------
>
>                 Key: HADOOP-20004
>                 URL: https://issues.apache.org/jira/browse/HADOOP-20004
>             Project: Hadoop Common
>          Issue Type: Sub-task
>          Components: common, hadoop-auth, kms, security
>            Reporter: Jose Luis López
>            Priority: Major
>
> {{AuthenticationFilter}}, {{RestCsrfPreventionFilter}} and 
> {{KMSAuthenticationFilter}} put their refusal message in the HTTP reason 
> phrase. The CSRF and KMS filters do it by casting to 
> {{org.eclipse.jetty.server.Response}} and calling {{setStatusWithReason}}. 
> Jetty writes an error-page body only for GET, POST and HEAD, on 9.4 and on 
> 12. So for a refused PUT or DELETE the phrase is the only place the message 
> appears, and Jetty 12 does not send one.
> h3. Changes
> * New request attribute 
> {{AuthenticationFilter.ERROR_MESSAGE_FOR_ANY_METHOD_ATTRIBUTE}} marks an 
> error whose message the caller must be able to read.
> * {{HttpServer2}} installs an error handler that writes the error page for a 
> marked error whatever the method. It extends {{ErrorPageErrorHandler}}, so 
> web.xml {{<error-page>}} mappings keep working. Unmarked errors are handled 
> exactly as today.
> * The three filters mark their refusals. In place of the Jetty cast they call 
> the Servlet API's {{setStatus(int, String)}}, so Jetty 9.4 and any other 
> container that sends a reason phrase still sends it. This also takes the 
> Jetty dependency out of filters that downstream projects run in their own 
> containers.
> h3. Compatibility
> The status code and the reason phrase are unchanged. A refused PUT or DELETE 
> now also has an error-page body.
> h3. Tests
> {{TestRestCsrfPreventionFilter}} checks the phrase and the marker. 
> {{TestHttpServer}} checks that a marked PUT error has a body and an unmarked 
> one does not.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to