Skip to content

Parser: empty-value query params (e.g. prefix=) incorrectly converted to "1" (bare-key heuristic) #200

Closed

Description

@scttfrdmn

Summary

In parser.go, the params-building loop converts any empty-string query-parameter value to "1" using the comment "bare key (e.g. ?uploads, ?versions)". However, Go's r.ParseForm() cannot distinguish a true bare key (?uploads) from a key with an explicitly empty value (?prefix=) — both produce an empty string value. As a result, prefix= is stored as prefix=1, which breaks ListObjectsV2 when the AWS SDK sends an explicit empty prefix.

Reproduction

// AWS SDK Go v2 sends: GET /<bucket>?list-type=2&prefix=&delimiter=%2F
// When Prefix: aws.String("") is passed to ListObjectsV2Input.
s3c.ListObjectsV2(ctx, &s3.ListObjectsV2Input{
    Bucket:    aws.String("my-bucket"),
    Prefix:    aws.String(""),   // explicitly empty
    Delimiter: aws.String("/"),
})
// Returns: CommonPrefixes=[] Contents=[] — all objects filtered out
// Expected: CommonPrefixes=[...] based on delimiter grouping

Root Cause

// parser.go (current)
if v == "" {
    v = "1" // bare key (e.g. ?uploads, ?versions)
}
params[k] = v

?prefix= → r.Form["prefix"] = [""] → converted to "1".
In listObjectsV2: prefix = "1", filtering out all objects that don't start with "1".

Fix

Parse r.URL.RawQuery manually to distinguish true bare keys (no = sign) from empty-value keys (have =):

// Only upgrade to "1" when the raw query actually has no "=" for this key.
barKeys := parseBareKeys(r.URL.RawQuery) // set of keys with no "="
for k, vs := range r.Form {
    v := ""
    if len(vs) > 0 { v = vs[0] }
    if v == "" && barKeys[k] { v = "1" }
    params[k] = v
}

Alternatively, only apply the bare-key heuristic for a known whitelist of S3 operation keys: uploads, delete, acl, tagging, versioning, versions, notification, lifecycle, policy, cors.

Context

Discovered while running Canopy integration tests. TestIntegration_S3_BrowseObjects calls liveBrowseObjects → ListObjectsV2 with Prefix: aws.String("") → prefix= in query → filtered to nothing.

Workaround applied in Canopy: omit Prefix from the input when it's empty string (use nil instead of aws.String("")). But this is a latent substrate bug that will affect any other AWS SDK client sending empty-string query parameters.

Activity

  1. scttfrdmn commented on Mar 18, 2026

    @scttfrdmn
    OwnerAuthor

    Fixed in v0.36.5. The raw query string is now inspected to build an explicitEmpty set before iterating r.Form, so keys like ?prefix= are correctly preserved as "" while true bare keys like ?uploads continue to map to "1".

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions