Skip to content

Commit

Permalink
feat: block creating pages with system reserved paths
Browse files Browse the repository at this point in the history
  • Loading branch information
NGPixel committed Apr 20, 2019
1 parent e597a7d commit 5b64c95
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion config.sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Wiki.js - CONFIGURATION #
#######################################################################
# Full documentation + examples:
# https://docs.requarks.io/wiki/install
# https://docs-beta.requarks.io/install

# ---------------------------------------------------------------------
# Port the server should listen to
Expand Down
5 changes: 0 additions & 5 deletions dev/build/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,5 @@ db:
pass: $(DB_PASS)
db: $(DB_NAME)
storage: $(DB_FILEPATH)
redis:
host: $(REDIS_HOST)
port: $(REDIS_PORT)
db: $(REDIS_DB)
password: $(REDIS_PASS)
trustProxy: $(TRUST_PROXY)
logLevel: info
10 changes: 10 additions & 0 deletions server/app/data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,14 @@ telemetry:
BUGSNAG_REMOTE: 'https://notify.bugsnag.com'
GA_ID: 'UA-9094100-7'
GA_REMOTE: 'https://www.google-analytics.com/batch'
reservedPaths:
- login
- logout
- register
- verify
- favicons
- fonts
- img
- js
- svg
# ---------------------------------
5 changes: 5 additions & 0 deletions server/controllers/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ router.get('/robots.txt', (req, res, next) => {
*/
router.get(['/e', '/e/*'], async (req, res, next) => {
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({
path: pageArgs.path,
locale: pageArgs.locale,
Expand Down
6 changes: 6 additions & 0 deletions server/helpers/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,11 @@ module.exports = {
default:
return page.content
}
},
/**
* Check if path is a reserved path
*/
isReservedPath(rawPath)  {
return _.some(WIKI.data.reservedPaths, p => _.startsWith(rawPath, p))
}
}

0 comments on commit 5b64c95

Please sign in to comment.