Repository navigation
fix(functions): return 400 for malformed execution headers - #13963
Conversation
🟢 Tier S · Ready to merge
The pull request returns HTTP 400 for malformed function execution headers by rejecting array or object values and using the invalid-argument exception type. It adds unit and end-to-end coverage for invalid values and header names. The latest commit preserves acceptance of scalar header values and revises the validator’s error message. Latest changes: The newest commit changed header validation to allow scalar values again, updated unit expectations for integers and booleans, and clarified the validation description.
Note @AayushKrGupta does not have write access to this repository, so Hansi does not approve automatically. A maintainer can review and approve. 📂 Walkthrough · 4
Reviewed the commits since |
|
713175e to
b2be519
Compare
Fixes appwrite#13962 Reject non-string and non-null values in the Headers validator to prevent a TypeError when strlen() is called on non-string values. In Executions\Create, pass Exception::GENERAL_ARGUMENT_INVALID as the exception type rather than passing the description string and integer 400 as message.
b2be519 to
ec55235
Compare
Only arrays and objects break the header size check, so numeric and boolean values stay accepted as before. The description now follows the other validators and mentions the leading/trailing hyphen rule.
What does this PR do?
Fixes two bugs causing
POST /v1/functions/:functionId/executionsto return HTTP 500 (general_unknown) instead of HTTP 400 when malformed headers are passed:HeadersvalidatorTypeErroron non-string values:Headers::isValid()was calculating$size += $length + \strlen($val ?? '')without asserting the type of$val. When a caller sends a non-string value (like an array{headers: {X-Test: [bad]}}), PHP throwsTypeError: strlen(): Argument #1 ($string) must be of type string, array given.Headers::isValid()now returnsfalseif$valis neither a string nornull.Wrong
Exceptionconstructor arguments inExecutions/Create:When header validation failed, the route threw:
Appwrite\Extend\Exceptiontakes an error type constant as the first argument and the description as the second. Passing the description string as the type and400as the message left the HTTP code unset, so the exception handler fell back to an unhandled 500 error.This now throws
Exception::GENERAL_ARGUMENT_INVALIDwith the validator description, matching the datetime check in the same route.Test Plan
tests/unit/Functions/Validator/HeadersTest.php:tests/e2e/Services/Functions/FunctionsCustomServerTest.php:testCreateExecutionverifying that invalid header shapes (e.g. array values, bad key names) return HTTP 400 withgeneral_argument_invalid.Related PRs and Issues
Checklist