mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-22 00:16:15 -04:00
security: Enable authorize plugins to grant read-only access
This commit is contained in:
parent
505d67ed1c
commit
180983736d
5 changed files with 41 additions and 5 deletions
|
@ -1,3 +1,4 @@
|
|||
const assert = require('assert').strict;
|
||||
const express = require('express');
|
||||
const log4js = require('log4js');
|
||||
const httpLogger = log4js.getLogger('http');
|
||||
|
@ -15,6 +16,7 @@ exports.normalizeAuthzLevel = (level) => {
|
|||
switch (level) {
|
||||
case true:
|
||||
return 'create';
|
||||
case 'readOnly':
|
||||
case 'modify':
|
||||
case 'create':
|
||||
return level;
|
||||
|
@ -24,6 +26,16 @@ exports.normalizeAuthzLevel = (level) => {
|
|||
return false;
|
||||
};
|
||||
|
||||
exports.userCanModify = (padId, req) => {
|
||||
if (!settings.requireAuthentication) return true;
|
||||
const {session: {user} = {}} = req;
|
||||
assert(user); // If authn required and user == null, the request should have already been denied.
|
||||
assert(user.padAuthorizations); // This is populated even if !settings.requireAuthorization.
|
||||
const level = exports.normalizeAuthzLevel(user.padAuthorizations[padId]);
|
||||
assert(level); // If !level, the request should have already been denied.
|
||||
return level !== 'readOnly';
|
||||
};
|
||||
|
||||
// Exported so that tests can set this to 0 to avoid unnecessary test slowness.
|
||||
exports.authnFailureDelayMs = 1000;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue