Skip to content

Commit 6433954

Browse files
authored
fix(backend): redact api key logging (#1530)
1 parent 1aa8b75 commit 6433954

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

supabase/functions/_backend/private/delete_failed_version.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,15 @@ app.delete('/', middlewareKey(['all', 'write', 'upload']), async (c) => {
2020
cloudlog({ requestId: c.get('requestId'), message: 'delete failed version body', body })
2121
const apikey = c.get('apikey')
2222
const capgkey = c.get('capgkey') as string
23-
cloudlog({ requestId: c.get('requestId'), message: 'apikey', apikey })
24-
cloudlog({ requestId: c.get('requestId'), message: 'capgkey', capgkey })
23+
if (apikey && typeof apikey === 'object') {
24+
cloudlog({
25+
requestId: c.get('requestId'),
26+
message: 'apikey context',
27+
apikeyId: (apikey as { id?: number }).id,
28+
userId: (apikey as { user_id?: string }).user_id,
29+
mode: (apikey as { mode?: string }).mode,
30+
})
31+
}
2532
const { data: _userId, error: _errorUserId } = await supabaseApikey(c, capgkey)
2633
.rpc('get_user_id', { apikey: capgkey, app_id: body.app_id })
2734
if (_errorUserId) {

supabase/functions/_backend/private/upload_link.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ app.post('/', middlewareKey(['all', 'write', 'upload']), async (c) => {
2222
cloudlog({ requestId: c.get('requestId'), message: 'post upload link body', body })
2323
const apikey = c.get('apikey') as Database['public']['Tables']['apikeys']['Row']
2424
const capgkey = c.get('capgkey') as string
25+
cloudlog({
26+
requestId: c.get('requestId'),
27+
message: 'apikey context',
28+
apikeyId: apikey.id,
29+
userId: apikey.user_id,
30+
mode: apikey.mode,
31+
})
2532
const { data: _userId, error: _errorUserId } = await supabaseApikey(c, capgkey)
2633
.rpc('get_user_id', { apikey: capgkey, app_id: body.app_id })
2734
if (_errorUserId) {

supabase/functions/_backend/public/device/index.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ app.post('/', middlewareKey(['all', 'write']), async (c) => {
2727
const apikey = c.get('apikey') as Database['public']['Tables']['apikeys']['Row']
2828

2929
cloudlog({ requestId: c.get('requestId'), message: 'body', body })
30-
cloudlog({ requestId: c.get('requestId'), message: 'apikey', apikey })
30+
cloudlog({
31+
requestId: c.get('requestId'),
32+
message: 'apikey context',
33+
apikeyId: apikey.id,
34+
userId: apikey.user_id,
35+
mode: apikey.mode,
36+
})
3137

3238
// Rate limit: max 1 set per second per device+app, and same channel set max once per 60 seconds
3339
// Note: We check device_id && app_id only (not channel) so op-level rate limiting applies even for invalid requests
@@ -53,7 +59,13 @@ app.get('/', middlewareKey(['all', 'write', 'read']), async (c) => {
5359
const body = await getBodyOrQuery<DeviceLink>(c)
5460
const apikey = c.get('apikey') as Database['public']['Tables']['apikeys']['Row']
5561
cloudlog({ requestId: c.get('requestId'), message: 'body', body })
56-
cloudlog({ requestId: c.get('requestId'), message: 'apikey', apikey })
62+
cloudlog({
63+
requestId: c.get('requestId'),
64+
message: 'apikey context',
65+
apikeyId: apikey.id,
66+
userId: apikey.user_id,
67+
mode: apikey.mode,
68+
})
5769

5870
// Rate limit: max 1 get per second per device+app
5971
if (body.device_id && body.app_id) {
@@ -78,7 +90,13 @@ app.delete('/', middlewareKey(['all', 'write']), async (c) => {
7890
const body = await getBodyOrQuery<DeviceLink>(c)
7991
const apikey = c.get('apikey') as Database['public']['Tables']['apikeys']['Row']
8092
cloudlog({ requestId: c.get('requestId'), message: 'body', body })
81-
cloudlog({ requestId: c.get('requestId'), message: 'apikey', apikey })
93+
cloudlog({
94+
requestId: c.get('requestId'),
95+
message: 'apikey context',
96+
apikeyId: apikey.id,
97+
userId: apikey.user_id,
98+
mode: apikey.mode,
99+
})
82100

83101
// Rate limit: max 1 delete per second per device+app
84102
if (body.device_id && body.app_id) {

0 commit comments

Comments
 (0)