[PR #6904] [CLOSED] fix(captures): enforce object types and numeric bounds on HAR schemas (#6890) #7436

Closed
opened 2026-11-01 21:47:51 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/6904
Author: @bhedanikhilkumar-code
Created: 10/23/2026
Status: ❌ Closed

Base: main ← Head: fix/issue-6890-har-timings-validation


📝 Commits (1)

  • 3f9a54c fix(captures): enforce object types and numeric bounds on HAR schemas (#6890)

📊 Changes

2 files changed (+85 additions, -1 deletions)

View changed files

📝 src/browser/history/HarCapture.test.ts (+67 -0)
📝 src/browser/history/HarSchema.ts (+18 -1)

📄 Description

Summary

Fixes #6890

Enforces object types on HAR schemas that define properties or required fields without an explicit type, and registers the min keyword in the Ajv validator to enforce standard non-negative / lower-bound timing constraints in HAR 1.2 captures.

Problem and expected behavior

HAR import accepted timings: null and timing objects with negative values such as wait: -2 as successful capture records. The standard draft-06 JSON schema validator did not reject timings: null because upstream timings.json omitted "type": "object", and required / properties constraints only evaluate on object instances in draft-06. Furthermore, node_modules/har-schema specifies lower bounds using "min": -1 or "min": 0, which were ignored by Ajv under strict: false because min is not the standard draft-06 keyword (minimum).

The expected behavior is that malformed timings or cache instances (such as null or negative numbers violating min) return a typed CaptureFormatError with reason format and an accurate JSON pointer.

Change and scope

  • In src/browser/history/HarSchema.ts:
    • Registered the min keyword on Ajv to validate data >= schema for numbers, matching the constraints defined in node_modules/har-schema/lib/ (timings.json, pageTimings.json, entry.json).
    • Normalized schemas loaded from har-schema so that any schema defining properties or required without an explicit type is declared with type: "object" (specifically timings.json and cache.json).
  • In src/browser/history/HarCapture.test.ts:
    • Added unit test cases verifying rejection of null timings, null cache, negative wait, negative send, negative receive, and negative entry time with expected format error messages and pointers (/log/entries/0/timings, /log/entries/0/timings/wait, etc.).

Follow the contribution scope: Ordinary fix within existing capture decoder boundaries; maintainer scope decision is not applicable.

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/browser/history/HarSchema.ts (JSON schema validation).
  • Contribution scope fit and linked maintainer decision: not applicable (within existing capture validation boundaries).
  • CLI and MCP/tool-catalog contract: Unchanged; malformed HAR captures now fail fast with CaptureFormatError instead of producing invalid records.
  • Provider, bridge, target-format, or platform compatibility: Cross-platform Node.js; compliant with HAR 1.2 timing definitions.
  • Evidence, artifact, provenance, or reconstruction contract: Preserves valid captures while rejecting invalid timing data.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): none.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated:
    • src/browser/history/HarCapture.test.ts: Added tests verifying rejection of null timings, null cache, negative wait, send, receive, and time values with exact pointers.
  • Base reproduction or other evidence: Verified that timings: null and wait: -2 previously passed decoding and now throw typed CaptureFormatError.
  • User-visible CLI/MCP output: Malformed HAR captures fail with format error instead of returning partial or unverified records.
  • Remaining proof gaps: none.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run test:local -- src/browser/history/HarCapture.test.ts — 76 passed
  • npm run test:local -- src/browser/history/CaptureFailures.test.ts src/browser/history/CaptureRedaction.test.ts src/browser/history/HarCapture.test.ts src/browser/history/NodeCaptureAdapter.test.ts src/browser/history/QlogCapture.test.ts src/browser/history/SazMetadata.test.ts — 170 passed
  • npm run check:fast — passed (turbo typecheck and lint)

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Fixes a bug where invalid HAR records were incorrectly admitted.
  • Real Hopper/Ghidra, browser, or OS coverage: Validated across HAR decoder and tests.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: Prevents invalid or malformed network capture timings from entering analysis.

Author readiness

Human owner: @bhedanikhilkumar-code

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/6904 **Author:** [@bhedanikhilkumar-code](https://github.com/bhedanikhilkumar-code) **Created:** 10/23/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/issue-6890-har-timings-validation` --- ### 📝 Commits (1) - [`3f9a54c`](https://github.com/morluto/rea/commit/3f9a54c19c0214b6b93f1b56b5e94f0c332847a2) fix(captures): enforce object types and numeric bounds on HAR schemas (#6890) ### 📊 Changes **2 files changed** (+85 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/browser/history/HarCapture.test.ts` (+67 -0) 📝 `src/browser/history/HarSchema.ts` (+18 -1) </details> ### 📄 Description ## Summary Fixes #6890 Enforces `object` types on HAR schemas that define properties or required fields without an explicit type, and registers the `min` keyword in the Ajv validator to enforce standard non-negative / lower-bound timing constraints in HAR 1.2 captures. ## Problem and expected behavior HAR import accepted `timings: null` and timing objects with negative values such as `wait: -2` as successful capture records. The standard draft-06 JSON schema validator did not reject `timings: null` because upstream `timings.json` omitted `"type": "object"`, and `required` / `properties` constraints only evaluate on object instances in draft-06. Furthermore, `node_modules/har-schema` specifies lower bounds using `"min": -1` or `"min": 0`, which were ignored by Ajv under `strict: false` because `min` is not the standard draft-06 keyword (`minimum`). The expected behavior is that malformed timings or cache instances (such as `null` or negative numbers violating `min`) return a typed `CaptureFormatError` with reason `format` and an accurate JSON pointer. ## Change and scope - In `src/browser/history/HarSchema.ts`: - Registered the `min` keyword on `Ajv` to validate `data >= schema` for numbers, matching the constraints defined in `node_modules/har-schema/lib/` (`timings.json`, `pageTimings.json`, `entry.json`). - Normalized schemas loaded from `har-schema` so that any schema defining `properties` or `required` without an explicit `type` is declared with `type: "object"` (specifically `timings.json` and `cache.json`). - In `src/browser/history/HarCapture.test.ts`: - Added unit test cases verifying rejection of `null` timings, `null` cache, negative `wait`, negative `send`, negative `receive`, and negative entry `time` with expected format error messages and pointers (`/log/entries/0/timings`, `/log/entries/0/timings/wait`, etc.). Follow the contribution scope: Ordinary fix within existing capture decoder boundaries; maintainer scope decision is not applicable. ## Contract and boundary impact - Semantic owner and earliest changed stage: `src/browser/history/HarSchema.ts` (JSON schema validation). - Contribution scope fit and linked maintainer decision: not applicable (within existing capture validation boundaries). - CLI and MCP/tool-catalog contract: Unchanged; malformed HAR captures now fail fast with `CaptureFormatError` instead of producing invalid records. - Provider, bridge, target-format, or platform compatibility: Cross-platform Node.js; compliant with HAR 1.2 timing definitions. - Evidence, artifact, provenance, or reconstruction contract: Preserves valid captures while rejecting invalid timing data. - Target selection, authority, upstream behavior, and cleanup details (if applicable): none. - Generated metadata (`docs/public/product-catalog.json`), package, or installation impact: none. Expected effects: - [x] Read existing files or captured data. - [ ] Launch or attach to a process. - [ ] Inject instrumentation or run scripts/code. - [ ] Change process memory, registers, files, or configuration. - [ ] Contact network services. - [ ] Recover protected code or work around protections. - [ ] Documentation or usability only; no target interaction. - [ ] Not sure yet; investigation or maintainer guidance needed. ## Evidence and regression coverage - Tests added or updated: - `src/browser/history/HarCapture.test.ts`: Added tests verifying rejection of `null` timings, `null` cache, negative `wait`, `send`, `receive`, and `time` values with exact pointers. - Base reproduction or other evidence: Verified that `timings: null` and `wait: -2` previously passed decoding and now throw typed `CaptureFormatError`. - User-visible CLI/MCP output: Malformed HAR captures fail with `format` error instead of returning partial or unverified records. - Remaining proof gaps: none. For evidence-bearing changes: - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed - `npm run test:local -- src/browser/history/HarCapture.test.ts` — 76 passed - `npm run test:local -- src/browser/history/CaptureFailures.test.ts src/browser/history/CaptureRedaction.test.ts src/browser/history/HarCapture.test.ts src/browser/history/NodeCaptureAdapter.test.ts src/browser/history/QlogCapture.test.ts src/browser/history/SazMetadata.test.ts` — 170 passed - `npm run check:fast` — passed (turbo typecheck and lint) ## Compatibility, safety, and release - Breaking changes or migration steps: none. Fixes a bug where invalid HAR records were incorrectly admitted. - Real Hopper/Ghidra, browser, or OS coverage: Validated across HAR decoder and tests. - Package or release metadata impact: none. - Security, privacy, process, or containment review: Prevents invalid or malformed network capture timings from entering analysis. ## Author readiness Human owner: @bhedanikhilkumar-code - [x] I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. ## Before merge - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [x] The PR has one focused outcome and the title follows `type(scope): outcome`. - [x] Related issue is linked, or the reason for not linking one is stated above. - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] Owning docs, contracts, and generated metadata are updated where needed. - [x] User-visible CLI/MCP changes include representative output. - [x] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-01 21:47:51 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#7436
No description provided.