Skip to content

Commit

Permalink
fix: strip starting slash from path during page create
Browse files Browse the repository at this point in the history
  • Loading branch information
NGPixel committed Jun 5, 2020
1 parent deacd80 commit 65f71d8
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions server/models/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ module.exports = class Page extends Model {
*/
static async createPage(opts) {
// -> Validate path
if (opts.path.indexOf('.') >= 0 || opts.path.indexOf(' ') >= 0 || opts.path.indexOf('\\') >= 0) {
if (opts.path.indexOf('.') >= 0 || opts.path.indexOf(' ') >= 0 || opts.path.indexOf('\\') >= 0 || opts.path.indexOf('//') >= 0) {
throw new WIKI.Error.PageIllegalPath()
}

Expand All @@ -223,6 +223,11 @@ module.exports = class Page extends Model {
opts.path = opts.path.slice(0, -1)
}

// -> Remove starting slash
if (opts.path.startsWith('/')) {
opts.path = opts.path.slice(1)
}

// -> Check for page access
if (!WIKI.auth.checkAccess(opts.user, ['write:pages'], {
locale: opts.locale,
Expand Down Expand Up @@ -404,7 +409,7 @@ module.exports = class Page extends Model {
}

// -> Validate path
if (opts.destinationPath.indexOf('.') >= 0 || opts.destinationPath.indexOf(' ') >= 0 || opts.destinationPath.indexOf('\\') >= 0) {
if (opts.destinationPath.indexOf('.') >= 0 || opts.destinationPath.indexOf(' ') >= 0 || opts.destinationPath.indexOf('\\') >= 0 || opts.destinationPath.indexOf('//') >= 0) {
throw new WIKI.Error.PageIllegalPath()
}

Expand All @@ -413,6 +418,11 @@ module.exports = class Page extends Model {
opts.destinationPath = opts.destinationPath.slice(0, -1)
}

// -> Remove starting slash
if (opts.destinationPath.startsWith('/')) {
opts.destinationPath = opts.destinationPath.slice(1)
}

// -> Check for source page access
if (!WIKI.auth.checkAccess(opts.user, ['manage:pages'], {
locale: page.localeCode,
Expand Down

0 comments on commit 65f71d8

Please sign in to comment.