Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-list-todos-tenant-leak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@aws-blocks/create-blocks-app": patch
---

Fix multi-tenant data leak in demo template: `listTodos()` no longer falls back to `scan()` when no `sortBy` is provided. All paths now use `query()` with a `userId` filter, ensuring users only see their own todos.
21 changes: 11 additions & 10 deletions packages/create-blocks-app/templates/demo/aws-blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
});

// Simple hello world API for testing CDK deployment
export const hello = new ApiNamespace(scope, 'hello', (context) => ({

Check warning on line 62 in packages/create-blocks-app/templates/demo/aws-blocks/index.ts

View workflow job for this annotation

GitHub Actions / Build, Unit Tests, E2E Local

lint/correctness/noUnusedFunctionParameters

This parameter context is unused.
async greet(name: string) {
return { message: `Hello, ${name}!`, timestamp: Date.now() };
}
Expand Down Expand Up @@ -117,17 +117,18 @@

async listTodos(sortBy?: 'priority' | 'title' | 'createdAt'): Promise<Todo[]> {
const user = await auth.requireAuth(context);
const indexMap = {
priority: 'byPriority',
title: 'byTitle',
createdAt: 'byCreatedAt'

const indexMap = {
priority: 'byPriority',
title: 'byTitle',
createdAt: 'byCreatedAt'
} as const;

const iterator = sortBy
? todos.query(indexMap[sortBy], { userId: { equals: user.username } })
: todos.scan();


const iterator = todos.query({
index: sortBy ? indexMap[sortBy] : 'byCreatedAt',
where: { userId: { equals: user.username } }
});

return await Array.fromAsync(iterator);
},

Expand Down
Loading