Skip to content

fix(iam): decode query-protocol scalar parameters (#642) - #643

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/iam-numeric-params
Aug 14, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/iam-numeric-params

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #642

What was broken

MaxItems failed every paginated IAM operation with 400 ValidationError, and
CreateRole rejected MaxSessionDuration. Through the Go SDK:

operation error IAM: ListUsers, StatusCode: 400, api error ValidationError:
invalid request body: json: cannot unmarshal string into Go struct field .MaxItems of type int

Why

The same root cause as #639, one layer along. IAM speaks the query protocol, so
ParseAWSRequest flattens the form body into AWSRequest.Params (map[string]string) and
server.go:583-589 rebuilds req.Body as json.Marshal(req.Params) — every value in that
JSON object is a string. A handler field declared int made encoding/json refuse the
whole request. Where #639's lists unmarshaled to nil in silence, an integer took the request
down with it.

The fix

iamInt and iamBool in emulator/iam_query.go accept either a JSON number or a numeric
JSON string. All 14 MaxItems declarations and MaxSessionDuration now use iamInt.
iamBool lands unused so #497's OnlyAttached is not built with the defect already in it.

Both shapes are accepted rather than only the string, because iamRequest
(iam_plugin_test.go:40) hand-marshals a real JSON number — that asymmetry is precisely what
hid this.

An empty value is the zero value rather than an error: a client that sent MaxItems=
expressed no limit, and refusing it would fail a request AWS accepts. A malformed value now
names its parameter — MaxItems must be an integer, got "abc" — carried through a
*json.UnmarshalTypeError, which is the one error type encoding/json annotates with the
field path it was decoding (and it nests correctly for a scalar inside a list member).

How it was found, and why no test caught it

By probing ListUsers(MaxItems: 1) through the SDK while building #579. That makes this the
third defect of the #561/#610/#636/#639 class. The unit suite structurally cannot see it:
iamRequest sends the one shape no AWS client produces, and the IAM journeys that do go
through the SDK never passed MaxItems, because pagination is asserted at the unit level
where the number is real.

test/e2e/journey_iam_numbers_test.go closes that: MaxItems across two pages (asserting
the pages are disjoint and complete, so a Marker that silently restarted still fails) and
MaxSessionDuration round-tripped through GetRole. Verified to fail against the pre-fix
code
by reverting listUsers and re-running — it reproduces the 400 above.

Gates

gofmt -l . clean · go build ./... · go vet ./... · golangci-lint run ./... → 0
issues
· make test (race) · make coverage → emulator 82.3%, total 81.6% ·
go vet -C test/e2e ./... && go test -C test/e2e ./...

MaxItems failed every paginated IAM operation with 400 ValidationError, and
CreateRole rejected MaxSessionDuration. Same root cause as #639, one layer
along: the query protocol has no types, so server.go rebuilds req.Body as
json.Marshal(req.Params) over a map[string]string and MaxItems=1 arrives as
{"MaxItems":"1"}. A field declared `int` made encoding/json refuse the whole
request. Where #639's lists unmarshaled to nil silently, an integer took the
request down with it.

iamInt and iamBool in iam_query.go accept either a JSON number or a numeric
JSON string; all 14 MaxItems fields and MaxSessionDuration now use iamInt.
iamBool lands unused so #497's OnlyAttached is not built with the defect
already in it. An empty value is the zero value, not an error — a client that
sent MaxItems= expressed no limit. A malformed value names its parameter via a
json.UnmarshalTypeError, which is the one error type encoding/json annotates
with the field path it was decoding, so the message is "MaxItems must be an
integer, got \"abc\"" rather than a Go struct field.

Found by probing ListUsers(MaxItems: 1) through the SDK while building #579,
which makes this the third defect of the class. The unit suite cannot see it:
iamRequest hand-marshals a body holding a real JSON number, the one shape no
AWS client produces, and the IAM journeys never passed MaxItems because
pagination is asserted at the unit level where the number is real.
journey_iam_numbers_test.go closes that — it fails against the pre-fix code
with exactly the 400 above, verified by reverting listUsers and re-running.

Gates: gofmt clean, go build, go vet, golangci-lint 0 issues, make test
(race), coverage 82.3% emulator / 81.6% total, test/e2e vet+test.
@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.22222% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/iam_query.go 95.74% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit a6c6140 into main Aug 14, 2026
13 checks passed
@scttfrdmn
scttfrdmn deleted the fix/iam-numeric-params branch August 14, 2026 23:55
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.

IAM MaxItems and MaxSessionDuration are rejected over the wire: a query-protocol integer arrives as a string

1 participant