fix(security): improve access control and storage security (#518)

* fix(security): improve access control and storage security

* fix(security): set NODE_ENV in dockerfiles and sign local storage get urls with lru cache
This commit is contained in:
Yiling-J
2026-11-05 20:49:38 +08:00
committed by GitHub
parent 0dc0bbeb03
commit 65e2ac1383
26 changed files with 811 additions and 208 deletions
+15 -1
View File
@@ -2,16 +2,19 @@ import { Hono } from 'hono'
import { teamService } from '@shumai/core/src/team/team'
import { userService } from '@shumai/core/src/user/user'
import { auth } from '@shumai/core/src/auth/auth'
import { createGuestToken } from '@shumai/core/src/auth/guest-token'
import { isArchiveStorageEnabled } from '@shumai/core/src/s3/archive-storage'
import { z } from 'zod'
import { zValidator } from '@hono/zod-validator'
import { ulid } from 'ulid'
import { setCookie } from 'hono/cookie'
const app = new Hono()
const identifySchema = z.object({
username: z.string().min(1),
email: z.string().email(),
shareId: z.string().min(1).optional(),
})
const route = app
@@ -30,7 +33,7 @@ const route = app
return c.json({ id: session?.user?.id ?? null })
})
.post('/identify', zValidator('json', identifySchema), async (c) => {
const { username, email } = c.req.valid('json')
const { username, email, shareId } = c.req.valid('json')
const dummyEmail = `guest_${ulid()}@guest.local`
const user = await userService.createGuestUser({
@@ -39,6 +42,17 @@ const route = app
guestEmail: email,
})
if (shareId) {
const token = createGuestToken({ userId: user.id, shareId })
setCookie(c, `shumai_guest_${shareId}`, token, {
httpOnly: true,
path: '/',
sameSite: 'Lax',
secure: c.req.url.startsWith('https://') || process.env.NODE_ENV === 'production',
maxAge: 30 * 24 * 60 * 60,
})
}
return c.json({ id: user.id })
})
.all('/auth/*', (c) => {