Review API Gateway authentication configuration

Attach appropriate authentication to protected API routes and verify actual permission checks.

Description

Choose authentication for the API type and callers. IAM or other controls may already apply without a separate Authorizer resource, so inspect the protected method or route.

Potential impact

Authenticating a WebSocket connection does not authorize every later message. A caller may request operations outside their permissions if the application skips that check.

Remediation

A WebSocket Lambda authorizer runs only on $connect. Set that route’s AuthorizationType to CUSTOM, assign its AuthorizerId and allow API Gateway to invoke the Lambda function. Have the application authorize later operations and test allowed and denied cases.

Examples

Use the actual Lambda function ARN. If a token is supplied in the query string as shown, use WSS and exclude it from logs.

Before

yaml
Resources:
  DevWebSocket:
    Type: AWS::ApiGatewayV2::Api
    Properties:
      Name: dev-websocket
      ProtocolType: WEBSOCKET
      RouteSelectionExpression: $request.body.action

The first excerpt defines only the API. Compare the deployed route settings with the intended public access.

After

yaml
Resources:
  DevWebSocket:
    Type: AWS::ApiGatewayV2::Api
    Properties:
      Name: dev-websocket
      ProtocolType: WEBSOCKET
      RouteSelectionExpression: $request.body.action

  DevAuthorizer:
    Type: AWS::ApiGatewayV2::Authorizer
    Properties:
      Name: request-authorizer
      ApiId: !Ref DevWebSocket
      AuthorizerType: REQUEST
      IdentitySource:
        - route.request.querystring.token
      AuthorizerUri: arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:123456789012:function:auth/invocations

The second adds a REQUEST authorizer. Its attachment to the $connect route is omitted.

References