mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 19:40:11 +08:00
Fix issue 51 (#99)
Please test if this passes security check, modified server/src/api/routes/index.js
This commit is contained in:
8 files changed
+84
-19
No files matched your search
@@ -135,3 +135,6 @@ dist
|
|||||||
.yarn/build-state.yml
|
.yarn/build-state.yml
|
||||||
.yarn/install-state.gz
|
.yarn/install-state.gz
|
||||||
.pnp.*
|
.pnp.*
|
||||||
|
|
||||||
|
#screenshots
|
||||||
|
tests/cypress/screenshots
|
||||||
Vendored
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
"editor.tabSize": 2,
|
"editor.tabSize": 2,
|
||||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||||
|
"editor.formatOnSave": true
|
||||||
}
|
}
|
||||||
@@ -7,5 +7,4 @@ const api = axios.create({
|
|||||||
},
|
},
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
export default api
|
export default api
|
||||||
@@ -20,6 +20,7 @@
|
|||||||
"bcrypt": "^5.1.1",
|
"bcrypt": "^5.1.1",
|
||||||
"commander": "^11.0.0",
|
"commander": "^11.0.0",
|
||||||
"connect-mongo": "^5.0.0",
|
"connect-mongo": "^5.0.0",
|
||||||
|
"cookie-parser": "^1.4.6",
|
||||||
"dockerode": "^3.3.5",
|
"dockerode": "^3.3.5",
|
||||||
"dotenv": "^16.4.1",
|
"dotenv": "^16.4.1",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
@@ -27,6 +28,7 @@
|
|||||||
"express-session": "^1.17.3",
|
"express-session": "^1.17.3",
|
||||||
"express-validator": "^7.0.1",
|
"express-validator": "^7.0.1",
|
||||||
"jsonwebtoken": "^9.0.1",
|
"jsonwebtoken": "^9.0.1",
|
||||||
|
"lusca": "^1.7.0",
|
||||||
"minimist": "^1.2.8",
|
"minimist": "^1.2.8",
|
||||||
"mongodb": "^6.3.0",
|
"mongodb": "^6.3.0",
|
||||||
"mongoose": "^8.0.3",
|
"mongoose": "^8.0.3",
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { Router } from 'express'
|
import { Router } from 'express'
|
||||||
import passport from 'passport'
|
import passport from 'passport'
|
||||||
|
import lusca from 'lusca'
|
||||||
|
import cookieParser from 'cookie-parser'
|
||||||
import sessions from './sessionRouter.js'
|
import sessions from './sessionRouter.js'
|
||||||
import quests from './questRouter.js'
|
import quests from './questRouter.js'
|
||||||
import commands from './commandRouter.js'
|
import commands from './commandRouter.js'
|
||||||
@@ -10,7 +12,7 @@ import config from '../../config.js'
|
|||||||
import leaderboardController from '../controllers/leaderboardController.js'
|
import leaderboardController from '../controllers/leaderboardController.js'
|
||||||
|
|
||||||
const router = Router()
|
const router = Router()
|
||||||
|
router.use(cookieParser())
|
||||||
if (!config.isProduction) {
|
if (!config.isProduction) {
|
||||||
router.get('/', (req, res) => {
|
router.get('/', (req, res) => {
|
||||||
res.send('Hello API!')
|
res.send('Hello API!')
|
||||||
@@ -21,17 +23,27 @@ if (!config.isProduction) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
router.use('/auth', authRouter)
|
|
||||||
router.use('/quests', quests)
|
|
||||||
router.use('/users', userRouter)
|
|
||||||
|
|
||||||
router.use('/sessions', authRequired, sessions)
|
|
||||||
router.use(
|
router.use(
|
||||||
'/commands',
|
'/commands',
|
||||||
passport.authenticate('jwt', { session: false }),
|
passport.authenticate('jwt', { session: false }),
|
||||||
authRequired,
|
authRequired,
|
||||||
commands
|
commands
|
||||||
)
|
)
|
||||||
|
router.use('/auth', authRouter)
|
||||||
|
router.use('/sessions', authRequired, sessions)
|
||||||
|
router.use(
|
||||||
|
lusca({
|
||||||
|
csrf: {
|
||||||
|
cookie: { name: '_csrf' },
|
||||||
|
header: 'x-csrf-token',
|
||||||
|
secret: config.secret,
|
||||||
|
},
|
||||||
|
hsts: { maxAge: 31536000, includeSubDomains: true, preload: true },
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
router.use('/quests', quests)
|
||||||
|
router.use('/users', userRouter)
|
||||||
|
|
||||||
router.get('/survey', (req, res) => {
|
router.get('/survey', (req, res) => {
|
||||||
if (!config.surveyUrl) {
|
if (!config.surveyUrl) {
|
||||||
|
|||||||
+21
-9
@@ -23,9 +23,19 @@ function getUrl(key) {
|
|||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
const config = {
|
function createConfig() {
|
||||||
host: get('HOST', 'localhost'),
|
const isProduction = process.env.NODE_ENV === 'production'
|
||||||
port: get('PORT', 3000),
|
const host = get('HOST', 'localhost')
|
||||||
|
const port = Number(get('PORT', 3000))
|
||||||
|
const baseUrl = get('BASE_URL', `http://${host}:${port}`)
|
||||||
|
const url = new URL(baseUrl)
|
||||||
|
return {
|
||||||
|
host,
|
||||||
|
port,
|
||||||
|
baseUrl,
|
||||||
|
domain: url.hostname,
|
||||||
|
protocol: url.protocol,
|
||||||
|
backendUrl: get('BACKEND_URL', baseUrl),
|
||||||
db: get('MONGO_URL', 'mongodb://localhost:27017/odyssey-test'),
|
db: get('MONGO_URL', 'mongodb://localhost:27017/odyssey-test'),
|
||||||
secret: get('SECRET_KEY', ''),
|
secret: get('SECRET_KEY', ''),
|
||||||
isProduction: process.env.NODE_ENV === 'production',
|
isProduction: process.env.NODE_ENV === 'production',
|
||||||
@@ -54,16 +64,18 @@ const config = {
|
|||||||
log: {
|
log: {
|
||||||
path: get('LOG_PATH', '../logs'),
|
path: get('LOG_PATH', '../logs'),
|
||||||
},
|
},
|
||||||
}
|
testing: {
|
||||||
|
enabled: !isProduction && process.env.TESTING === 'true',
|
||||||
config.baseUrl = get('BASE_URL', `http://${config.host}:${config.port}`)
|
|
||||||
config.backendUrl = get('BACKEND_URL', config.baseUrl)
|
|
||||||
config.testing = {
|
|
||||||
enabled: !config.isProduction && process.env.TESTING === 'true',
|
|
||||||
username: get('TESTING_USERNAME', ''),
|
username: get('TESTING_USERNAME', ''),
|
||||||
password: get('TESTING_PASSWORD', ''),
|
password: get('TESTING_PASSWORD', ''),
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const config = createConfig()
|
||||||
|
|
||||||
|
console.log(config)
|
||||||
|
|
||||||
export function getQuestImage(id) {
|
export function getQuestImage(id) {
|
||||||
return `${config.docker.imagePrefix}${id}`
|
return `${config.docker.imagePrefix}${id}`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,10 @@ export default session({
|
|||||||
saveUninitialized: false,
|
saveUninitialized: false,
|
||||||
rolling: true,
|
rolling: true,
|
||||||
cookie: {
|
cookie: {
|
||||||
|
domain: config.domain,
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
secure: false,
|
secure: config.protocol === 'https:',
|
||||||
sameSite: 'lax',
|
sameSite: 'strict',
|
||||||
maxAge: config.sessionMaxAge,
|
maxAge: config.sessionMaxAge,
|
||||||
},
|
},
|
||||||
store: MongoStore.create({
|
store: MongoStore.create({
|
||||||
|
|||||||
@@ -3146,6 +3146,16 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"cookie-parser@npm:^1.4.6":
|
||||||
|
version: 1.4.6
|
||||||
|
resolution: "cookie-parser@npm:1.4.6"
|
||||||
|
dependencies:
|
||||||
|
cookie: "npm:0.4.1"
|
||||||
|
cookie-signature: "npm:1.0.6"
|
||||||
|
checksum: 10c0/9c2ade5459290802cd472a2d2a6e46fbd7de3e8514e02bfed5edfde892d77733c7f89d9d2015f752a9087680429b416972d7aba748bf6824e21eb680c8556383
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"cookie-signature@npm:1.0.6":
|
"cookie-signature@npm:1.0.6":
|
||||||
version: 1.0.6
|
version: 1.0.6
|
||||||
resolution: "cookie-signature@npm:1.0.6"
|
resolution: "cookie-signature@npm:1.0.6"
|
||||||
@@ -3160,6 +3170,13 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"cookie@npm:0.4.1":
|
||||||
|
version: 0.4.1
|
||||||
|
resolution: "cookie@npm:0.4.1"
|
||||||
|
checksum: 10c0/4d7bc798df3d0f34035977949cd6b7d05bbab47d7dcb868667f460b578a550cd20dec923832b8a3a107ef35aba091a3975e14f79efacf6e39282dc0fed6db4a1
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"cookie@npm:0.5.0":
|
"cookie@npm:0.5.0":
|
||||||
version: 0.5.0
|
version: 0.5.0
|
||||||
resolution: "cookie@npm:0.5.0"
|
resolution: "cookie@npm:0.5.0"
|
||||||
@@ -6709,6 +6726,15 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"lusca@npm:^1.7.0":
|
||||||
|
version: 1.7.0
|
||||||
|
resolution: "lusca@npm:1.7.0"
|
||||||
|
dependencies:
|
||||||
|
tsscmp: "npm:^1.0.5"
|
||||||
|
checksum: 10c0/73b49c9289bbdff73298421bdafc0633f958d97bef51a0fe747bbd1ec5a8c6bb2ff9ada37e84d3a8e23703ae2db1fcf8e3d1fbea366559e3b7261467c66fbe2e
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"luxon@npm:^3.2.1":
|
"luxon@npm:^3.2.1":
|
||||||
version: 3.4.4
|
version: 3.4.4
|
||||||
resolution: "luxon@npm:3.4.4"
|
resolution: "luxon@npm:3.4.4"
|
||||||
@@ -8413,6 +8439,7 @@ __metadata:
|
|||||||
commander: "npm:^11.0.0"
|
commander: "npm:^11.0.0"
|
||||||
concurrently: "npm:^8.2.2"
|
concurrently: "npm:^8.2.2"
|
||||||
connect-mongo: "npm:^5.0.0"
|
connect-mongo: "npm:^5.0.0"
|
||||||
|
cookie-parser: "npm:^1.4.6"
|
||||||
dockerode: "npm:^3.3.5"
|
dockerode: "npm:^3.3.5"
|
||||||
dotenv: "npm:^16.4.1"
|
dotenv: "npm:^16.4.1"
|
||||||
express: "npm:^4.18.2"
|
express: "npm:^4.18.2"
|
||||||
@@ -8421,6 +8448,7 @@ __metadata:
|
|||||||
express-validator: "npm:^7.0.1"
|
express-validator: "npm:^7.0.1"
|
||||||
jest: "npm:^29.6.1"
|
jest: "npm:^29.6.1"
|
||||||
jsonwebtoken: "npm:^9.0.1"
|
jsonwebtoken: "npm:^9.0.1"
|
||||||
|
lusca: "npm:^1.7.0"
|
||||||
minimist: "npm:^1.2.8"
|
minimist: "npm:^1.2.8"
|
||||||
mongodb: "npm:^6.3.0"
|
mongodb: "npm:^6.3.0"
|
||||||
mongoose: "npm:^8.0.3"
|
mongoose: "npm:^8.0.3"
|
||||||
@@ -9354,6 +9382,13 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"tsscmp@npm:^1.0.5":
|
||||||
|
version: 1.0.6
|
||||||
|
resolution: "tsscmp@npm:1.0.6"
|
||||||
|
checksum: 10c0/2f79a9455e7e3e8071995f98cdf3487ccfc91b760bec21a9abb4d90519557eafaa37246e87c92fa8bf3fef8fd30cfd0cc3c4212bb929baa9fb62494bfa4d24b2
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"tunnel-agent@npm:^0.6.0":
|
"tunnel-agent@npm:^0.6.0":
|
||||||
version: 0.6.0
|
version: 0.6.0
|
||||||
resolution: "tunnel-agent@npm:0.6.0"
|
resolution: "tunnel-agent@npm:0.6.0"
|
||||||
|
|||||||
Reference in new issue
Block a user