Skip to content

Fix Network.post() silently dropping falsy-but-defined params from FormData#909

Merged
Valforte merged 1 commit intomainfrom
fix-network-falsy-value-drop
Apr 13, 2026
Merged

Fix Network.post() silently dropping falsy-but-defined params from FormData#909
Valforte merged 1 commit intomainfrom
fix-network-falsy-value-drop

Conversation

@Beamanator
Copy link
Copy Markdown
Contributor

@Beamanator Beamanator commented Apr 10, 2026

Fix Network.post() silently dropping falsy-but-defined values from FormData.

The check if (!value) is a falsy guard — it drops false, 0, '', null, and undefined. For multipart requests (those containing a File or Blob), this meant parameters like csrfToken could be silently omitted from the FormData body if their value was falsy.

The keepalive() method in the same file already uses the correct guard if (value === undefined). This aligns post() to match.

History: This fix was originally made in 2020 (commit 832cd5a) and then reverted 10 minutes later in the same PR (#262) as "an unnecessary change" with no further explanation. The revert left keepalive() with the correct undefined check while post() regressed back to the falsy check.

Behavioral change for callers: Boolean false, null, 0, and '' values were previously dropped from FormData silently. After this fix they are included and serialized by FormData (false → 'false', null → 'null', etc.). Audited Web-Expensify callers of file upload commands — the affected falsy values are boolean false (e.g. shouldSkipSmartScan, isManualRequestScan) and undefined. PHP's Str::toBool() (used by Request::getBool) calls filter_var($input, FILTER_VALIDATE_BOOLEAN) which correctly maps the string "false"false, so behavior is unchanged.

Fixed Issues

$ https://github.com/Expensify/Expensify/issues/535855

Tests

  1. No existing automated test coverage for the FormData construction path.
  2. Verified by code trace: post() only uses FormData as settings.data when a File or Blob is present in parameters (i.e., receipt/attachment upload commands). Regular API calls are unaffected — they use settings.data = parameters (the plain object).

QA

Regression — receipt upload still works end-to-end:

  1. Log in to OldDot (expensify.com)
  2. Open DevTools → Network tab, filter by Expense_Create
  3. Go to the Expenses page and click the SmartScan / upload receipt button
  4. Upload any image file (jpg, png)
  5. In the Network tab, find the Expense_Create POST request
  6. Click the request → Payload tab → view the multipart form data body
  7. Confirm csrfToken is present with a non-empty value
  8. Confirm isManualRequestScan is present with value "false" (previously this was dropped; now it is sent as the string "false", which PHP correctly interprets as false)
  9. Confirm the receipt upload succeeds and the expense appears in the list

Regression — non-file API calls unaffected:

  1. With DevTools open, perform any regular (non-file) API action (e.g., submit a report)
  2. Confirm the request does not use multipart/form-data (it should be application/x-www-form-urlencoded or JSON)
  3. Confirm the action succeeds normally

…rmData

The falsy check `if (!value)` drops false, 0, '', null, and undefined — causing
csrfToken (and potentially other valid params) to be silently omitted from
multipart FormData requests when the value is undefined or another falsy type.

The keepalive() method in the same file already uses the correct check
`if (value === undefined)`. Aligning post() to the same guard.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Beamanator Beamanator requested a review from a team as a code owner April 10, 2026 21:10
@melvin-bot melvin-bot Bot requested review from Valforte and removed request for a team April 10, 2026 21:11
@Beamanator
Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

@Valforte Valforte merged commit f7113e0 into main Apr 13, 2026
9 checks passed
@Valforte Valforte deleted the fix-network-falsy-value-drop branch April 13, 2026 12:56
@os-botify
Copy link
Copy Markdown
Contributor

os-botify Bot commented Apr 13, 2026

🚀 Published to npm in 2.0.177 🎉

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