Skip to content

Validate and bound plugin settings requests - #5

Merged
carochacs merged 6 commits into
mainfrom
copilot/fix-settings-post-endpoint-validation
Aug 9, 2026
Merged

Validate and bound plugin settings requests#5
carochacs merged 6 commits into
mainfrom
copilot/fix-settings-post-endpoint-validation

Conversation

Copilot AI commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

The template accepted arbitrary JSON settings bodies and persisted unknown, nested, or oversized values. This adds bounded request handling and a strict schema for the template’s settings.

  • Request limits

    • Stream request bodies with a 16 KiB cap before JSON decoding.
    • Reject invalid, negative, and oversized Content-Length values.
  • Settings schema

    • Accept only color, intensity, and enable_animations.
    • Enforce supported colors, integer intensity 0–10, and boolean animation state.
    • Normalize legacy persisted settings to defaults when values are invalid or unknown.
  • Client alignment

    • Submit enable_animations using the server key.
    • Serialize the range value as a number.
if len(body) + len(chunk) > MAX_SETTINGS_BODY_BYTES:
    return JSONResponse({"error": "request body too large"}, status_code=413)

if not all(_is_valid_setting(key, value) for key, value in incoming.items()):
    return JSONResponse(
        {"error": "body contains invalid setting values"}, status_code=400
    )

Greptile Summary

The PR bounds settings request bodies at 16 KiB and introduces strict validation for accepted and persisted values.

  • Streams request bodies with both header-based and cumulative size checks.
  • Restricts settings to the documented color, intensity, and animation schema.
  • Aligns frontend keys and numeric serialization with the server contract.

Confidence Score: 5/5

The PR appears safe to merge with no concrete correctness or security failures identified.

The request-size limit remains enforced for bodies with or without a usable Content-Length header, persisted values are normalized as described, and the frontend now submits keys and types accepted by the backend.

Important Files Changed

Filename Overview
my-plugin/routes.py Adds bounded body streaming, strict request validation, and normalization of persisted settings without an identified actionable regression.
my-plugin/settings.html Aligns the animation key and range-value type with the newly enforced backend schema.

Reviews (1): Last reviewed commit: "Sanitize invalid JSON errors" | Re-trigger Greptile

Copilot AI and others added 3 commits August 6, 2026 05:24
Co-authored-by: carochacs <79524656+carochacs@users.noreply.github.com>
Co-authored-by: carochacs <79524656+carochacs@users.noreply.github.com>
Co-authored-by: carochacs <79524656+carochacs@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix unvalidated JSON body in settings POST endpoint Validate and bound plugin settings requests Aug 6, 2026
Copilot AI requested a review from carochacs August 6, 2026 05:27
@carochacs
carochacs marked this pull request as ready for review August 6, 2026 16:50

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@my-plugin/routes.py`:
- Around line 88-136: The async set_settings handler performs blocking
filesystem work directly; move every _read(), config_dir.mkdir(), and
config_file.write_text() invocation to asyncio.to_thread and await the results.
Preserve the existing bounded-body validation and settings-update behavior while
ensuring no synchronous filesystem operation runs on the event loop.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4b1a8352-e1a1-421c-9969-41141d74cbcd

📥 Commits

Reviewing files that changed from the base of the PR and between 2bdf294 and dcd94a0.

📒 Files selected for processing (2)
  • my-plugin/routes.py
  • my-plugin/settings.html

Comment thread my-plugin/routes.py
carochacs and others added 2 commits August 6, 2026 18:33
set_settings must stay async def to stream the request body, but the
read-merge-write it did directly (_read(), config_dir.mkdir(),
config_file.write_text()) are blocking filesystem calls that would
block every concurrent request while a settings update is in flight.
Wrapped the merge+persist step in asyncio.to_thread(), matching this
repo's convention for keeping blocking work off the event loop
(CodeRabbit).
@carochacs
carochacs merged commit d645a62 into main Aug 9, 2026
5 checks passed
@carochacs
carochacs deleted the copilot/fix-settings-post-endpoint-validation branch August 9, 2026 01:48
@get-flashbacks get-flashbacks deleted a comment from coderabbitai Bot Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Settings POST endpoint accepts unvalidated/unbounded JSON body

3 participants