fix(gnoweb): In serveEval, use MaxBytesReader to cap the JSON size#5897
Open
jefft0 wants to merge 3 commits into
Open
fix(gnoweb): In serveEval, use MaxBytesReader to cap the JSON size#5897jefft0 wants to merge 3 commits into
jefft0 wants to merge 3 commits into
Conversation
Signed-off-by: Jeff Thompson <jeff@thefirst.org>
Collaborator
🛠 PR Checks SummaryAll Automated Checks passed. ✅ Manual Checks (for Reviewers):
Read More🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers. ✅ Automated Checks (for Contributors):No automated checks match this pull request. ☑️ Contributor Actions:
☑️ Reviewer Actions:
📚 Resources:Debug
|
…ession Signed-off-by: Jeff Thompson <jeff@thefirst.org>
13 tasks
davd-gzl
approved these changes
Jul 3, 2026
davd-gzl
left a comment
Member
There was a problem hiding this comment.
Verified on ee9f7e0: each cap rejects the oversized input it guards, and an expression at the 64 KiB limit still passes. The suite covers none of these paths.
The sizes you asked about are fine: real pkg paths are dozens of bytes and expressions are short calls, so 1024 and 64 KiB leave plenty of headroom.
| return | ||
| } | ||
|
|
||
| r.Body = http.MaxBytesReader(w, r.Body, maxEvalBodyBytes) |
Member
There was a problem hiding this comment.
Missing test: the three new caps have no coverage. Add to TestHandlerPlaygroundEval:
test cases
{
name: "oversized body",
method: http.MethodPost,
body: `{"pkg_path":"r/x","expression":"` + strings.Repeat("a", maxEvalBodyBytes+1) + `"}`,
wantStatus: http.StatusBadRequest,
wantError: "invalid request body",
},
{
name: "oversized pkg_path",
method: http.MethodPost,
body: `{"pkg_path":"` + strings.Repeat("a", maxEvalPkgPathLen+1) + `","expression":"Render(\"\")"}`,
wantStatus: http.StatusBadRequest,
wantError: "too long",
},
{
name: "oversized expression",
method: http.MethodPost,
body: `{"pkg_path":"r/x","expression":"` + strings.Repeat("a", maxEvalExpressionLen+1) + `"}`,
wantStatus: http.StatusBadRequest,
wantError: "too long",
},
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In the spirit of "small PRs against the playground2 branch", this PR fixes this comment from @alexiscolin . We put new constants like
maxEvalBodyBytesnext to the other constants likemaxForkCodeSize.Following the comment from @moul, we also limit the size of
req.PkgPathto 1024 andreq.Expressionto 64K. Are these good sizes?