Skip to content

Fix Jetty security headers handler chain - #2676

Closed
Utkarsh-rwt wants to merge 9 commits into
apache:mainfrom
Utkarsh-rwt:fix/jetty12-security-headers
Closed

Utkarsh-rwt wants to merge 9 commits into
apache:mainfrom
Utkarsh-rwt:fix/jetty12-security-headers

Conversation

@Utkarsh-rwt

Copy link
Copy Markdown

Description

Fix the missing HTTP security headers in the ActiveMQ web console following the migration to Jetty 12 / EE11.

The RewriteHandler was configured as a sibling of the /admin and /api web application contexts inside ContextHandlerCollection. 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 RewriteHandler into the server's handler chain so that it wraps the context collection and processes requests before they reach the web applications.

Changes Made

  • Updated assembly/src/release/conf/jetty/jetty-webapps.xml to insert the RewriteHandler into the server's handler chain using Server.insertHandler(...).
  • Applied the same handler configuration change to activemq-web-console/src/test/resources/jetty/jetty-webapps.xml to keep the integration test environment consistent with production.
  • Extended JettyServerBeanTest to make an authenticated request to /admin/ and verify that the response contains X-Frame-Options: SAMEORIGIN.
  • Preserved the existing security header values and authentication behavior.

Testing

The following validations were performed:

  • Focused Maven test completed successfully.
  • Both modified XML configuration files passed xmllint validation.
  • git diff --check completed without errors.

Test command:

mvn -pl activemq-web-console -am \
    -Dtest=JettyServerBeanTest \
    -Dsurefire.failIfNoSpecifiedTests=false \
    test

Result: BUILD SUCCESS

Screenshots

Regression test / test execution

Regression test execution

HTTP response headers

HTTP response headers

Related Issue

Closes #2659

Utkarsh-rwt and others added 2 commits October 16, 2026 14:28
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Utkarsh-rwt

Copy link
Copy Markdown
Author

Resolved the merge conflict while preserving both changes and ran the relevant test to verify the updates.

@Utkarsh-rwt

Utkarsh-rwt commented Oct 16, 2026 •

Copy link
Copy Markdown
Author

@mattrpav , I fixed the spacing changes, please review it again

@jbonofre
jbonofre self-requested a review October 19, 2026 04:51
<Call name="addHandler">
<Arg>
<Ref refid="Server">
<Call name="insertHandler">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 queue
  • message.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 😄

Comment on lines +59 to +65
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));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Add a test login.config with a activemq entry that uses PropertiesLoginModule, plus users.properties and groups.properties that put admin in admins (the role /admin/* requires). Point java.security.auth.login.config at it, either through surefire systemPropertyVariables or from the test itself.
  2. 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));
  1. 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 call JettyServerBean.destroy(). Only close() does.

Nit: java.util.Base64 is written out in full inline, while StandardCharsets gets an import.

@mattrpav mattrpav moved this from Backlog to In progress in Apache ActiveMQ v6.4.0 Oct 20, 2026
@mattrpav mattrpav moved this from In progress to In review in Apache ActiveMQ v6.4.0 Oct 20, 2026
@Utkarsh-rwt Utkarsh-rwt closed this by deleting the head repository Oct 24, 2026
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.

Web console security headers are not sent (RewriteHandler in jetty-webapps.xml never wraps the webapps)

3 participants