mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-22 08:26:16 -04:00
security: Fix authz check for pad names with encoded characters
Also: * Minor test cleanups (`function` instead of arrow functions, etc.). * Add a test for a case that was previously not covered.
This commit is contained in:
parent
3c9ae57bb3
commit
72ed1816ec
2 changed files with 69 additions and 30 deletions
|
@ -39,12 +39,13 @@ exports.checkAccess = (req, res, next) => {
|
|||
if (!level) return fail();
|
||||
const user = req.session.user;
|
||||
if (user == null) return next(); // This will happen if authentication is not required.
|
||||
const padID = (req.path.match(/^\/p\/(.*)$/) || [])[1];
|
||||
if (padID == null) return next();
|
||||
const encodedPadId = (req.path.match(/^\/p\/(.*)$/) || [])[1];
|
||||
if (encodedPadId == null) return next();
|
||||
const padId = decodeURIComponent(encodedPadId);
|
||||
// The user was granted access to a pad. Remember the authorization level in the user's
|
||||
// settings so that SecurityManager can approve or deny specific actions.
|
||||
if (user.padAuthorizations == null) user.padAuthorizations = {};
|
||||
user.padAuthorizations[padID] = level;
|
||||
user.padAuthorizations[padId] = level;
|
||||
return next();
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue