Skip to content

Commit

Permalink
admin: Enhance the security of the Entry Token cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
ThrRip committed Nov 9, 2023
1 parent bd33363 commit 6130a73
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions app.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export default defineAppConfig({
appHomeBase: 'https://mzg.fan/',
appAdminBasePath: '/admin',

backendBase: 'https://api.mzg.fan/v1',
backendProjectId: '649758e1eb1fa584a04d',
Expand Down
1 change: 1 addition & 0 deletions packages/admin/ecosystem.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
max_memory_restart: '200M',
env: {
'NITRO_PORT': 22321,
'NUXT_APP_SECURE_CONTEXT': true,
'NUXT_BACKEND_API_KEY': ''
}
}
Expand Down
7 changes: 6 additions & 1 deletion packages/admin/middleware/entry.global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ export default defineNuxtRouteMiddleware(async (to) => {
if (process.client) { return }

const entryTokenQuery = to.query.entrytoken
const entryTokenCookie = useCookie('admin_entry_token')
const entryTokenCookie = useCookie('admin_entry_token', {
maxAge: 2592000,
path: useAppConfig().appAdminBasePath,
sameSite: 'strict',
secure: useRuntimeConfig().appSecureContext
})
let entryToken = entryTokenQuery ?? entryTokenCookie.value
if (!String(entryToken).match(/[A-Za-z0-9]{32}/)) { entryToken = null }

Expand Down
1 change: 1 addition & 0 deletions packages/admin/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default defineNuxtConfig({
},

runtimeConfig: {
appSecureContext: true,
backendApiKey: ''
}
})

0 comments on commit 6130a73

Please sign in to comment.