@digitalbazaar/ezcap-express 4.3.0 → 4.3.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 +7 -0
- package/lib/helpers.js +25 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @digitalbazaar/ezcap-express Changelog
|
|
2
2
|
|
|
3
|
+
## 4.3.1 - 2021-12-13
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- Fix `expectedAction` to be `write` for `DELETE` method.
|
|
7
|
+
- Throw error when no `expectedAction` is given for a given HTTP method and
|
|
8
|
+
provide defaults for all common HTTP methods.
|
|
9
|
+
|
|
3
10
|
## 4.3.0 - 2021-12-10
|
|
4
11
|
|
|
5
12
|
### Added
|
package/lib/helpers.js
CHANGED
|
@@ -10,6 +10,19 @@ import {verifyHeaderValue} from '@digitalbazaar/http-digest-header';
|
|
|
10
10
|
|
|
11
11
|
const {ZCAP_CONTEXT_URL} = zCapConstants;
|
|
12
12
|
|
|
13
|
+
const DEFAULT_ACTION_FOR_METHOD = new Map([
|
|
14
|
+
['GET', 'read'],
|
|
15
|
+
['HEAD', 'read'],
|
|
16
|
+
['OPTIONS', 'read'],
|
|
17
|
+
['POST', 'write'],
|
|
18
|
+
['PUT', 'write'],
|
|
19
|
+
['PATCH', 'write'],
|
|
20
|
+
['DELETE', 'write'],
|
|
21
|
+
['CONNECT', 'write'],
|
|
22
|
+
['TRACE', 'write'],
|
|
23
|
+
['PATCH', 'write']
|
|
24
|
+
]);
|
|
25
|
+
|
|
13
26
|
export const ZCAP_ROOT_PREFIX = 'urn:zcap:root:';
|
|
14
27
|
|
|
15
28
|
// middleware used to collect expected values for zcap authorization
|
|
@@ -87,16 +100,23 @@ export function createExpectationMiddleware({
|
|
|
87
100
|
|
|
88
101
|
/* Note: This is safe as long as the server's request handling
|
|
89
102
|
infrastructure differentiates based on HTTP method (as is typical practice
|
|
90
|
-
with express/connect routing. So, while the client specifies the HTTP
|
|
103
|
+
with express/connect routing). So, while the client specifies the HTTP
|
|
91
104
|
method, the server specifies the handler for that HTTP method. For example,
|
|
92
105
|
this middleware will ensure that if a client specifies "POST" then it
|
|
93
|
-
must be invoking a zcap that grants "write" action authority. Then,
|
|
94
|
-
that the server's router ensures that only the "POST" handler will
|
|
95
|
-
executed (typical routing practice), all is well. If the handler code is
|
|
106
|
+
must be invoking a zcap that grants "write" action authority. Then,
|
|
107
|
+
provided that the server's router ensures that only the "POST" handler will
|
|
108
|
+
be executed (typical routing practice), all is well. If the handler code is
|
|
96
109
|
chosen via some other means, e.g., via the request body, then the caller
|
|
97
110
|
MUST provide the expected action and not rely on default behavior. */
|
|
98
111
|
if(req.ezcap.expectedAction === undefined) {
|
|
99
|
-
req.ezcap.expectedAction = req.method
|
|
112
|
+
req.ezcap.expectedAction = DEFAULT_ACTION_FOR_METHOD.get(req.method);
|
|
113
|
+
if(req.ezcap.expectedAction === undefined) {
|
|
114
|
+
const error = new Error(
|
|
115
|
+
`The HTTP method ${req.method} has no expected capability action.`);
|
|
116
|
+
error.name = 'NotSupportedError';
|
|
117
|
+
error.httpStatusCode = 400;
|
|
118
|
+
return helpers.handleError({error, onError});
|
|
119
|
+
}
|
|
100
120
|
}
|
|
101
121
|
|
|
102
122
|
try {
|