mirror of
https://github.com/sasjs/server.git
synced 2025-12-10 19:34:34 +00:00
fix: add authorize middleware for appStreams
This commit is contained in:
@@ -5,7 +5,7 @@ import { PermissionSetting } from '../controllers/permission'
|
||||
|
||||
export const authorize: RequestHandler = async (req, res, next) => {
|
||||
let permission
|
||||
const user = req.user
|
||||
const user = req.user || req.session.user
|
||||
if (user) {
|
||||
// no need to check for permissions when user is admin
|
||||
if (user.isAdmin) return next()
|
||||
@@ -13,7 +13,7 @@ export const authorize: RequestHandler = async (req, res, next) => {
|
||||
const dbUser = await User.findOne({ id: user.userId })
|
||||
if (!dbUser) return res.sendStatus(401)
|
||||
|
||||
const uri = req.baseUrl + req.route.path
|
||||
const uri = req.baseUrl + req.path
|
||||
|
||||
// find permission w.r.t user
|
||||
permission = await Permission.findOne({ uri, user: dbUser._id })
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import path from 'path'
|
||||
import express, { Request } from 'express'
|
||||
import { authorize } from '../../middlewares/authorize'
|
||||
import { folderExists } from '@sasjs/utils'
|
||||
|
||||
import { addEntryToAppStreamConfig, getFilesFolder } from '../../utils'
|
||||
@@ -9,7 +10,7 @@ const appStreams: { [key: string]: string } = {}
|
||||
|
||||
const router = express.Router()
|
||||
|
||||
router.get('/', async (req, res) => {
|
||||
router.get('/', authorize, async (req, res) => {
|
||||
const content = appStreamHtml(process.appStreamConfig)
|
||||
|
||||
res.cookie('XSRF-TOKEN', req.csrfToken())
|
||||
@@ -66,7 +67,7 @@ export const publishAppStream = async (
|
||||
return {}
|
||||
}
|
||||
|
||||
router.get(`/*`, function (req: Request, res, next) {
|
||||
router.get(`/*`, authorize, function (req: Request, res, next) {
|
||||
const reqPath = req.path.replace(/^\//, '')
|
||||
|
||||
// Redirecting to url with trailing slash for appStream base URL only
|
||||
|
||||
Reference in New Issue
Block a user