fix: forward authFilter in RDS index query to prevent cross-tenant data exposure - #3504
Conversation
…ta exposure The RDS secondary-index request template (generateIndexQueryRequestTemplate) was not forwarding ctx.stash.authFilter to the SQL Lambda, allowing any authenticated user to bypass owner/group row-level authorization by querying through auto-generated index query fields (e.g., listByRep). Add constructAuthFilterStatement, constructNonScalarFieldsStatement, constructArrayFieldsStatement, and constructFieldMappingInput to match the standard list query path which correctly applies these filters.
…test The RDS index query now calls constructNonScalarFieldsStatement and constructArrayFieldsStatement which require ctx.output.getObject. Add the mock to the test's constructMockContext helper.
Add a unit test that directly exercises RDSIndexVTLGenerator and asserts the generated VTL contains ctx.stash.authFilter forwarding to the SQL Lambda payload. This ensures the authorization bypass cannot regress.
sarayev
left a comment
There was a problem hiding this comment.
Is it feasible to add an e2e for this against a real SQL data source? I'm thinking: deploy the repro schema (owner @auth model with a @index + custom queryField), seed rows for two users, then as user A call the index query with user B's key and assert none of B's rows come back. Would that fit into the existing RDS auth e2e suite, or is there a reason we can't test it end-to-end here?
The existing The new unit test directly asserts that TL;DR: The e2e already proves |
Description of changes
The RDS secondary-index request mapping template (
generateIndexQueryRequestTemplateinpackages/amplify-graphql-index-transformer/src/resolvers/generators/rds-vtl-generator.ts) was not forwarding$ctx.stash.authFilterto the SQL Lambda function. This allowed any authenticated user to bypass owner/group row-level authorization by querying through auto-generated secondary-index query fields (e.g.,listByRep), resulting in cross-tenant data exposure.The fix adds
constructAuthFilterStatement,constructNonScalarFieldsStatement,constructArrayFieldsStatement, andconstructFieldMappingInputto the index query template — matching the standard list query path (packages/amplify-graphql-model-transformer/src/resolvers/rds/query.ts) which correctly applies these filters.CDK / CloudFormation Parameters Changed
None — this change only affects the VTL request mapping template content generated for RDS-backed secondary index queries.
Issue #, if available
P463461136 (HackerOne report #3827340)
Description of how you validated changes
@auth(rules: [{ allow: owner }])and@index(name: "byRep", queryField: "listByRep")on a PostgreSQL data sourcelistByRep(accountRepresentativeId: "REP_A")returns repA's private data (VULNERABILITY CONFIRMED)items: [](VULNERABILITY BLOCKED)Checklist
yarn testpassesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.