Skip to content

fix: HttpApi explicit AuthorizationScopes: [] is not overridden by authorizer default - #3980

Open
Adityaj0 wants to merge 1 commit into
aws:developfrom
Adityaj0:fix/httpapi-empty-authorization-scopes-override
Open

fix: HttpApi explicit AuthorizationScopes: [] is not overridden by authorizer default#3980
Adityaj0 wants to merge 1 commit into
aws:developfrom
Adityaj0:fix/httpapi-empty-authorization-scopes-override

Conversation

@Adityaj0

Copy link
Copy Markdown

Summary

Fixes #3979.

For AWS::Serverless::HttpApi, an event/function-level Auth.AuthorizationScopes: [] is meant to override the named authorizer's default AuthorizationScopes, requiring no scopes for that method — this already works correctly for AWS::Serverless::Api (REST APIs).

OpenApiEditor.add_auth_to_method (samtranslator/open_api/open_api.py) defaulted an unset AuthorizationScopes to []:

authorization_scopes = auth.get("AuthorizationScopes", [])

_set_method_authorizer then checked it with if authorization_scopes: — since [] is falsy, this is indistinguishable from "not set," so the explicit override was silently dropped and the authorizer's default scopes were enforced instead. This means requests the template author intended to allow without those scopes get rejected by API Gateway.

SwaggerEditor's equivalent REST API code path (samtranslator/swagger/swagger.py) already handles this correctly — it uses None as the "not set" sentinel (auth.get("AuthorizationScopes"), no default) and checks is not None. This PR applies the identical fix to OpenApiEditor, and also aligns the authorizer-presence check (authorizers.get(authorizer_name) is not None) with swagger.py's pattern, replacing an unguarded authorizers[authorizer_name] dict-subscript.

Test plan

  • Added tests/translator/input/http_api_with_auth_with_default_scopes.yaml, a direct HttpApi port of the existing REST API regression test tests/translator/input/api_with_auth_with_default_scopes.yaml (default authorizer, explicit authorizer, scope overwrite, and both AuthorizationScopes: [] cases), with expected output for all three partitions (aws, aws-cn, aws-us-gov).
  • Verified the new test fails against the pre-fix code — both AuthorizationScopes: [] cases produced the authorizer's default scopes instead of [] — and passes with the fix, with output matching the semantics already proven correct for REST APIs.
  • python -m pytest tests/translator tests/plugins tests/parser tests/openapi tests/swagger tests/model — 3241 passed (same 5 pre-existing, unrelated SAR-timing/region failures as on develop).
  • ruff check / black --check clean on the changed file.

…thorizer default

OpenApiEditor.add_auth_to_method defaulted an unset AuthorizationScopes to
[], then _set_method_authorizer checked it with `if authorization_scopes:`.
Since [] is falsy, this couldn't distinguish "not set" from an explicit
empty-list override, so a method-level `AuthorizationScopes: []` (meant to
require no scopes, overriding the authorizer's default) was silently
ignored and the authorizer's default AuthorizationScopes were enforced
instead.

SwaggerEditor's equivalent REST API code path (swagger.py) already gets
this right by using None as the "not set" sentinel and an `is not None`
check. This applies the same fix to OpenApiEditor so HTTP APIs behave
consistently with REST APIs, and also aligns the authorizer-presence
check (`authorizers.get(authorizer_name) is not None`) with swagger.py's
pattern.

Fixes aws#3979
@Adityaj0
Adityaj0 requested a review from a team as a code owner August 14, 2026 07:07
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.

HttpApi: explicit AuthorizationScopes: [] is silently overridden by the authorizer's default scopes

1 participant