Repository navigation
Fix Jetty security headers handler chain - #2676
Utkarsh-rwt wants to merge 9 commits into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Resolved the merge conflict while preserving both changes and ran the relevant test to verify the updates. |
|
@mattrpav , I fixed the spacing changes, please review it again |
| <Call name="addHandler"> | ||
| <Arg> | ||
| <Ref refid="Server"> | ||
| <Call name="insertHandler"> |
There was a problem hiding this comment.
Moving the RewriteHandler to the server level is right.
But it means the CSP (line 68) is now actually sent, which has a side effect. That policy sets script-src-elem 'self' and default-src 'none', with no script-src or script-src-attr. Inline event handlers fall back to default-src: 'none', so the browser blocks them.
The console still has three of them:
browse.jsp:64:onclick="return confirm('Are you sure you want to delete this message?')"browse.jsp:85: confirmation before retrying to the DLQ's target queuemessage.jsp:154: confirmation before Retry
When the onclick is blocked, the confirm dialog never appears and the link goes straight to deleteMessage.action / moveMessage.action / retryMessage.action.
So once this merges, Delete and Retry on a DLQ run without asking. Today they prompt.
Could you move these three handlers to external JS, the same way js/message.js already does for actionDelete?
Please don't loosen the CSP with unsafe-inline to get around it 😄
| HttpResponse<String> authenticatedResponse = client.send( | ||
| HttpRequest.newBuilder(URI.create("http://127.0.0.1:" + port + "/admin/")) | ||
| .header("Authorization", "Basic " + java.util.Base64.getEncoder().encodeToString( | ||
| "admin:admin".getBytes(StandardCharsets.ISO_8859_1))) | ||
| .GET().build(), | ||
| HttpResponse.BodyHandlers.ofString()); | ||
| assertEquals("SAMEORIGIN", authenticatedResponse.headers().firstValue("X-Frame-Options").orElse(null)); |
There was a problem hiding this comment.
This request never actually authenticates. The test resource have no JAAS configuration: there's no login.config, and neither java.security.auth.login.config nor activemq.conf is set.
JAASLoginService can't load the activemq login module, so this request gets a 401, just like the one above.
The assertion still passes because the RewriteHandler now runs before the SecurityHandler, which puts X-Frame-Options on the 401 too. So the authenticated path is not covered. The test would stay green even if headers were dropped from 200 responses.
I suggest the following changes:
- Add a test
login.configwith aactivemqentry that usesPropertiesLoginModule, plususers.propertiesandgroups.propertiesthat putadmininadmins(the role/admin/*requires). Pointjava.security.auth.login.configat it, either through surefiresystemPropertyVariablesor from the test itself. - Check the status before the header (the test webapp has an
index.html, so a 200 is expected):
assertEquals(200, authenticatedResponse.statusCode());
assertEquals("SAMEORIIGIN", authenticatedResponse.headers().firstValue("X-Frame-Options").orElse(null));
- Wrap up the test body in
try { ... } finally { context.close(); }. If this assertion fails,context.stop()is skipped and Jetty stays running into the next test. Even when it isn't skipped,stop()does't callJettyServerBean.destroy(). Onlyclose()does.
Nit: java.util.Base64 is written out in full inline, while StandardCharsets gets an import.
Description
Fix the missing HTTP security headers in the ActiveMQ web console following the migration to Jetty 12 / EE11.
The
RewriteHandlerwas configured as a sibling of the/adminand/apiweb application contexts insideContextHandlerCollection. As a result, requests could reach these contexts without passing through the rewrite rules responsible for adding the configured security headers.This change inserts the
RewriteHandlerinto the server's handler chain so that it wraps the context collection and processes requests before they reach the web applications.Changes Made
assembly/src/release/conf/jetty/jetty-webapps.xmlto insert theRewriteHandlerinto the server's handler chain usingServer.insertHandler(...).activemq-web-console/src/test/resources/jetty/jetty-webapps.xmlto keep the integration test environment consistent with production.JettyServerBeanTestto make an authenticated request to/admin/and verify that the response containsX-Frame-Options: SAMEORIGIN.Testing
The following validations were performed:
xmllintvalidation.git diff --checkcompleted without errors.Test command:
mvn -pl activemq-web-console -am \ -Dtest=JettyServerBeanTest \ -Dsurefire.failIfNoSpecifiedTests=false \ testResult:
BUILD SUCCESSScreenshots
Regression test / test execution
HTTP response headers
Related Issue
Closes #2659