fix(security): harden CSRF with Content-Type gate and OpenAPI sync#2819
Merged
fix(security): harden CSRF with Content-Type gate and OpenAPI sync#2819
Conversation
Defense-in-depth over GET→POST alone: reject the three CORS-safelisted
simple-form Content-Types (x-www-form-urlencoded, multipart/form-data,
text/plain) on 5 no-body POST handlers (snapshot/save,
manager/queue/{reset,start,update_comfyui}, manager/reboot) to block
<form method=POST> CSRF that bypasses method-only gating. Convert 10 pure
state-changing endpoints (fetch_updates, queue/{update_all,reset,start,
update_comfyui}, snapshot/{remove,restore,save}, comfyui_switch_version,
reboot) from GET to POST and split 5 config endpoints
(db_mode/preview_method/channel_url_list/policy/{component,update}) into
GET(read) + POST(write, JSON body). Emit the in_progress + done event pair
from the /manager/queue/install sync-enable fast-path so client UI
finalizes (previously only queue/start's empty worker done fired, leaving
item.restart unset and the Enable button visible after a successful enable).
Harden js/custom-nodes-manager.js completion path: await onQueueCompleted
with try/catch (surfaces silent turbogrid stale-item throws), replace the
{}.length == 0 no-op empty guard, set install_context before queue/install
to avoid a sync-completion race, wrap classList/updateCell in try/catch.
Resynchronize openapi.yaml with the converted routes (method → post, query
params → requestBody JSON schema, sibling post on 5 split endpoints).
Update 31 JS fetchApi call sites across 7 files; add
tests/test_csrf_content_type_helper.py covering 5 Content-Type cases via
aiohttp TestClient.
Reported-by: XlabAI Team of Tencent Xuanwu Lab
CVSS: 8.1 (AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:H)
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.
Summary
<img>-triggered CSRF vector.application/x-www-form-urlencoded,multipart/form-data,text/plain) to block<form method=POST>CSRF that bypasses method-only gating. Bare POST andapplication/jsonpass through unchanged — no first-party JS changes needed for the gate./manager/queue/installsync-enable fast-path now emits thein_progress + doneevent pair. Previously onlyqueue/start's empty-worker done fired, leavingitem.restartunset and the Enable button visible after successful enable.js/custom-nodes-manager.js: awaitonQueueCompletedwith try/catch (surfaces silent turbogrid stale-item throws), replace{}.length == 0no-op empty guard, setinstall_contextbeforequeue/installto avoid sync-completion race, wrapclassList.remove/grid.updateCellin try/catch.openapi.yamlupdated to match converted routes (method→post, query params→requestBody JSON schema, sibling post on 5 split endpoints).pyproject.toml,manager_core.py).tests/test_csrf_content_type_helper.pycovers 5 Content-Type cases via aiohttp TestClient.Scope
glob/manager_server.pyjs/custom-nodes-manager.jsjs/{cm-api,comfyui-manager,common,model-manager,snapshot}.jsopenapi.yamltests/test_csrf_content_type_helper.pypyproject.toml,glob/manager_core.pyTotal: 11 files, +567 / -144.
Test plan
python tests/test_csrf_content_type_helper.py— Ran 5 tests in 0.003s, OK (form-urlencoded→400, multipart→400, text/plain→400, no Content-Type→200, application/json→200)python -c "import yaml; yaml.safe_load(open('openapi.yaml'))"— passes@routes.postpath inglob/manager_server.pyhas matchingpost:inopenapi.yaml(27/27)request.content_typenormalization across 16 CT variants (case, whitespace,charset=,boundary=) — no bypass identifiedruff check— All checks passedRelated
manager-v4branch (v4/v2/manager/*routes) handling the same CVE: fix(security): harden CSRF with Content-Type gate and expand E2E coverage #2818fix(security): harden CSRF with Content-Type gate and ...)and identical
Reported-by/CVSStrailer for audit cross-reference(
git log --grep='XlabAI' --all).Reported-by: XlabAI Team of Tencent Xuanwu Lab
CVSS: 8.1 (AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:H)