@apolitical/server 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [2.1.1] - 2022-01-31
|
|
9
|
+
### Fixed
|
|
10
|
+
- Authorisation logic
|
|
11
|
+
|
|
8
12
|
## [2.1.0] - 2022-01-21
|
|
9
13
|
### Added
|
|
10
14
|
- Prerender middleware
|
package/package.json
CHANGED
|
@@ -8,21 +8,21 @@ module.exports = ({ logger, serverError: { Forbidden }, config }) => {
|
|
|
8
8
|
return function handler(req, res, next) {
|
|
9
9
|
const childLogger = logger.where(__filename, 'handler');
|
|
10
10
|
childLogger.debug('Started');
|
|
11
|
-
let isNotMyselfSlug = false;
|
|
12
11
|
let isNotAdmin = false;
|
|
13
|
-
|
|
14
|
-
if (myselfSource) {
|
|
15
|
-
isNotMyselfSlug = req.params[myselfSource] !== MYSELF_SLUG;
|
|
16
|
-
}
|
|
12
|
+
let isNotMyselfSlug = false;
|
|
17
13
|
// Check user role (from JWT)
|
|
18
14
|
if (!allowNonAdmin) {
|
|
19
15
|
isNotAdmin = req.user && req.user.role !== ADMIN_ROLE;
|
|
20
16
|
}
|
|
17
|
+
// Check myself param
|
|
18
|
+
if (myselfSource) {
|
|
19
|
+
isNotMyselfSlug = req.params[myselfSource] !== MYSELF_SLUG;
|
|
20
|
+
}
|
|
21
21
|
// Check permissions and prevent unauthorised requests
|
|
22
22
|
let unauthorised = false;
|
|
23
|
-
if (
|
|
23
|
+
if (!allowNonAdmin && isNotAdmin && isNotMyselfSlug) {
|
|
24
24
|
unauthorised = true;
|
|
25
|
-
} else if (isNotAdmin && !
|
|
25
|
+
} else if (!allowNonAdmin && isNotAdmin && !myselfSource) {
|
|
26
26
|
unauthorised = true;
|
|
27
27
|
}
|
|
28
28
|
if (unauthorised) {
|