Skip to content

Guard JSON tree renderer against deep and oversized payloads#2

Open
baanish wants to merge 1 commit intomainfrom
codex/fix-client-side-dos-in-json-rendering
Open

Guard JSON tree renderer against deep and oversized payloads#2
baanish wants to merge 1 commit intomainfrom
codex/fix-client-side-dos-in-json-rendering

Conversation

@baanish
Copy link
Owner

@baanish baanish commented Mar 9, 2026

Motivation

  • The JSON tree renderer previously expanded every nested object/array with no depth or node-count guard, which allows an attacker to craft deeply nested or very large JSON payloads that can cause excessive recursion/DOM creation and a client-side denial of service.

Description

  • Add src/lib/json/tree-limits.ts which exports MAX_TREE_DEPTH, MAX_TREE_NODES, and exceedsTreeLimits, using an iterative traversal to detect excessive depth or node counts without recursion.
  • Update src/components/renderers/json-renderer.tsx to parse the artifact, check exceedsTreeLimits, and when the payload is too large show a clear message and fall back to the Raw/code view instead of rendering the full tree.
  • Add unit tests in tests/json-tree-limits.test.ts that verify small payloads are allowed and that overly deep or overly large payloads are blocked.
  • The guard is implemented as a lightweight, reusable pre-check to preserve existing tree rendering for safe payloads while preventing unbounded DOM expansion.

Testing

  • Ran npm test and all tests passed, including the new tests/json-tree-limits.test.ts.
  • Ran npm run lint and the linter completed successfully.
  • Ran npm run typecheck and TypeScript checks completed successfully.

Codex Task

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 9, 2026

Deploying agent-render with  Cloudflare Pages  Cloudflare Pages

Latest commit: d3c9729
Status: ✅  Deploy successful!
Preview URL: https://c4462930.agent-render.pages.dev
Branch Preview URL: https://codex-fix-client-side-dos-in.agent-render.pages.dev

View logs

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 9, 2026

Warning

Rate limit exceeded

@baanish has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 29 minutes and 8 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b965350b-b4ec-4ac9-bf82-3cea2a3cb30c

📥 Commits

Reviewing files that changed from the base of the PR and between 7cab153 and d3c9729.

📒 Files selected for processing (3)
  • src/components/renderers/json-renderer.tsx
  • src/lib/json/tree-limits.ts
  • tests/json-tree-limits.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/fix-client-side-dos-in-json-rendering

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@kilo-code-bot
Copy link

kilo-code-bot bot commented Mar 9, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Overview

This PR adds security improvements to protect against DoS attacks from large JSON payloads by implementing tree depth and node count limits.

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 0

Security Assessment

The implementation correctly:

  • Uses an iterative stack-based traversal (avoids stack overflow)
  • Checks both depth (MAX_TREE_DEPTH = 64) and node count (MAX_TREE_NODES = 5000) limits
  • Gracefully falls back to raw view when limits are exceeded
  • Handles parse errors without accessing the tree limit property

Code Quality

  • Clean separation of concerns with new tree-limits.ts module
  • Type safety maintained with exported JsonValue type
  • Good test coverage for edge cases
Files Reviewed (3 files)
  • src/components/renderers/json-renderer.tsx - Modified to add tree limit checks
  • src/lib/json/tree-limits.ts - New file with limit checking logic
  • tests/json-tree-limits.test.ts - New test file

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d3c9729a16

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +25 to +27
const entries = Array.isArray(current.value) ? current.value : Object.values(current.value);
for (const entry of entries) {
stack.push({ value: entry, depth: current.depth + 1 });

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Enforce node cap while expanding children

The size guard still does unbounded work for very wide payloads because exceedsTreeLimits pushes every child from entries before checking visitedNodes again, so an object/array with hundreds of thousands of top-level items will allocate a huge stack and can still freeze the UI even when maxNodes is small. This undermines the protection added in this commit for oversized JSON, since the expensive expansion happens before the function can return true.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant