Skip to content

fix: enforce _MAX_DATA_BYTES limit on learning-path payloads#1208

Open
mrudulaa11 wants to merge 1 commit into
komalharshita:mainfrom
mrudulaa11:fix/learning-path-payload-size-limit
Open

fix: enforce _MAX_DATA_BYTES limit on learning-path payloads#1208
mrudulaa11 wants to merge 1 commit into
komalharshita:mainfrom
mrudulaa11:fix/learning-path-payload-size-limit

Conversation

@mrudulaa11

Copy link
Copy Markdown

Summary [required]

_MAX_DATA_BYTES was defined in src/routes/main_routes.py with a comment
stating it guards against oversized payloads, but it was never actually
checked anywhere. This PR wires it up.

Related Issue [required]

Closes #1137

Type of Change [required]

  • Bug fix — resolves a broken behaviour
  • Feature — adds new functionality
  • Data — adds new projects to data/projects.json
  • Documentation — updates docs, README, or code comments only
  • Style — CSS or visual changes only, no logic change
  • Refactor — restructures code without changing behaviour
  • Test — adds or updates tests

What Was Changed [required]

File Change made
src/routes/main_routes.py Added _payload_too_large() helper; called it in create_path() and update_path() before JSON parsing, returning 400 when the raw body exceeds _MAX_DATA_BYTES (64KB)
tests/test_basic.py Added 4 new tests: oversized POST rejected, oversized PUT rejected, within-limit POST succeeds, within-limit PUT succeeds

How to Test This PR [required]

  1. Clone this branch: git checkout fix/learning-path-payload-size-limit
  2. Install dependencies: pip install -r requirements.txt
  3. Run the app: python app.py
  4. Send a POST to /api/learning-path/test123 with header X-Learning-Path-Token: anytoken and a JSON body over 64KB — confirm you get a 400 with a size-limit error instead of 201
  5. Run the tests: python -m pytest tests/test_basic.py -v

Self-Review Checklist [required]

  • I have read CONTRIBUTING.md and followed all guidelines
  • My branch name follows the convention: fix/learning-path-payload-size-limit
  • I have run python -m pytest tests/test_basic.py and all tests pass
  • I have run flake8 . locally and there are no errors
  • I have not introduced any print() or console.log() debug statements
  • Every new function I wrote has a docstring
  • I have not modified files outside the scope of the linked issue
  • If I changed the UI, I tested it at 375px (mobile) and 1280px (desktop) — N/A, backend-only change
  • If I added a project to the dataset, it has all required JSON fields — N/A

Notes for Reviewer

None.

The 64KB size guard defined in main_routes.py was never actually
referenced by create_path() or update_path(), leaving learning-path
requests with no enforced size limit.

- Add _payload_too_large() helper that checks the raw request body
  against _MAX_DATA_BYTES before JSON parsing
- Call it in both create_path() (POST) and update_path() (PUT)
- Return 400 with a descriptive error when the limit is exceeded
- Add tests covering oversized POST/PUT payloads and confirm
  within-limit requests are unaffected

Fixes komalharshita#1137
@vercel

vercel Bot commented Jun 27, 2026

Copy link
Copy Markdown

@mrudulaa11 is attempting to deploy a commit to the komalsony234-1530's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thank you for submitting your first pull request to DevPath.

Before review:

  • Complete the PR template fully
  • Ensure all tests pass
  • Link your PR to an issue
  • Keep changes scoped to the issue

A maintainer will review your contribution soon.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: _MAX_DATA_BYTES constant in learning-path routes is defined but never enforced

1 participant