Skip to content

fix(trigger): reject multipart webhooks missing a required file - #44901

Open
TemitopeKadri wants to merge 1 commit into
langgenius:mainfrom
TemitopeKadri:fix/webhook-required-file-params
Open

TemitopeKadri wants to merge 1 commit into
langgenius:mainfrom
TemitopeKadri:fix/webhook-required-file-params

Conversation

@TemitopeKadri

@TemitopeKadri TemitopeKadri commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

Fixes #44900

In a multipart/form-data webhook, a File body parameter marked as required was never enforced. _process_body_parameters skips file configs because "multipart file validation is handled separately in the extraction phase", but nothing in the extract phase checked required. A request without the file returned 200 and ran the workflow.

This adds WebhookRequestParser._validate_required_files (in controllers/trigger/webhook_request.py, where #45912 moved the parsing), called from _process_and_validate_data after the body is processed. For form-data webhooks it raises Required file missing: <name> when a required File parameter is not among the uploaded files. It raises WebhookRequestValidationError, so it becomes a 400, the same as the existing required header, query and body checks. A file whose upload failed to process is also absent from files, so it now gets the same 400 instead of silently running without it.

Optional file parameters and the other content types are unchanged. This doesn't overlap with #41072, which changes what the node outputs for a missing optional file.

Screenshots

Request (required File param invoice) Before After
no file 200, workflow runs 400 Required file missing: invoice
only another file (receipt) 200, workflow runs 400 Required file missing: invoice
invoice uploaded 200 200 (unchanged)
optional File param, no file 200 200 (unchanged)

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've verified the change and added or updated tests where meaningful regression risk justifies coverage.
  • I've updated the documentation accordingly.
  • I ran make lint && make type-check (backend) and vp staged (frontend) to appease the lint gods

Tests: rebased onto main after #45912, so the tests now live in tests/unit_tests/controllers/trigger/test_webhook_request.py. test_extract_and_validate_webhook_request_missing_required_file asserted the old behavior (files == {}), so it now expects the 400 error. I added cases for a present required file, a missing optional file, a different file uploaded in place of the required one, and a non-form content type. Three of these fail on main. tests/unit_tests/controllers/trigger and tests/unit_tests/services/trigger pass (337 passed). ruff check and ruff format --check on the changed files are clean.

🤖 Generated with Claude Code

From Claude Code

@github-actions github-actions Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Oct 27, 2026
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-10-27 15:48:18.482050502 +0000
+++ /tmp/pyrefly_pr.txt	2026-10-27 15:47:55.549881182 +0000
@@ -6379,13 +6379,17 @@
 ERROR Argument `dict[str, dict[str, list[dict[str, bool | str]] | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
    --> tests/unit_tests/services/trigger/test_webhook_service.py:934:90
 ERROR Argument `dict[str, dict[str, list[dict[str, bool | str]] | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
-   --> tests/unit_tests/services/trigger/test_webhook_service.py:952:95
+   --> tests/unit_tests/services/trigger/test_webhook_service.py:953:90
+ERROR Argument `dict[str, dict[str, list[dict[str, bool | str]] | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
+   --> tests/unit_tests/services/trigger/test_webhook_service.py:974:99
+ERROR Argument `dict[str, dict[str, list[dict[str, bool | str]] | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
+   --> tests/unit_tests/services/trigger/test_webhook_service.py:994:95
 ERROR Argument `dict[str, str | dict[str, str]]` is not assignable to parameter `webhook_data` with type `RawWebhookDataDict` in function `services.trigger.webhook_service.WebhookService._validate_http_metadata` [bad-argument-type]
-    --> tests/unit_tests/services/trigger/test_webhook_service.py:1212:61
+    --> tests/unit_tests/services/trigger/test_webhook_service.py:1268:61
 ERROR Argument `dict[str, dict[str, int] | dict[str, str]]` is not assignable to parameter `webhook_data` with type `RawWebhookDataDict` in function `services.trigger.webhook_service.WebhookService.build_workflow_inputs` [bad-argument-type]
-    --> tests/unit_tests/services/trigger/test_webhook_service.py:1224:59
+    --> tests/unit_tests/services/trigger/test_webhook_service.py:1280:59
 ERROR Argument `dict[str, dict[str, int | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.generate_webhook_response` [bad-argument-type]
-    --> tests/unit_tests/services/trigger/test_webhook_service.py:1235:69
+    --> tests/unit_tests/services/trigger/test_webhook_service.py:1291:69
 ERROR Cannot find module `dify_graph.enums` [missing-import]
   --> tests/unit_tests/services/workflow/test_workflow_converter.py:36:5
 ERROR Cannot find module `dify_graph.model_runtime.entities.llm_entities` [missing-import]

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 87.16% 87.16% +0.00%
Strict coverage 86.82% 86.83% +0.00%
Typed symbols 96,578 96,586 +8
Untyped symbols 14,280 14,280 0
Modules 4652 4652 0

@autofix-ci
autofix-ci Bot requested a review from QuantumGhost as a code owner October 27, 2026 15:44
@autofix-ci
autofix-ci Bot requested a review from a team October 27, 2026 15:44
@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.39%. Comparing base (a92a64a) to head (5a2e029).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #44901   +/-   ##
=======================================
  Coverage   90.39%   90.39%           
=======================================
  Files        6534     6534           
  Lines      409459   409466    +7     
  Branches    82225    82228    +3     
=======================================
+ Hits       370116   370124    +8     
+ Misses      32944    32942    -2     
- Partials     6399     6400    +1     
Flag Coverage Δ
api 90.14% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@TemitopeKadri
TemitopeKadri force-pushed the fix/webhook-required-file-params branch from 770797b to 5a2e029 Compare November 23, 2026 21:01
@TemitopeKadri
TemitopeKadri requested a review from FFXN as a code owner November 23, 2026 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Required File parameter is not enforced for multipart/form-data webhooks

1 participant