Skip to content

fix(e2b): correct query parsing for ListSandboxes filters - #821

Open
AnshulPatil2005 wants to merge 1 commit into
openkruise:masterfrom
AnshulPatil2005:fix/e2b-list-query-parsing
Open

fix(e2b): correct query parsing for ListSandboxes filters#821
AnshulPatil2005 wants to merge 1 commit into
openkruise:masterfrom
AnshulPatil2005:fix/e2b-list-query-parsing

Conversation

@AnshulPatil2005

Copy link
Copy Markdown

I. Describe what this PR does

Three fixes in parseListSandboxesRequest, all from #804.

r.URL.Query() has already unescaped the query, so the extra url.QueryUnescape on metadata decoded it a second time. Dropped.

The loop read only values[0], so a repeated parameter lost everything after the first. state and metadata now read every value. state still accepts the comma separated form as well.

An invalid state reported the whole parameter instead of the token that failed, so state=running,foo said not: 'running,foo'. It now names foo.

The default branch is left alone. It maps an unknown parameter to a single metadata key, and a map holds one value per key either way, so picking values[0] over the last one is arbitrary rather than wrong.

II. Does this pull request fix one issue?

fixes #804

III. Describe how to verify it

go test ./pkg/servers/e2b/ -run TestParseListSandboxesRequest -count=1

Four of the seven cases fail on master and pass here. The other three cover behaviour that should not change: the comma separated state form, encoded separators still splitting into pairs, and forbidden metadata keys still being rejected.

IV. Special notes for reviews

One correction to the issue. It gives ?metadata=progress=100% as the repro for the 400, but a bare % never reaches this function: url.ParseQuery fails on the invalid escape and r.URL.Query() drops the parameter, so metadata is silently empty and no error is returned.

The 400 comes from the opposite case, a correctly encoded value. ?metadata=note=50%25off arrives here already decoded to note=50%off, and the second unescape then reads %of as an escape sequence and fails. So the bug is real but it hits clients that encode properly rather than clients that do not, which seemed worth getting right in the test. That case is percent sign in a metadata value survives.

TestParseCreateSandboxRequest, TestCreateSandbox and TestCloneSandbox fail for me on a clean master too, so they look unrelated to this.

@kruise-bot
kruise-bot requested review from AiRanthem and zmberg August 14, 2026 09:44
@kruise-bot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign zmberg for approval by writing /assign @zmberg in a comment. For more information see:The Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.81818% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.10%. Comparing base (1781b7c) to head (afb4dc4).

Files with missing lines Patch % Lines
pkg/servers/e2b/list.go 81.81% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #821      +/-   ##
==========================================
+ Coverage   83.08%   83.10%   +0.01%     
==========================================
  Files         259      259              
  Lines       22555    22552       -3     
==========================================
+ Hits        18739    18741       +2     
+ Misses       3093     3089       -4     
+ Partials      723      722       -1     
Flag Coverage Δ
unittests 83.10% <81.81%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AnshulPatil2005
AnshulPatil2005 force-pushed the fix/e2b-list-query-parsing branch from d35dea5 to 845e812 Compare September 4, 2026 04:27
r.URL.Query() has already unescaped the query, so the extra
url.QueryUnescape on metadata decoded it twice. A value carrying an encoded
percent sign arrived as "%" and was then read as the start of a new escape,
failing the request with 400 invalid URL escape.

The loop also read only values[0], so a repeated parameter silently lost
everything after the first: state=running&state=paused filtered on running
alone, and a second metadata parameter was dropped.

An invalid state reported the whole parameter rather than the token that was
rejected.

Drop the second unescape, read every value, and name the offending token.

Fixes openkruise#804

Signed-off-by: Anshul <anshulpatil1022@gmail.com>
@AnshulPatil2005
AnshulPatil2005 force-pushed the fix/e2b-list-query-parsing branch from 845e812 to afb4dc4 Compare September 5, 2026 20:57
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] E2B ListSandboxes API fails on metadata with special characters and drops repeated query parameters

2 participants