Skip to content

Integrate batch G (fixes for 1.7.0): #325 #322 #327 #326 #329 #270 #282 - #340

Merged
danielplohmann merged 29 commits into
masterfrom
integrate/fixes-G
Oct 29, 2026
Merged

danielplohmann merged 29 commits into
masterfrom
integrate/fixes-G

Conversation

@danielplohmann

Copy link
Copy Markdown
Collaborator

Seven security and robustness fixes (batch G) for 1.7.0, integrated the same way as #318 and #339. Each PR's head commit is an ancestor of this branch, so GitHub marks them merged when this lands with a merge commit.

PR fix
#325 reflected XSS: filter forms wrote URL values into unquoted value= attributes, so a crafted filter_family_name link added event handlers to the input. All such attributes are quoted now
#322 follow-ups from the batch E review (#319): a read-only database file, an instance folder without hard links, and upper-case job ids missing the result cache
#327 the family and sample edit dialogs kept "Delete" ticked into the next row's dialog, so a plain rename could delete a family (and its samples) or a sample
#326 a password change accepted an empty password, which then signed in with an empty password field
#329 wrong current passwords on the settings forms were not counted by the login throttle
#270 findLoops answers hand-made graphs (no blocks, a block named like the super root) instead of a 500
#282 findLoops' dominators come from the dominator tree (cubic to roughly linear), its input is bounded (FIND_LOOPS_MAX_BYTES, 8000 blocks), and the function pages say when loop analysis was skipped. Contains #270

Integration

Built on master e7e75fa. #325, #326 and #329 already carry r0ny123's merge of e7e75fa. Two conflicts remained:

Before r0ny123's merges I had resolved the conflicts of #325, #326 and #329 myself. The tree from his merges is identical to mine.

Verified

  • Full suite against the published mcrit 1.16.0 wheel: 2428 passed, 19 skipped. ruff check is clean.
  • Visual walkthrough by the maintainer on a private preview against the live backend:
    • the XSS link is inert;
    • the edit dialogs open with Delete unticked;
    • an empty new password is refused;
    • an upper-case result link works;
    • the 8,298-block function shows "too large for loop analysis".

Seen during the walkthrough, older than this batch, for the graph batch

🤖 Generated with Claude Code

https://claude.ai/code/session_01HERmVhHo4ibp7HSTXr3Ya8

r0ny123 and others added 29 commits October 8, 2026 14:57
cfg_explorer_detector.run() went straight to get_roots(), which falls
back to min() of the graph's nodes when no node is a root. A graph with
no nodes at all - an empty digraph, an empty body, or any text that is
not a dot graph, all of which parse to an empty graph - made that min()
raise ValueError, and /explore/findLoops/ answered with a 500 and a
traceback in the log. A body that is not UTF-8 got the same 500 earlier,
from the route's decode.

The pages never post such a graph: both parse the fetched graph in the
browser before posting it, and graphlibDot.parse() throws on an empty
one, while a function without disassembly gets a one-node "No control
flow graph stored" graph. So the 500 took a hand-made POST, which any
logged-in visitor can send.

A graph without blocks has no loops, so run() answers [] for it, the
same answer a function without loops gets, and the route decodes the
body with replacement, so bytes that are not UTF-8 parse to whatever
blocks they have, or to none. main() carried a line-for-line copy of
run()'s body; it now reads the file and calls run(), so it picks up the
same guard.
With several roots get_roots() adds my_super_root above them. A posted
graph with a block of that name made it one more root's parent instead,
which left no root and failed the assert in run() with a 500. The super
root now takes a name the graph does not use.
dominanators() kept one set per block and intersected the sets of its
predecessors until nothing changed. On a posted graph that costs more
than the square of its blocks: 26 s for 1000 blocks, 294 s for 2000, in
one request from any visitor. The real functions of the test corpus,
up to 971 blocks, took up to a second. The dominators now come from
networkx's immediate_dominators, and membership is read off the
dominator tree, with blocks the entry never reaches still dominated by
every block as before.

immediate_dominators is still quadratic on a graph built for it, and
the loop bodies are the answer itself, which a graph where every block
jumps back to the entry makes grow with the square of its blocks. So
findLoops now refuses graphs over 8000 blocks or 16000 edges, and stops
at 2000 back edges or 200000 loop body entries; such a graph gets no
loops, so the page still draws it. addParentInfo stops recording
"equal" entries, which the page does not read, past 200000, so a
flattened dispatcher keeps its loops, and it looks headers up in sets
instead of scanning node lists.
Switching to WAL is a write, and on a database this process may not
write SQLite raises for it rather than keeping the old mode, so
create_app died in migrate() where it used to start and serve reads.
A SQLITE_READONLY error (any extended code) is now printed, as the
docstring said, and the start goes on. Anything else still raises.
Run from the wrong directory, sqlite3.connect('instance/mcritweb.sqlite')
created an empty database and backed that up. mode=ro fails instead. The
backup now goes into instance/ too, so under docker exec it is kept on
the bind mount rather than left in the container.
os.link fails with EPERM on vfat and exFAT and ENOTSUP on some SMB and
FUSE mounts, so a first start with instance/ on one of those no longer
came up. On any OSError but EEXIST the key now goes into a file created
with O_EXCL instead. That file is empty until the key is in it, so it is
flocked before the write, which makes a worker that finds it empty wait
in _replace_if_still_empty and read the key rather than replace it; and
if one replaced it before the lock was taken, the creator sees that path
names another file and returns that file's key.
…parsing at the bounds

The bounds were checked on the parsed graph, and MAX_CONTENT_LENGTH lets 1 GiB
through: 32 MiB of edges built 1.6 GiB of graph before the block bound refused
it. A body declaring more than FIND_LOOPS_MAX_BYTES (32 MiB) is now answered
without being read, a chunked one is read only up to the cap, and the parser
gives up as soon as the graph is past MAX_BLOCKS or MAX_EDGES. It scans for the
lines that can hold a block or an edge rather than splitting the text first,
which held 570 MiB for 32 MiB of short lines.

A skipped analysis still answers 200 and [], now with an X-Loop-Analysis header
naming the bound, for the page to read. The bounds test lowered MAX_BLOCKS for
all four of its cases, so each of them hit the block bound; only the block case
does now.
main.js and main_duo.js read findLoops' X-Loop-Analysis header and say above
the graph that the function is too large for loop analysis, with its block
count, and that its loops are not highlighted. The graph is drawn as before.
JOB_ID_PATTERN accepts upper-case hex and the backend finds the job by
it, but reports are cached under the id the backend answers with, which
is lower case. So /data/result/<upper-case id> missed the cache on every
visit and fetched and wrote the report again. The routes that check the
pattern now lower-case the id before using it, for the cache and for
the backend alike, and the diagram route does the same for the job id
in a diagram name, which otherwise rendered a new file per casing.
mcrit's LocalQueue mints ObjectIds since 1.14, like MongoQueue. The
comments and test docstrings that still said uuid4 now say that was
before 1.14; the shapes they accept are unchanged, since setup.py still
allows mcrit 1.12.
39 inputs printed their value as value={{ ... }}. Autoescape keeps a value inside a
quoted attribute, but not a space or an =, so an unquoted one ended at the first space
and the rest became attributes of its own. The result page's family filter is reflected
from the query string: ?filter_family_name=x autofocus onfocus=... ran script in the
session of whoever opened the link, with a visitor's login. The other values are parsed
as numbers or come from the user's own settings and the server record, and are quoted
the same way.

tests/testAttributeQuoting.py fails on an unquoted attribute value in any template and
renders the family filter with that payload.
Registration refused an empty password, a password change did not: it only compared the
new password with its confirmation, so Confirm with both left empty set the account's
password to the empty string, replaced its API token, and from then on anyone who knew
the name signed in with an empty password field.

change_password() now asks for a password as registration does, and the settings form
marks the new password and its confirmation required. A sign-in with an empty password
fails whatever the account holds, so one emptied before this change is closed too; it
spends the same check an unknown name does, so the answer's timing still says nothing
about whether the name exists.
Each page has one edit dialog per kind, filled from the button that opens it, and its
Delete box was never reset. Ticked and the dialog closed, it came back ticked for the
next family or sample, with the delete button showing, and a plain Submit Changes then
sent family_delete or sample_delete, which modifyFamily and modifySample act on by its
presence alone: a rename deleted the family (and, with Keep samples unticked, its
samples) or the sample.

Every opening now unticks Delete, hides its button, and puts Keep samples back on, in
the three templates that carry a copy of the dialogs.
Changing the username and changing the password both ask for the current
password, and neither counted a wrong one. Whoever held a stolen or copied
session could guess at the password there without limit, while /login stops
the same address after LOGIN_ATTEMPT_LIMIT tries (#101).

Both forms now check the throttle before the password, record a wrong one
as a failed login from that address, and clear the account's failures on a
right one, as a successful login does.
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.
Bootstrap 5.0.2 ignores Escape while a modal's show transition runs, and the
test waited only for `.show`, which is added when the transition starts. On a
slow or busy machine Escape was pressed too early, the dialog stayed open and
the test timed out. It now waits for `shown.bs.modal`, on both opens.
# Conflicts:
#	mcritweb/templates/admin_server.html
#	mcritweb/templates/result_compare_function.html
#	mcritweb/templates/result_compare_sample.html
#	mcritweb/templates/result_compare_vs.html
#	mcritweb/templates/settings.html
# Conflicts:
#	mcritweb/templates/settings.html
# Conflicts:
#	mcritweb/views/administration.py
# Conflicts:
#	mcritweb/views/data.py
# Conflicts:
#	mcritweb/__init__.py
@danielplohmann
danielplohmann merged commit 30cbc8a into master Oct 29, 2026
8 checks passed
@danielplohmann
danielplohmann deleted the integrate/fixes-G branch October 29, 2026 21:10
@danielplohmann danielplohmann mentioned this pull request Oct 29, 2026
r0ny123 pushed a commit to r0ny123/mcritweb that referenced this pull request Oct 30, 2026
Bumps setup.py and adds the version history entry, folding in the five
"unreleased" lines (familiary#263, familiary#262, familiary#261, familiary#293, familiary#254).

48 PRs since 1.6.0: batches C1 (familiary#298), C2 (familiary#299), security E (familiary#318),
UI F (familiary#339) and fixes G (familiary#340). No dependency changes.

The entry leads with the three things that affect existing deployments:
instance/ backups under WAL mode, the bounded result cache, and the
optional retirement of pre-1.5.0 API tokens.

Test count measured on the batch G tree, which master 30cbc8a is
identical to: 2428 passed, 19 skipped against mcrit 1.16.0, 2447
collected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HERmVhHo4ibp7HSTXr3Ya8
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.

2 participants