Bound JSON nesting before json.loads on text from the network

Open
#125 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
58/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
django, python
Domain
backend, security

Research direction

Read _token._shallow from #123, then trace _context.read_principal, _connector.py, and _jcs.py to identify every json.loads that receives network text. Add a linear depth check before parsing, using the stated limit of 64 as a reference. Done means all listed network parsing paths are bounded and the 1 MB thread test at 9,000 nesting levels confirms the process does not crash.

Written by the indexing model from the issue text.

Description

On Python 3.12 and 3.13 the json module's scanner is recursive in C, and it can exhaust a thread's stack before it raises RecursionError. On a thread with a 1 MB stack (the official Alpine images, and runserver's request threads there), a text nested about 8,000 to 9,000 levels deep crashes the process with SIGSEGV. except RecursionError is only a backstop, not a bound.

  • _context.read_principal reads an inbound Neolith-Principal with json.loads and no depth bound first. It is reached from the network once provider endpoints land (step 5, task 6).
  • Every other json.loads on text from a request or a response (_connector.py, _jcs.py) needs the same check once it receives text from a network (step 5, tasks 1 and 4).
  • Fix: check depth with a linear scan before json.loads, as _token._shallow does in #123 (limit 64 for the token header), with a test on a 1 MB thread at 9,000 levels.

Found in the review of #123.

Dominant language
Python
Stars
1
Forks
0
Avg merge
5h 30m
Merged PRs (30d)
85

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stack314/django-neolith

All issues in stack314/django-neolith

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.