fix(respect): record request bodies in the HAR postData entry - #2992
Conversation
🦋 Changeset detectedLatest commit: d0c4d82 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@ariesclark If I understand correctly, the main issue is that the postData field is missing. Is that right? |
|
From the description: Actually, the HAR is passed through conditionallyMaskSecrets before being written |
Yup, that's right, |
|
Hi @ariesclark, |
There was a problem hiding this comment.
Pull request overview
This PR fixes HAR capture for respect --har-output so request bodies are recorded in the HAR request.postData field (instead of always {}), enabling downstream tools like drift to validate request bodies rather than treating missing data as a pass.
Changes:
- Add
buildPostData()to serialize text request bodies and derivemimeTypefrom the requestcontent-typeheader. - Wire
postData(andrequest.bodySizebased on serialized text length) into the HAR entry produced bywithHar. - Add unit tests for
buildPostDataand a changeset documenting the fix.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/cli/src/commands/respect/har-logs/with-har.ts | Uses buildPostData() and populates request.bodySize/request.postData in HAR entries. |
| packages/cli/src/commands/respect/har-logs/helpers/build-post-data.ts | New helper to produce HAR postData for string/URLSearchParams bodies and determine mimeType. |
| packages/cli/src/tests/commands/respect/har-logs/helpers/build-post-data.test.ts | New unit tests covering header shapes, fallbacks, and omitted non-text bodies. |
| .changeset/respect-har-post-data.md | Patch changeset describing the HAR postData fix for @redocly/cli. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a927ba4. Configure here.
Performance Benchmark (Lower is Faster)
|

What/Why/How?
withHarrecordedpostData: {}for every request, so a HAR fromrespect --har-outputnever contained the request body. Replaying that capture throughdriftskips request-body validation and reports no problems. Missing data reads as a pass.buildPostDataserializes the body and reads the mime type from the request'scontent-type, going throughbuildHeadersso it treats every header shape alike. It records only text bodies, omittingFormData, streams, and binary rather than stringifying them to[object Object].request.bodySizenow carries the byte length instead of-1.Reference
None.
Testing
build-post-data.test.tscovers the content-type sources, theapplication/octet-streamfallback, and the cases that must record nothing: no body, empty string,Buffer,FormData, plain object.Check yourself
Security
The HAR now stores request bodies verbatim, so capturing a login flow puts credentials in the file. The capture already recorded headers and response bodies unmasked, so this widens an existing exposure rather than adding a new kind.
Note
Low Risk
Scoped to HAR logging in
respect; it persists request bodies in capture files (including possible secrets), extending exposure similar to headers/responses already recorded.Overview
respect --har-outputnow writes request bodies into each HAR entry’spostData, instead of always emitting an empty object, so replays (e.g. throughdrift) can validate request bodies instead of treating missing data as success.A new
buildPostDatahelper serializes string andURLSearchParamsbodies, resolvesContent-Typevia the samebuildHeaderspath as the rest of the HAR entry (including casing and alternate header shapes), and falls back toapplication/octet-streamor form-urlencoded when appropriate. It skips bodies it cannot represent safely (empty/no body,Buffer,FormData, plain objects).withHaruses that helper and setsrequest.bodySizefrom the recorded text when possible, or0/-1when there is no body vs. a body that was not recorded.Unit tests cover content-type handling, fallbacks, and omit cases.
Reviewed by Cursor Bugbot for commit d0c4d82. Bugbot is set up for automated code reviews on this repo. Configure here.