Skip to content

fix(console): serve the pages under a Content-Security-Policy that runs no inline script - #1325

Merged
LeeroyHannigan merged 1 commit into
mainfrom
fix/706-console-csp
Dec 4, 2026
Merged

LeeroyHannigan merged 1 commit into
mainfrom
fix/706-console-csp

Conversation

@LeeroyHannigan

Copy link
Copy Markdown
Collaborator

What

The console's HTML responses now carry this Content-Security-Policy:

default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self'; base-uri 'none'; form-action 'self'; frame-ancestors 'none'

The browser runs scripts only from the server's own origin. An inline script, an event handler attribute or a javascript: URL does not run.

  • html_policy in crates/server/src/console/mod.rs gives the header to a response whose media type is text/html, in any case. A script, JSON, PDF or redirect response gets no policy.
  • start_server sets it with a SetResponseHeaderLayer where it nests the console router. The layer covers every route that the console router holds at that point.
  • The console's inline scripts move into two files. Two new routes serve them from /console/assets/ as text/javascript; charset=utf-8 with Cache-Control: no-cache, and need no session.
    • console.js adds the CSRF field to POST forms (from html.rs) and hides the fields of the other scopes on the cache page (from cache_pages.rs). It also asks the question of each delete form.
    • metrics.js holds the dashboard script from metrics_content.rs. Apart from the header comment, its one new line reads the data plane operations from the data-ops attribute of its script tag.
  • The eight delete forms put their question in a data-confirm attribute. They delete an account, a user, an access key, a group, a role, or an inline policy of a user, a group or a role. Before, an inline onsubmit handler asked the question.
  • The three window links of the metrics page use href="#" in place of javascript:void(0).
  • docs/manuals/10-security-model.md and docs/manuals/01-architecture-guide.md state the policy. The architecture guide also names the two script files among the routes that need no login.

style-src keeps 'unsafe-inline', because the pages use style attributes and one <style> block. #1311 tracks their move.

Why

No console response carried a Content-Security-Policy. The delete forms put an HTML-escaped name inside an inline JavaScript string, for example onsubmit="return confirm('Delete group {name}?')". The browser decodes the escaped quote before it runs the handler, so a quote in a name ends the string. The rest of the name then runs as script in the session of the admin who clicks Delete. Since #506, the console's forms refuse such names, as the management API does. A name that an earlier release stored can still hold a quote.

Now the question is attribute text, and the browser runs no inline script that gets into a page.

Closes #706

Testing done

At 77628c5, on main 8c64333.

  • New tests/test_console_csp.py, 18 cases, on a SQLite server built from the branch:
    • 11 pages, the login page among them, carry the policy and load console.js. An html.parser check finds no <script> without src, no on* attribute and no javascript: URL in them.
    • The account, user, group and role pages carry the expected delete questions in data-confirm, compared by equality after a sort. The backends list policies in different orders.
    • Each setup step asserts its exact status, and finally deletes the account. The setup writes its own trust and access policy documents. The other console test classes keep theirs inside their own classes, and a shared helper would change tests/test_console_integration.py outside this fix.
    • The server sends both scripts as JavaScript without a session and without the policy.
    • A self-test feeds the html.parser check each shape that it must find.
  • That file and tests/test_console_integration.py together: 52 passed. On a server built from f0170bd, which has the console code of 8c64333, 17 of the 18 new cases fail. The parser self-test passes, because it needs no server.
  • Rust unit tests in console/mod.rs: the policy goes on HTML responses only, with any case in the media type. The test also compares the policy with its exact text. A second test requires the text in the scripts that the pages and the server depend on. That text holds the two event listeners, data-confirm, _csrf, the CSRF meta tag, data-ops and the metrics feed.
  • A manual check in headless Chromium 157.0.8103.15 (Playwright 1.65.2) under the policy: 19 checks passed, with no securitypolicyviolation event and no page error. This check is not part of CI. It covered:
    • the login page and the dashboard
    • the CSRF field on POST forms, and an account created through the form
    • the delete dialog on the user page: dismiss keeps the user, and accept deletes it
    • the metrics data load and a window link
    • the field filter of the cache page
    • the accounts, account, settings and docs pages
  • cargo +1.97.0 fmt --all -- --check and both commands of clippy.yml: pass. cargo +1.97.0 test -p extenddb-server --lib: 515 passed. The other 5, in backup_store::tests, fail on the build host, which has no directory whose ancestors belong to root or the test user. This change does not touch backup_store.

Open PRs that add console pages:

Checklist

  • I have read CONTRIBUTING.md
  • All tests pass (cargo test --workspace)
  • Code is formatted (cargo fmt --check)
  • Clippy is clean (cargo clippy -- -W clippy::pedantic)
  • I have added or updated tests for new functionality
  • I have updated documentation if behavior changed
  • Breaking changes are noted below (if any)
  • If this changes the wire protocol, Storage trait, auth model, on-disk
    format, or public CLI surface, an RFC has been accepted or is linked
    below. Otherwise, an ADR captures the decision (link below).

ADR / RFC: n/a


By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache License 2.0 and I agree to the Developer Certificate of
Origin (DCO). See CONTRIBUTING.md for details.

…ns no inline script

Console HTML responses now carry this Content-Security-Policy:

    default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline';
    img-src 'self' data:; connect-src 'self'; base-uri 'none';
    form-action 'self'; frame-ancestors 'none'

Scripts run only from the server's own origin. An inline script, an
event handler attribute or a javascript: URL does not run. The server
adds the layer where it nests the console router, so the layer covers
every route that the console router holds. A script, JSON, PDF or
redirect response gets no policy.

The inline scripts move into two files that the console serves from
/console/assets/. console.js adds the CSRF field to POST forms, asks
the delete questions, and filters the fields of the cache page.
metrics.js holds the dashboard script. Apart from the header comment,
its one new line reads the data plane operations from the data-ops
attribute of its script tag.

The delete forms put the question in a data-confirm attribute in place
of an inline onsubmit handler. A quote in a name ended the script
string of the handler, because the browser decodes the escaped quote
before it runs the handler.

The security model and the architecture guide state the policy. The
architecture guide also names the two script files among the routes
that need no login.

The pages keep their inline styles, so style-src keeps 'unsafe-inline'.
#1311 tracks the move of the styles. #706 also asks the group, role
and policy forms to refuse the names that the management API refuses,
and #506 did that.

Closes #706
Refs #1311

