Skip to content

fix(parser): keep the client certificate in APIGatewayProxyEventV2Model - #8851

Open
Manishram-ai wants to merge 1 commit into
aws-powertools:developfrom
Manishram-ai:fix/parser-apigwv2-client-cert
Open

Manishram-ai wants to merge 1 commit into
aws-powertools:developfrom
Manishram-ai:fix/parser-apigwv2-client-cert

Conversation

@Manishram-ai

Copy link
Copy Markdown
Contributor

Issue number:
closes #8848

Summary

Changes

  • RequestContextV2 has an optional authentication field now, with the client certificate API Gateway sends when mutual TLS is on (PEM, subject DN, issuer DN, serial number and validity dates). ApiGatewayAuthorizerRequestV2 gets it too, since it uses the same request context.
  • The new RequestContextV2Authentication, RequestContextV2ClientCert and RequestContextV2ClientCertValidity models are exported from parser.models like the other RequestContextV2 models. They're defined in apigwv2.py instead of reusing ApiGatewayUserCert, because importing apigw.py would load the REST models whenever a v2 model is used, and test_model_imports.py checks that it doesn't.
  • New tests parse a v2 event and a v2 Lambda authorizer event that have a client certificate, and a v2 event without one.

User experience

Today the certificate is dropped during parsing, so a handler or an HTTP API Lambda authorizer that wants to check the client's subject DN has to go back to the raw event. With this change parsed.requestContext.authentication.clientCert.subjectDN returns www.example.com for the repo's apiGatewayProxyV2Event.json. Events without mutual TLS parse the same as before, with authentication set to None, including Lambda function URL events that send "authentication": null. model_dump() on the request context now includes an authentication key.

Verification

  • The three new tests fail on develop with 'RequestContextV2' object has no attribute 'authentication', and pass with this change.
  • tests/unit/parser and tests/functional/parser: 275 passed on Python 3.10, 3.12 and 3.14.
  • ruff check, ruff format --check and mypy are clean, and tests/performance passes.
  • I didn't run this against a live HTTP API with mutual TLS. The shape comes from the payload format 2.0 example linked in the issue and the v2 events already in tests/events, and it matches the certificate fields the REST model already parses.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@Manishram-ai
Manishram-ai requested a review from a team as a code owner November 16, 2026 19:12
@Manishram-ai
Manishram-ai requested a review from svozza November 16, 2026 19:12
@boring-cyborg boring-cyborg Bot added the tests label Nov 16, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 16, 2026
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

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

Labels

size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: APIGatewayProxyEventV2Model drops the mutual TLS client certificate

1 participant