Skip to content

API Gateway: state structs are marshalled straight to the wire, so responses are PascalCase and carry substrate's internal AccountID/Region #529

Closed

Description

@scttfrdmn

Summary

APIGatewayRestAPI and its sibling types are marshalled directly onto the wire from their state representation, so API Gateway responses have two defects at once:

  1. PascalCase members, where the API Gateway API uses camelCase — the same defect as Logs: DescribeLogGroups/DescribeLogStreams/GetLogEvents return PascalCase members, so an SDK parses every field to null #528 in CloudWatch Logs, with the same consequence: an SDK matches response members case-sensitively against the service model, so every field parses to nothing and the caller gets an empty object with HTTP 200 and no error.
  2. Substrate's internal state fields on the wire. AccountID and Region are the plugin's own state-partitioning fields. They are not members of any documented API Gateway type, and no real endpoint returns them. That is inventing observations, which docs/fidelity.md forbids — a consumer could read response["AccountID"] and build a test on a field that will never exist in AWS.

Found while sweeping #528 for the "is this systematic?" question the reporter asked. It is not repo-wide; it is the specific plugins that reuse one struct for both state and wire.

Raw wire

$ curl -s -X POST localhost:4599/restapis -d '{"name":"api2"}'
{"Id":"igiaehgppe","Name":"api2","RootResourceId":"agihcnfekb",
 "CreatedDate":"2026-08-02T21:07:48.020895708-07:00",
 "AccountID":"000000000000","Region":"us-east-1"}

$ curl -s localhost:4599/restapis
{"items":[{"Id":…,"Name":…,"RootResourceId":…,"CreatedDate":…,"AccountID":…,"Region":…}]}

Per the RestApi reference the members are id, name, rootResourceId, createdDate, description, tags, version, binaryMediaTypes, apiKeySource, policy, minimumCompressionSize, disableExecuteApiEndpoint, endpointConfiguration, warnings — all camelCase, and neither AccountID nor Region among them.

Note the envelope key items is already correct, exactly as in #528: the envelopes are declared inline per handler with proper tags, and only the elements are wrong.

Cause

emulator/apigateway_types.go:11 onward tags every member PascalCase (json:"Id", json:"Name", json:"RootResourceId", json:"AccountID", json:"Region") because the struct is the state representation — json.Marshal(api) → state.Put at emulator/apigateway_plugin.go:423. The same value is then embedded in the response. 75 PascalCase tags across the file, so this is not three slips.

emulator/apigatewayv2_types.go has 53 and needs the same check; API Gateway v2's API is also camelCase.

Scope of the sweep

Also affected by the internal-field leak, though not by the casing (its API is natively PascalCase, so its casing is correct):

  • MSK — GET /v1/clusters returns AccountID and Region on every cluster (emulator/msk_types.go:25).

Confirmed clean — correct casing, no leak, because they build response types separately from state: ECS, ECR, Step Functions, Batch, Kinesis, EFS, Glue, Secrets Manager, SQS, CloudWatch.

Acceptance criteria

  • GetRestApis/GetRestApi/CreateRestApi and the Resource, Method, Deployment, Stage, Authorizer, ApiKey, UsagePlan types put camelCase members on the wire, verified against each type's API reference rather than inferred.
  • No response carries AccountID or Region, in API Gateway or in MSK.
  • Same check applied to API Gateway v2 (emulator/apigatewayv2_types.go), whose API is also camelCase.
  • State encoding is unchanged, or the changelog states the change. Follow Logs: DescribeLogGroups/DescribeLogStreams/GetLogEvents return PascalCase members, so an SDK parses every field to null #528's approach: keep the state struct and give each read operation a response-only element type, so state and wire cannot be conflated again.
  • Regression tests assert on raw JSON bytes, not a Go round-trip. A struct marshalled and unmarshalled by the same definition agrees with itself whatever the casing, which is why the existing tests pass today; only a wire-level assertion sees the mismatch. Include a negative assertion on "AccountID".
  • docs/services.md API Gateway section reviewed for any documented member name that was wrong.

Related