@demohan demohan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The console runs no injected script at 77628c5, and every page works under the policy. With headless Chromium and Firefox against SQLite and PostgreSQL builds of this head and main: every text/html response under /console, 54 kinds twice, including login after a wrong password, HTML error pages, POST results and the access key page, carries exactly the stated policy, and redirects, JSON, text, the scripts and the data plane carry none; nosniff, X-Frame-Options, Referrer-Policy and HSTS are unchanged. A group, policy or access key named x'+(window.__pwned=1)+' runs its script from the Delete button on main in both browsers (#706) and not on this head, and 26 vectors injected into a page (inline script, handlers, javascript: links and frames, data: and blob: scripts, eval, <base>, workers, objects, outside scripts, images, fonts, fetches and form posts) all ran on main and were blocked here, with no request reaching the outside host. A 64-step walk of every page and action (login, the lockout page, accounts, users, groups, roles, members, access keys, inline policies, the cache filter and invalidation, docs, metrics with its op buttons, ranges and exports) gives the same result on both builds with no violation, every form carries its CSRF field, and all nine delete questions ask as before, cancel sending nothing. It also works behind a proxy on another origin. The branch merges with main at 222d80a, the merged tree builds and passes 60 console tests and 18 of the new cases, fmt, both clippy commands and the 1.91.1 check are clean, main's binary fails 17 of the 18 new cases, and CI is green.

/// because the pages use `style` attributes. Forms post to the server's own
/// origin, and no page loads a plugin or shows in a frame.
const CONTENT_SECURITY_POLICY: &str = "default-src 'none'; script-src 'self'; \
style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self'; \

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Optional. Nothing the console serves loads an image or a stylesheet file: with img-src removed and style-src 'unsafe-inline' alone, every check above gave the same result, with no violation in Chromium and only Firefox's own favicon request in Firefox. img-src 'self' and style-src 'unsafe-inline', with the test at line 249 and 10-security-model.md:293, would allow only what is used.

Comment thread tests/test_console_csp.py
"/login",
"",
"/accounts",
"/accounts/{a}",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Optional. This list covers 11 pages and leaves out the create forms, the three add-policy forms, the access key page that shows the secret, /docs/{slug} and the error pages: an inline script put on the access key page and the docs view, and an onclick on the add-policy form, still pass all 18 cases and 60 Rust tests. All of those pages are clean at this head. Adding them, or following every link from the dashboard, would keep them so.

/// rows hold those names and the calls and events that use them. This
/// checks the text of the scripts, not what they do.
#[test]
fn the_scripts_read_the_names_the_pages_write() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Optional. No test runs console.js, so matching 'get' instead of 'post' (every browser form would then get a 403 without its CSRF field) or inverting the question !== null test (deletes without asking) passes every test. The body says the browser check was by hand; one headless-browser case in CI would hold both. The two scripts are also sent with no-cache and no ETag, so each page load fetches them in full, 76 times in one walk; an ETag from the file text would let the browser revalidate.

@LeeroyHannigan
LeeroyHannigan added this pull request to the merge queue Dec 3, 2026
Merged via the queue into main with commit cb2b6af Dec 4, 2026
58 checks passed
@LeeroyHannigan
LeeroyHannigan deleted the fix/706-console-csp branch December 4, 2026 04:25
LeeroyHannigan added a commit that referenced this pull request Dec 4, 2026
Main added the console's Content-Security-Policy (#1325) at the place in
crates/server/src/console/mod.rs where this branch adds
host_refused_page. The merge keeps both: the policy constant, then the
page.
LeeroyHannigan added a commit that referenced this pull request Dec 4, 2026
…-time

The merge takes f583547, the last head of #1093 before main merged
it as 1e2ebdd. The last merge took b8f73c4. Since then, #1093
merged main at 1174651, eight PRs past db8a90d: #1466, #1087,
#768, #1296, #1485, #1228, #1325 and #1443. Git merged without a
conflict. Two files of this branch have changes on both sides:

- crates/storage/src/util/mod.rs: #1087 declares and exports
  scan_segment, and this branch declares and exports throughput.
- docs/differences-from-dynamodb.md: #1443 changes the
  control_plane_delay_seconds default to 0.25 in two rows, and this
  branch adds the LastIncreaseDateTime row to the Control Plane table.
LeeroyHannigan added a commit that referenced this pull request Dec 4, 2026
Main is at 1e2ebdd, ten commits past db8a90d: #1466, #1087,
#768, #1296, #1485, #1228, #1325, #1443, #1269 and the squash commit
of #1093.

One file conflicted: docs/manuals/07-upgrade-manual.md. #1093 adds its
v1.2.0 entry at the top of "Behavior Changes by Release", where this
branch has its entry. The merge keeps both entries without change. The
entry of this branch stays first. The entry of #1093 comes next, above
the other v1.2.0 entries of main. #1087 adds its entry after the other
v1.2.0 entries of main, and git merged it with no conflict.

Git merged four other files with no conflict:

- crates/core/src/validation/mod.rs: #1228 adds the pattern clause for
  an empty value in validate_name_member. This branch declares the
  table_name_length module near the top of the file.
- crates/server/src/table_name_gate.rs: #1296 adds has_no_table_member
  and an arm of check_table_name_chars for the six operations that have
  no table member. This branch checks none of those operations.
- crates/wasm-adapter/parity/corpus.json: #1087 adds a Scan case, and
  #1228 changes the text of a ListBackups case. This branch changes
  other cases.
- docs/manuals/10-security-model.md: #1325 adds the
  Content-Security-Policy line of the console. This branch changes the
  line on the requests that get an answer before the IAM decision.
LeeroyHannigan added a commit that referenced this pull request Dec 4, 2026
Main is at 1e2ebdd, six commits past 44a7b79: #1485, #1228,
#1325, #1443, #1269 and the squash commit of #1093.

One file conflicted:
crates/storage-mongodb/src/data_engine_live_tests.rs. #1093 declares
the update_window module after delete_table, where this branch
declares put_race and contention. The merge keeps all three
declarations: update_window first, then the two of this branch.

Git merged five other files with no conflict:

- crates/storage-mongodb/src/snapshot_engine.rs: #1093 checks that a
  table serves with TableStatus::serves, and its tests set a table to
  CREATING instead of UPDATING. This branch builds a test engine with
  MongoEngine::for_test, at other lines.
- crates/storage/src/error.rs: #1093 adds a sentence to the doc comment
  of IndexesInUse. This branch changes the doc comment of Transient.
- crates/storage/src/lib.rs: #1093 declares update_window_conformance,
  and this branch declares request_clock.
- docs/differences-from-dynamodb.md: #1443 changes the default delay
  to 0.25 s, and #1093 changes the row on stream disable and the row of
  the delay setting. This branch changes two rows near the top and adds
  the row on sustained contention.
- docs/manuals/07-upgrade-manual.md: #1093 adds its v1.2.0 entry at the
  top of "Behavior Changes by Release". The entry of this branch stays
  after the v1.2.0 entries of main.
LeeroyHannigan added a commit that referenced this pull request Dec 4, 2026
Main is at 1e2ebdd, six commits past 44a7b79: #1485, #1228,
#1325, #1443, #1269 and the squash commit of #1093.

One file conflicted:
crates/storage-mongodb/src/data_engine_live_tests.rs. #1093 declares
the update_window module after delete_table, where this branch
declares the token module. The merge keeps both declarations:
update_window first, then token.

Git merged five other files with no conflict:

- crates/core/src/validation/mod.rs: #1228 adds the pattern clause for
  an empty value in validate_name_member. This branch changes the index
  key checks, at other lines.
- crates/storage/src/error.rs: #1093 adds a sentence to the doc comment
  of IndexesInUse, and this branch adds TransactionInProgress.
- crates/storage/src/lib.rs: #1093 declares update_window_conformance,
  and this branch adds names to the transact exports.
- docs/differences-from-dynamodb.md: #1443 changes the default delay
  to 0.25 s, and #1093 changes the row on stream disable and the row of
  the delay setting. This branch changes the row on index key
  validation.
- docs/manuals/07-upgrade-manual.md: #1093 adds its v1.2.0 entry at the
  top of "Behavior Changes by Release". The entry of this branch stays
  after the v1.2.0 entries of main.
LeeroyHannigan added a commit that referenced this pull request Dec 4, 2026
Main is at 1e2ebdd, eight commits past 5826e1b: #768, #1296,
#1485, #1228, #1325, #1443, #1269 and the squash commit of #1093.

Three files conflicted, in four hunks. In each hunk the UpdateTable
window of #1093 meets the answer of this branch for a DELETING table:

- crates/storage-postgres/src/update_table.rs and
  crates/storage-sqlite/src/update_table.rs have one hunk each. #1093
  reads three more columns of the table row: the stored throughput, the
  table class and the window (in_window on PostgreSQL,
  stored_transition_at on SQLite). This branch answers a DELETING table
  with TableBeingDeleted right after UpdateTable reads the row. The
  merge keeps the wider read of #1093, then the DELETING check of this
  branch, then the check for a status other than ACTIVE. The window
  checks of #1093 come after that check, as on main.
- crates/storage-mongodb/src/table_engine.rs has two hunks, both in
  require_active_table. #1093 makes the function return the catalog
  document of the table, and UpdateTable reads the window from it. This
  branch answers DELETING with TableBeingDeleted in a match on the
  status. The merge keeps that match, and its ACTIVE arm returns the
  document. The doc comment names the document and the three answers.

A table has one stored status. #1093 reports UPDATING only for a
stored ACTIVE table whose status_transition_at is later than now
(reported_status in crates/storage/src/util/mod.rs). So no table is
UPDATING and DELETING at the same time, and the merge does not choose
between the two answers.

Git merged six other files of this branch with no conflict:

- crates/engine/src/update_table.rs: #1093 changes the doc comment of
  handle_update_table and declares the status_tests module. This branch
  maps TableBeingDeleted in update_table_err_to_dynamo.
- crates/storage-cassandra/src/update_table.rs: #1093 reads
  status_transition_at and adds the window. This branch adds the same
  DELETING check before the check for a status other than ACTIVE.
- crates/storage-postgres/tests/table_snapshot.rs: #1093 writes
  CREATING instead of UPDATING in two fixtures. This branch changes
  other tests.
- crates/storage/src/error.rs: #1093 adds a sentence to the doc comment
  of IndexesInUse, and this branch adds TableBeingDeleted.
- docs/differences-from-dynamodb.md: #1443 changes the default delay
  to 0.25 s, and #1093 changes the row on stream disable and the row of
  the delay setting. This branch adds the row on requests during a
  DELETING window.
- docs/manuals/07-upgrade-manual.md: #1093 adds its v1.2.0 entry at the
  top of "Behavior Changes by Release". The entry of this branch stays
  after the v1.2.0 entries of main. The change of this branch to the
  entry of #1411 stays too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request security

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Console: no Content-Security-Policy header, and delete buttons embed names in inline JavaScript

2 participants