Repository navigation
Conversation
The Content-Security-Policy said only who may frame a page. Markup that got past autoescaping could still load a plugin, add a <base> that re-points every relative link, post a form to another site, or fetch and send data anywhere. The policy now also carries object-src 'none', base-uri 'none', form-action 'self', connect-src, font-src, worker-src and manifest-src 'self', img-src 'self' data: blob: and media-src 'none'. Everything MCRITweb loads is its own, so nothing changes for a page: every page was walked in Chromium as each role and signed out, with the upload, the overlay's on-demand Dropzone, live search, the CFG worker and the function comparison driven, without a violation. It is still set with setdefault, so a response that names its own policy keeps it.
Playwright evaluates a wait_for_function predicate given as a bare expression with eval, once per poll. Under a Content-Security-Policy that refuses eval, the first poll that is needed fails the wait with an EvalError, though the page itself is fine. A predicate written as a function is compiled once, through the debugging protocol, which the policy does not govern. The 37 expression predicates in the browser tests become arrow functions with the same body, ahead of the script policy that refuses eval on every page.
The Content-Security-Policy said nothing about scripts, so a <script> that slipped past autoescaping ran like one of ours. It now carries script-src 'nonce-...' 'strict-dynamic' 'report-sample', with a nonce drawn per response by csp_nonce() and written on every script element the templates have, and on the one flask-dropzone's config() writes. 'strict-dynamic' extends that to what those scripts add themselves: base.html's later() queue, the CFG viewer's libraries and its worker, Dropzone fetched on the first drag. live_search.js gives the scripts of the rows it swaps in this page's nonce, since an inline script is admitted by its nonce alone; Chromium runs it without, the spec does not. script-src-attr 'unsafe-inline' keeps the onclick= and other handler attributes running until they are listeners. No rendered page is reused: the result cache holds reports and images, the memos hold data, gzip compresses each response as it goes, and pages carry no validators, so every response renders its own nonce. testScriptNonces.py fails on a template's script without the nonce and on any rendered page's script without that response's nonce, and pins the policy's shape. testContentSecurityPolicyBrowser.py walks every page as visitor, contributor, admin and signed out, and drives the drop and the overlay's Dropzone, live search, the CFG worker, the function comparison, the cross compare tabs and swatches, the dialogs, sorting, the copy buttons, the column settings and a running job's polling, failing on any violation, page error or worker fallback. AGENTS.md says how to write a script, and a browser test's wait, under the policy.
No response said which browser features a page may ask for, and none told a browser that had come over HTTPS to stay there or kept other sites from holding a handle on MCRITweb's window. Every response now carries Permissions-Policy: camera=(), microphone=(), geolocation=(), payment=(), usb=(), none of which a page uses; the clipboard the copy buttons write to stays allowed. A request that came over HTTPS, directly or through a proxy TRUSTED_PROXY_COUNT trusts, also gets Strict-Transport-Security and Cross-Origin-Opener-Policy: same-origin-allow-popups. Over plain HTTP neither is sent: a browser ignores HSTS there, and Chromium logs an error for COOP on every plain-HTTP page off the loopback address, which docker-mcrit's default site is. The HSTS value is STRICT_TRANSPORT_SECURITY, defaulting to the one docker-mcrit's TLS site already adds in NGINX. Browsers act on the first such header in a response, which is the app's, so any other default would change what that deployment says. None sends none.
Under the plain name "session", a sibling subdomain, or anyone in the middle of a plain-HTTP request to the host before the user signs in, could set a session cookie of their own - validly signed, for their own account - that the browser then sent in place of ours, or one that logged the user out. A browser takes a __Host- cookie only from the host itself, over HTTPS, for the whole site. create_app names the cookie once the config has loaded: __Host-session when it is Secure, has no Domain and its path is /, which is the default, and "session" otherwise, so plain-HTTP deployments with SESSION_COOKIE_SECURE = False and cookies shared across subdomains keep working. A name set in instance/config.py wins. Everyone logs in once more, as the session generation change in this release asks anyway. The shared test fixture keeps "session": the browser tests hand Chromium the cookie without a Secure flag, which it refuses under a __Host- name. testAppConfig.py covers the name and the attributes the prefix needs, and testSessionCookieBrowser.py signs in through the form of a deployment-built app and stays signed in.
Three places wrote a value with nothing but autoescaping, which is HTML escaping. The admin server page put the registration token, which the admin chooses and only the registration form's HTML pattern limits, into a quoted JS string: a trailing backslash escaped the closing quote and broke the script. The family rows put a contributor's family name into the path of the Malpedia link, where a ? or a # began a query or fragment of its own. And a cross compare cell wrote its sample's job id into a JS string in an onclick attribute, which the HTML parser decodes before the handler is compiled; job ids are ObjectIds, so that one was inert. The token goes through |tojson, as do the three integer ids written into the CFG pages' scripts, the family name through |urlencode, and the cell's link into a data-href with the same relative target, which a listener the page binds while it parses follows, as early as the onclick did. testScriptEscaping.py now fails on any interpolation in a script body that is not |tojson, url_for() apart, and renders the three cases.
testThemeBrowser.py builds its own app, which names its session cookie __Host-session as a deployment's now does, and handed Chromium the cookie without a Secure flag. Chromium refuses a __Host- cookie without one, so every test in the module failed to set up. The cookie now carries the flag the app's own Set-Cookie does, and the theme walk runs on the deployment's cookie name.
The Change Backend Server form printed the stored server token as the value of a text field, so that a submit would post it back unchanged: the token sat in clear in the page source, the browser's cache and on the admin's screen, where AGENTS.md says it is never rendered. An empty field cleared it. The field now starts empty and a line under it says whether a token is set. change_server keeps the stored token when the field comes back empty, replaces it with a typed one, and clears it only for the new Remove Token button, shown when there is a token to remove. The page still shows the registration token, so it stays uncompressed; the docstring and README sentence that listed the backend token there now list only that one.
The test that clicks a cross compare cell while jQuery is held back loaded the page waiting for its load event, which the held script can delay for good when the queue starts first. It timed out once in a full run. It now waits for the document to be parsed, which is all a listener bound while the page parses needs.
The settings page prints the account's API token and the server page the registration token. Without no-store a browser kept them in its back/forward cache, so Back after logout restored the page, token included, without asking the server. The two views now carry a no_store decorator next to uncompressed; every other page keeps its caching.
The rendered-pages test compares two renders of a page byte for byte. Each response now carries its own CSP nonce, so the two differed in every script tag. The comparison masks the nonce next to the CSRF token it already masks.
Without hard links the key was written into a file created with O_EXCL, empty until filled. A worker that opened that file in the gap could replace it and find the creator's key still written into the file it had displaced; a third worker that had opened the displaced file before the replacement then read the loser's key and used it, while everyone else used the winner's. One round in about 1600 ended that way. The staged key, complete and private from mkstemp, is now renamed into place under a lock on the instance folder, looking at the key file again once the lock is held. No key file is opened for writing any more, and none is ever visible unfinished. The test that pinned the old create-then-lock order is replaced by two that pin the new one.
This was referenced Oct 25, 2026
The settings page printed the account's API token, so the whole page was sent uncompressed (a secret that is the same in every response is what a BREACH attack reads out of a compressed one) and with no-store, for a value most visits never look at. The page now has a "Show token" button. static/show_apitoken.js, queued with later(), POSTs with the CSRF token to the new admin.show_apitoken, which answers the session's own token as JSON, uncompressed and no-store, and refuses a GET, a missing or wrong CSRF token, a signed-out caller and a pending account. The token lands where it was shown before, next to its copy button, and a polite status says whether it worked. Regenerating the token leaves a one-time mark in the session, so the page it leads back to fetches the new token at once, as it used to show it. The script takes the token off the page on pagehide, since the page may now be kept in the back/forward cache. base.html holds an early press on the button, as it does for data-post buttons. /settings has no secret left and is compressed and cacheable again. The registry of secret views, the token-scan test and the no-store test now name admin.show_apitoken instead, and printing the token on the settings page again fails the scan.
The test held the request for show_apitoken.js by its bare path. With #331's static versioning the URL ends in ?v=<digest>, the route never matched and the test failed on the build of all PRs. The pattern now allows a query.
r0ny123
added a commit
that referenced
this pull request
Oct 26, 2026
The status message tests copy the API token on the settings page. With #330 the page no longer prints the token: its copy button stays hidden until Show token is pressed, so the tests timed out on the build of all PRs. They press it first where the page has it.
r0ny123
added a commit
that referenced
this pull request
Oct 26, 2026
The test that the 64-character token wraps at 320 and 390px looked for it in the page's source. With #330 the page fetches the token when Show token is pressed, so it was not there on the build of all PRs. The test presses the button where the page has it and then measures the page with the token shown.
r0ny123
added a commit
that referenced
this pull request
Oct 26, 2026
…ading and #333's slider wording The tag that queues upload_form.js from base.html carries the page's nonce, the overlay's title is the h2 #336 made it, and the slider's handler upload_form.js defines for the overlay sets its aria-valuetext as the template's does. #333's tests of the overlay's button and of its family, version and base address fields read the overlay as the first drag fetches it.
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.
Based on
ref/integrate-all-20261025, the build of all open PRs (#316's comment has the order). Its scripts, templates and tests are the ones this changes, so the diff here is this change alone. One of a set of PRs from a review of the front end against the modern-web-guidance security and privacy guides; the others cover forms, keyboard access, semantics, colour, layout, tooltips, performance and account deletion (#328).What was wrong.
frame-ancestors 'self'. An injection that got past autoescaping (Server-rendered values are injected into <script> blocks via |safe #85 was one) could run inline script, load an<object>, set a<base>or post a form to another origin.Permissions-Policy,Cross-Origin-Opener-PolicyorStrict-Transport-Security.session. A sibling subdomain, or anyone in the middle of a plain-HTTP request before sign-in, could plant a validly signed session of their own account.admin_server.htmlwrote the registration token into a script as"{{ ... }}", and three integer ids went unescaped into scripts. The Malpedia link put the family name into a URL path unencoded. A cross-compare cell carried a backend id inside a JS string insideonclick. None of these is exploitable today, but each is the pattern AGENTS.md's escaping rules forbid./admin/serverprinted the backend server token into a text field, which AGENTS.md says is never rendered. The form needed it because an empty field cleared the token./settingsprinted the user's API token into the page, and the pages that show a token could be restored from the back/forward cache after logout.Change.
object-src 'none'; base-uri 'none'; form-action 'self'; connect-src 'self'; font-src 'self'; img-src 'self' data: blob:; worker-src 'self'; media-src 'none'; manifest-src 'self', still withsetdefault, so a deployment's own header wins.csp_nonce()). Every<script>in the templates carries it, as does the one flask-dropzone'sconfig()writes. The policy isscript-src 'nonce-…' 'strict-dynamic' 'report-sample'; script-src-attr 'unsafe-inline'.later(), the CFG viewer loader and the Dropzone loader add scripts bysrc, which'strict-dynamic'admits.live_search.js'sadopt()gives the scripts it re-creates the page's nonce.<script>does not.wait_for_functionpredicates witheval, which the policy refuses. 37 such predicates became arrow functions, and AGENTS.md says so.testFunctionTableRows.pycompared two renders byte for byte, which now differ in the nonce. It masks the nonce as it already masked the CSRF token.Permissions-Policy: camera=(), microphone=(), geolocation=(), payment=(), usb=(); the clipboard stays allowed.Cross-Origin-Opener-Policy: same-origin-allow-popupsandStrict-Transport-Securitygo only on secure requests: Chromium logs an error for COOP on every plain-HTTP page off loopback.STRICT_TRANSPORT_SECURITYsetting defaults to what docker-mcrit's TLS site already adds in NGINX,max-age=31536000; includeSubDomains. A browser acts on the first such header only, which would be ours.Nonesends none. The README has an HTTPS section.__Host-sessionwhen it is Secure, host-only and at path/, andsessionotherwise. ASESSION_COOKIE_NAMEininstance/config.pystill wins.appfixture pinssession, because Chromium refuses the harness's cookie dicts withoutsecureunder a__Host-name. Two new tests cover the production name.|tojsonand the Malpedia link through|urlencode.data-href, followed by a listener bound while the page parses, so an early click still works.testScriptEscaping.pynow fails on any interpolation in a script body other than|tojsonorurl_for().Cache-Control: no-store, which keeps them out of the HTTP cache and out of Chromium's back/forward cache, so Back after logout cannot show a token.no_storedecorator incompression.pysits next touncompressed, so every other page keeps its caching.Clear-Site-Datais not needed for this./settingsno longer contains the API token.admin.show_apitokenwith the CSRF token and gets back{"apitoken": …}for the signed-in user only. It then fills the field and enables the copy button. A failed request, including a session that has ended, shows an error and no token.show_apitokenis@visitor_required, POST-only,@no_storeand@uncompressed./settingsis gzipped and cacheable again: 9.4 KB on the wire instead of 42.8 KB. On mobile, the uncompressed page took an extra round trip and scored 99 on the build of all PRs./admin/serverstill shows the registration token and staysno-storeand uncompressed.Since review was requested.
testShowApitokenBrowser.pyheld the request forshow_apitoken.jsby its bare path. With Cache static files until they change, and trim what pages wait for #331's?v=<digest>static URLs the route never matched, and the early-click test failed on the build of all PRs. The pattern now allows a query. Nothing changes at runtime.Tests.
testContentSecurityPolicyBrowser.py,testScriptNonces.py,testSecurityHeaders.py,testSessionCookieBrowser.py,testServerToken.py,testNoStoreSecrets.py,testShowApitoken.pyandtestShowApitokenBrowser.py.testContentSecurityPolicyBrowser.pywalks every page as visitor, contributor, admin and signed out, plus the upload drop, the on-demand Dropzone, live search, the CFG graph and its worker, function comparison, modals, tabs, sorting, copy buttons, Show token, column settings and the jobs page's polling. It records zerosecuritypolicyviolationevents and no page error.testScriptNonces.pyfails on a<script>without the nonce.testShowApitoken.py(16 tests, CSRF on) checks that no role's/settingshas the token, and that the page is gzipped and notno-store. It checks that the route returns the caller's own token and never another user's, and that it refuses a missing or wrong CSRF token, a GET, a signed-out caller and a pending account. Printing the token insettings.htmlagain fails the token scan.testShowApitokenBrowser.py(6 tests, Chromium) clicks Show token and reads the copied token back from the clipboard. It also covers an early click, Regenerate, a server error, an ended session and a return through the back/forward cache. Its early-click test holds the script by a pattern that allows?v=(975aeef).testFramingHeaders.py,testAppConfig.py,testScriptEscaping.py,testCrossMatrixLinks.py,testCompression.pyandtestApiTokenRotation.py.Lighthouse. Accessibility, Best Practices and SEO are 100 on the sampled pages, signed in and out. Desktop Performance is 100. An interleaved run with and without the header showed no cost from the policy. On 5011a7e
/settingsscores 100 in all four on desktop. On mobile it scored 100, 99 and 100; the 99 was blocking time on a shared machine.For the other PRs of the set. Any new
<script>needsnonce="{{ csp_nonce() }}", or it does not run andtestScriptNonces.pyfails. A browser test that builds its own app needssecureon its cookie dicts. A new view that returns a token needs@no_storeand@uncompressed.