mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-24 18:27:15 +00:00
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:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user