feat: block creating pages with system reserved paths

This commit is contained in:
Nick 2019-04-19 20:45:05 -04:00
parent e597a7df1a
commit 5b64c95117
5 changed files with 22 additions and 6 deletions

View File

@ -2,7 +2,7 @@
# Wiki.js - CONFIGURATION # # Wiki.js - CONFIGURATION #
####################################################################### #######################################################################
# Full documentation + examples: # Full documentation + examples:
# https://docs.requarks.io/wiki/install # https://docs-beta.requarks.io/install
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Port the server should listen to # Port the server should listen to

View File

@ -8,10 +8,5 @@ db:
pass: $(DB_PASS) pass: $(DB_PASS)
db: $(DB_NAME) db: $(DB_NAME)
storage: $(DB_FILEPATH) storage: $(DB_FILEPATH)
redis:
host: $(REDIS_HOST)
port: $(REDIS_PORT)
db: $(REDIS_DB)
password: $(REDIS_PASS)
trustProxy: $(TRUST_PROXY) trustProxy: $(TRUST_PROXY)
logLevel: info logLevel: info

View File

@ -72,4 +72,14 @@ telemetry:
BUGSNAG_REMOTE: 'https://notify.bugsnag.com' BUGSNAG_REMOTE: 'https://notify.bugsnag.com'
GA_ID: 'UA-9094100-7' GA_ID: 'UA-9094100-7'
GA_REMOTE: 'https://www.google-analytics.com/batch' GA_REMOTE: 'https://www.google-analytics.com/batch'
reservedPaths:
- login
- logout
- register
- verify
- favicons
- fonts
- img
- js
- svg
# --------------------------------- # ---------------------------------

View File

@ -22,6 +22,11 @@ router.get('/robots.txt', (req, res, next) => {
*/ */
router.get(['/e', '/e/*'], async (req, res, next) => { router.get(['/e', '/e/*'], async (req, res, next) => {
const pageArgs = pageHelper.parsePath(req.path) const pageArgs = pageHelper.parsePath(req.path)
if (pageHelper.isReservedPath(pageArgs.path)) {
return next(new Error('Cannot create this page because it starts with a system reserved path.'))
}
let page = await WIKI.models.pages.getPageFromDb({ let page = await WIKI.models.pages.getPageFromDb({
path: pageArgs.path, path: pageArgs.path,
locale: pageArgs.locale, locale: pageArgs.locale,

View File

@ -56,5 +56,11 @@ module.exports = {
default: default:
return page.content return page.content
} }
},
/**
* Check if path is a reserved path
*/
isReservedPath(rawPath)  {
return _.some(WIKI.data.reservedPaths, p => _.startsWith(rawPath, p))
} }
} }