Activity

  1. added
    type: bug
    priority: medium
    on Aug 3, 2026
  2. modified the milestones: v0.89.0, v0.90.0 on Aug 3, 2026
  3. scttfrdmn commented on Aug 3, 2026

    @scttfrdmn
    OwnerAuthor

    Moved to v0.90.0. v0.89.0 is scoped to the CloudFormation delete/rollback cluster
    (#518, #508, #534, #520) — a resource sweep plus the two S3 leaks it would inherit and
    the rollback blocked on its dispatcher. Those four are one coupled model; this issue is
    a separate plugin and a separate mechanism, so it gains nothing from riding along and
    would widen a release that is already a large behaviour change.

    Nothing in v0.88.0 changed the analysis here. v0.88.0 fixed the same defect shape in
    CloudWatch Logs (#528) by giving each read a response-only element type rather than
    retagging the state struct — that is the pattern this fix should follow, and #528's
    emulator/cloudwatchlogs_types.go is now a worked example of it, including why the
    state encoding must be left alone (snapshot round-trips and event replay).

  4. modified the milestones: v0.90.0, v0.91.0 on Aug 4, 2026
  5. scttfrdmn commented on Aug 4, 2026

    @scttfrdmn
    OwnerAuthor

    Moved to v0.91.0. v0.90.0 is scoped to the silent-wrong-observable cluster
    (#544, #532, #551, #542, #530, #545) plus #455; this issue is the single largest item
    on the board and it has a prerequisite that was not known when it was filed.

    Measured size. 75 PascalCase json tags in emulator/apigateway_types.go, 53 in
    apigatewayv2_types.go, 24 in msk_types.go — 152 tags across 18 types in 3
    files
    . The leak is confirmed live rather than inferred:

    $ aws apigateway create-rest-api --name api4      # prints nothing at all
      raw body: {"Id":"nbbgnpikbk","Name":"api4","RootResourceId":"jkehkjkgna",
                 "CreatedDate":"…","AccountID":"123456789012","Region":"us-east-1"}
    
    $ aws kafka list-clusters
      …"KafkaVersion":"3.5.1","AccountID":"123456789012","Region":"us-east-1",…
    

    The CLI printing nothing for create-rest-api is this issue's symptom in its
    purest form: every member parses to nothing, so botocore returns an empty object with
    HTTP 200 and no error.

    The prerequisite — API Gateway v2 is unreachable over the wire. The acceptance
    criterion "same check applied to API Gateway v2" cannot be verified end to end today,
    because APIGatewayV2Plugin cannot be reached from an SDK at all:

    $ aws apigatewayv2 create-api --name h2 --protocol-type HTTP
    An error occurred (NotFoundException) … APIGatewayPlugin: unknown operation for POST /v2/apis
    

    Both the v1 and v2 clients sign with the same SigV4 service name —
    Credential=…/us-east-1/apigateway/aws4_request for each, confirmed with --debug —
    and emulator/parser.go's alias map has no apigatewayv2 entry, so every v2 request
    routes to APIGatewayPlugin. APIGatewayV2Plugin is registered
    (emulator/plugins.go:277) and has a full test file, but
    apigatewayv2_plugin_test.go calls p.HandleRequest directly — in-process only,
    which is why this has never shown up as a failure.

    Routing v2 by path (/v2/… under the shared apigateway signing name) is the likely
    shape, since the signing name cannot distinguish them. That fix belongs in the same
    release as this one: without it, the v2 half of this issue is unverifiable.

    Not filing the routing gap separately — it is a precondition of this issue's own
    acceptance criteria, and splitting it would just create a blocked pair.

  6. scttfrdmn commented on Aug 4, 2026

    @scttfrdmn
    OwnerAuthor

    Verified before implementing — three corrections to this issue

    Measured against main (31cff92) by running botocore's own parser and
    serializer
    (create_parser / create_serializer from awscli.botocore) against
    substrate's actual response bodies, plus a live server on :4620. Three findings
    change the work this issue describes, so recording them before opening the PRs.

    1. The items envelope is not already correct

    This issue says "the envelope key items is already correct … only the elements
    are wrong."
    It is not. Every v1 list operation's items member carries
    locationName: "item", singular. Asked directly:

    • {"items":[{"id":"a1"}]} → botocore parses {}
    • {"item":[{"id":"a1"}]} → parses

    So the envelope and the members are wrong, and seven of substrate's eight v1
    list handlers must emit item.

    One exception, which a blanket rename would break: GetStages' member is
    natively item, and apigateway_plugin.go:887 already emits item — it is
    the one handler that is right today. A regression gate for it is part of the fix.

    A third spelling exists: Usage.items -> "values". Not routed in substrate, so
    it is a docs note rather than code.

    2. MSK's casing is broken too, not merely leaking

    This issue says MSK is not affected by the casing, "its API is natively
    PascalCase, so its casing is correct"
    , and flags only the AccountID/Region
    leak. The kafka model is rest-json with 579 lowercase response keys and 0
    uppercase
    . Asked directly:

    • {"ClusterInfoList":[…]} → {}
    • {"clusterInfoList":[…]} → parses

    Confirmed live: aws kafka list-clusters returns nothing today. MSK v2 is affected
    identically — mskV2ClusterInfo (msk_plugin.go:283) hand-builds a PascalCase
    map, so being hand-written did not make it correct.

    MSK also emits "SecurityGroups":null and "VolumeSize":0 for want of
    omitempty; real MSK omits an unset member, and absent-vs-null is a real
    observable.

    3. The "confirmed clean" list holds, but the stated reason is wrong

    The list itself is correct — verified live that ecs describe-clusters,
    ecr describe-repositories, stepfunctions describe-state-machine and
    logs describe-log-groups all parse fully. But the reason given for MSK above —
    that a json-protocol service is natively PascalCase — is false in general:
    ECS's response wire is 1099 lowercase / 0 uppercase, Step Functions 401/0,
    ECR 417/2. Those plugins are clean because they hand-build camelCase response
    maps
    and never marshal a state struct.

    So the detector for this defect class is "does the plugin marshal a state struct
    onto a lowercase wire"
    , not "is the wire PascalCase".

    Blast radius, measured

    Swept all 41 emulator/*_types.go files, comparing each member's effective wire
    key
    (locationName if present, else the member name) over every shape
    transitively reachable from an operation's output, against substrate's JSON tags.

    Exactly three plugins marshal a PascalCase state struct onto a lowercase JSON
    wire: apigateway, apigatewayv2, msk. There is no fourth. cloudwatchlogs
    scored suspect and is a false positive — #528's cwLogGroupOut /
    cwLogStreamOut / cwOutputLogEventOut are already in place.

    The leak is broader than the casing: 29 files carry a json:"AccountID" or
    json:"Region" tag, but only these three put them on the wire. Elsewhere they are
    state-only and correct — the other 26 must not be swept.

    Why this stayed invisible: Go's json.Unmarshal matches keys
    case-insensitively, so the request side works despite the PascalCase tags (a
    camelCase create-rest-api / create-cluster body populates every field — checked
    live). This is a response-only fix, as the issue says.

    The API Gateway v2 routing prerequisite, now with the measurement

    Recorded in the deferral comment above; confirming it is in scope for v0.91.0
    and that the discriminator is provably safe rather than merely plausible.

    aws apigatewayv2 create-api still fails with
    NotFoundException: APIGatewayPlugin: unknown operation for POST /v2/apis. Route
    on the path, because the SigV4 scope cannot discriminate — v2's signingName
    is apigateway. From the two models' URI spaces: v2's requestUris are
    103/103 under /v2/, and v1's — /account, /apikeys,
    /clientcertificates, /domainnames, /domainnameaccessassociations,
    /rejectdomainnameaccessassociations, /restapis, /sdktypes, /tags,
    /usageplans, /vpclinks — include none under /v2/. So /v2/ →
    apigatewayv2 cannot misroute a v1 call. The step will be scoped to the case
    where the request otherwise resolves to apigateway, so it cannot capture an
    unrelated service that happens to use a /v2/ path.

    A second plugin turned out to be unreachable in the same way and is filed
    separately, since it is a distinct service and not a precondition of this issue.

  7. scttfrdmn commented on Aug 4, 2026

    @scttfrdmn
    OwnerAuthor

    Shipped across three PRs in v0.91.0, plus the routing prerequisite that made the v2 half verifiable at all.

    PR Scope
    #563 Routing: apigatewayv2 reachable on /v2/*, SSO Admin on the real SWBExternalService target prefix (#561)
    #564 MSK responses (7 types, both the v1 and v2 cluster paths)
    #565 API Gateway v1 responses (11 types, 8 list envelopes, nested projections)
    #567 API Gateway v2 responses (9 types, 5 list envelopes)

    Acceptance criteria

    • v1 RestApi/Resource/Method/Deployment/Stage/Authorizer/ApiKey/UsagePlan put camelCase members on the wire, each tag transcribed from the botocore model rather than inferred.
    • No response carries AccountID or Region, in API Gateway or MSK — and structurally: no wire type declares either member, so it cannot return through a field someone adds later.
    • Same check applied to API Gateway v2.
    • State encoding unchanged. Every state struct keeps its PascalCase tags, and a _StateEncodingUnchanged test per plugin asserts the persisted bytes still carry them — so recorded runs replay, and the test fails if someone later "fixes" a casing bug by retagging state.
    • Regression tests assert on raw JSON bytes (map[string]any + literal wire keys), with byte-level negative assertions on AccountID/Region.
    • docs/services.md reviewed. Both API Gateway sections gained a Response shape paragraph; MSK has no prose section, so no wrong member name was documented there.

    Three corrections to this issue as filed, all measured

    1. The v1 envelope was wrong too. This issue says items is "already correct". Every v1 collection member is named items in the model but carries locationName: "item" — singular — so {"items":[…]} parsed to nothing. Seven of eight handlers emitted items and now emit item; getStages already emitted item and was left alone, which is exactly why a blanket rename would have broken the one handler that worked. GetUsage is a third spelling (values) and is unrouted.
    2. MSK's casing was broken, not merely leaking. This issue says its API is "natively PascalCase, so its casing is correct". The kafka model is rest-json with 579 lowercase response keys and 0 uppercase; aws kafka list-clusters returned nothing at all. Both the struct path and the hand-written mskV2ClusterInfo map needed the fix.
    3. The "confirmed clean" list is right, for the wrong reason. json-protocol services are not natively PascalCase — ECS's wire is 1099 lowercase/0 upper, Step Functions 401/0. They are clean because their plugins build camelCase response maps by hand and never marshal a state struct. Measured blast radius: exactly three plugins of 41, with cloudwatchlogs a false positive because Logs: DescribeLogGroups/DescribeLogStreams/GetLogEvents return PascalCase members, so an SDK parses every field to null #528's fix was already in place.

    Verified on merged main through botocore's own parser

    18/18 checks against a live server — 11 operations that returned None or failed on a null now return values, and 7 raw wire bodies grep to 0 leaked fields. That includes get-stages still parsing under the singular item envelope while get-rest-apis now does too, which was the one regression a careless sweep would have caused.

    Why it hid for so long, and what that cost the tests

    Go's json.Unmarshal matches an object key against a struct tag case-insensitively — measured, not assumed: fields tagged json:"ApiId" and json:"apiId" both decode {"apiId":"abc123"} to the same value. So the request side worked, every Go round-trip test passed, and assertion structs with the wrong tags stayed green. Roughly 20 existing assertions across the three plugins were wrong today and passing, along with four CloudFormation v2 deploy decodes; those CloudFormation tests asserted only resource counts, so a physical ID falling back to a logical ID would not have failed one. They now assert the IDs themselves.

    Mutation-tested per PR against a green baseline, ~100 mutants total, all CAUGHT. One is worth recording: reverting a CloudFormation decode tag to PascalCase is EQUIVALENT, not a coverage gap — it changes nothing, for the case-insensitivity reason above. It was replaced with a mutant that does not case-fold onto the wire key, which is CAUGHT.

    Found alongside, filed separately

  8. added a commit that references this issue on Sep 20, 2026
  9. added a commit that references this issue on Sep 30, 2026
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

    area: apigatewayfidelitypriority: mediumtype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions