[mgt] For 4.3.4 - Drop unsafe-eval and unsafe-inline from the management UI Content Security Policy#16916
Merged
Conversation
MarcialRosales
marked this pull request as ready for review
July 14, 2026 08:39
|
Tick the box to add this pull request to the merge queue (same as
|
michaelklishin
added a commit
that referenced
this pull request
Jul 15, 2026
while at it, fix a subtle event propagation bug that only affects this branch.
michaelklishin
added a commit
that referenced
this pull request
Jul 15, 2026
michaelklishin
approved these changes
Jul 15, 2026
michaelklishin
left a comment
Collaborator
There was a problem hiding this comment.
@MarcialRosales I have fixed a subtle bug and improved Selenium test coverage for these templates.
Please take a look.
Contributor
Author
|
@michaelklishin nice changes ! specially the suggested changes to the selenium tests around feature flags. |
MarcialRosales
pushed a commit
that referenced
this pull request
Jul 16, 2026
while at it, fix a subtle event propagation bug that only affects this branch.
MarcialRosales
pushed a commit
that referenced
this pull request
Jul 16, 2026
Relax security requirements for inline event handlers until we refactor all the handlers
while at it, fix a subtle event propagation bug that only affects this branch.
Collaborator
|
@MarcialRosales I have rebased on top of Note that we can only backport these changes after |
Contributor
Author
|
@michaelklishin i am happy with the current state. I have added to the title "For 4.3.4". |
michaelklishin
approved these changes
Jul 20, 2026
6 tasks
michaelklishin
added a commit
that referenced
this pull request
Jul 20, 2026
michaelklishin
added a commit
that referenced
this pull request
Jul 20, 2026
[mgt] For 4.3.4 - Drop unsafe-eval and unsafe-inline from the management UI Content Security Policy (backport #16916)
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.
Motivation
This is a security improvement that removes two CSP directives:
unsafe-inlineand
unsafe-eval.Removing
unsafe-inlinewas straightforward: any inline<script>block inindex.htmlwas moved to a dedicated external JavaScript file. Also, we have to remove all the inline event handlers in overview, queues, feature-flags and oauth2.Removing
unsafe-evalrequired deeper changes. The management UI relies on theEJS 1.0 template engine, which — at runtime — fetches each
.ejsfile from theserver via XHR, then compiles it using JavaScript's
eval()to produce thefunction that renders the HTML. As long as that runtime compilation step
existed,
unsafe-evalcould not be removed from the CSP.Proposed Changes
All
.ejstemplates for a given plugin are compiled to JavaScript at buildtime and bundled into a single
<plugin>-ejs.jsfile (e.g.management-ejs.jsforrabbitmq_management,stream_management-ejs.jsforrabbitmq_stream_management).The management plugin's own bundle is loaded as a static
<script>tag inindex.htmlbecause it contains the core templates required before login. Allother plugins register their bundle via the
web_ui/0callback so it is loadedas an extension after a successful login.
Build-time compilation
The
.ejs→.jsconversion is performed by an Erlang escript(
scripts/precompile_ejs_templates). Using an escript keeps the builddependency-free for the majority of developers, who only need the Erlang
runtime that is already required to build and run the broker.
For developers who also have Node.js available (typically those working on the
management UI), the Makefile automatically runs a sanity check after
compilation: it compiles the same templates using the original EJS 1.0
JavaScript compiler and verifies that both renderers produce identical output.
Working on templates
After modifying a
.ejsfile, run the following to regenerate the JavaScriptbundle and reload the management UI in the browser:
The complete developer workflow and the limitations of the sanity check are
documented in
deps/rabbitmq_management/mk/rabbitmq-management-plugin.mk.Creating new UI components or updating existing ones
We cannot use inline event handlers. They will not work based on the default CSP directive. We have to register the events programmatically.
Benefits
Fewer network round-trips. Instead of up to 77 individual XHR requests
(one per
.ejsfile, issued lazily as the user navigates), the browserdownloads at most 6 script files — one per plugin — all via
<script>tagsor the extension mechanism.
Lower bandwidth. The 6 bundles transferred gzip-compressed total 49 KB,
versus 63 KB for the 77 individually-compressed
.ejsfiles. The savingcomes from gzip's ability to exploit repetition across a larger input.
Additionally,
ejs-1.0.min.jsis no longer loaded at runtime; it has beenreplaced by a small shim (
ejs-runtime.js) that provides only theEJS.Scanner.to_texthelper still referenced by the compiled templates.Stronger CSP. Eliminating runtime template compilation removes the need
for both
unsafe-evalandunsafe-inline, resulting in a stricterContent Security Policy.
Less work at startup. The browser no longer fetches a large number of
small template files on first use, nor compiles them before rendering.
Templates are available as plain JavaScript functions from the moment the
script is parsed.
Earlier error detection. Structural template errors (malformed EJS
delimiters, JavaScript syntax errors inside code blocks) are caught at build
time rather than at runtime. Errors that depend on real data or on helper
functions defined elsewhere in the UI are caught by the Selenium test suite.
Types of Changes
What types of changes does your code introduce to this project?
Put an
xin the boxes that apply