Skip to content

Commit c378a67

Browse files
committed
Update
1 parent 56d7af6 commit c378a67

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Default User is overwritten as privileged
2+
3+
The user whose request cannot be verified as authenticated is represented as `cds.User.default` internally. If this property is set to `cds.User.Privileged`, then a service may provide assets to some user who has no rights to access them.
4+
5+
## Recommendation
6+
7+
### Set up a development profile that uses non-production authentication
8+
9+
It may be tempting to overwrite the `cds.User.default` as `cds.User.Privileged`, for ease of development. However, this may slip through production undeleted since the assignment to `cds.User.default` can be hard to detect because it may take various forms; e.g. the programmer may choose to store `cds.User` to a variable `v` and access `cds.User.default` by `v.default`.
10+
11+
A safer and more elegant solution is to set up a development profile and opt in to use a non-production strategy such as basic, dummy, or mocked during its use. This can be done in `package.json` of the CAP application at its project root:
12+
13+
``` json
14+
{
15+
"requires": {
16+
"[dev]": {
17+
"auth": "dummy"
18+
}
19+
}
20+
}
21+
```
22+
23+
Setting `"dummy"` as the development authentication strategy has the effect of disabling `@requires` and `@restrict` annotations of CDS definitions that provides authorization. The application during development then can be run and tested with the `--profile dev` option.
24+
25+
```shell
26+
cds serve --profile dev
27+
```
28+
29+
## Example
30+
31+
Setting `cds.User.default` to `cds.User.Privileged` may happen anywhere in the application. The following is the server.js that provides the top-level definition of a CAP application, overwriting the property with the problematic class.
32+
33+
``` javascript
34+
const cds = require("@sap/cds");
35+
const app = require("express")();
36+
37+
/*
38+
* Antipattern: `cds.User.default` is overwritten to `cds.User.Privileged`
39+
*/
40+
cds.User.default = cdsUser.Privileged;
41+
42+
cds.serve("all").in(app);
43+
```
44+
45+
## References
46+
47+
- SAP CAPire Documentation: [cds.User.default](https://cap.cloud.sap/docs/node.js/authentication#default-user).
48+
- SAP CAPire Documentation: [Authentication Strategies](https://cap.cloud.sap/docs/node.js/authentication#strategies).
49+
- Common Weakness Enumeration: [CWE-862](https://cwe.mitre.org/data/definitions/862.html).
50+
- Common Weakness Enumeration: [CWE-306](https://cwe.mitre.org/data/definitions/306.html).

javascript/frameworks/cap/src/bad-authn-authz/EntityExposedWithoutAuthn.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
# CAP Entities Exposed without Access Controls
1+
# CAP Definitions Exposed without Access Controls
2+
3+
Although using a production-level authentication strategy such as `jwt` ensures that all entities and services require the user to be authenticated, this does not guarantee any further authorization. Furthermore, the lack of required authentication or authorization may imply a gap in the design of the system.
24

35
## Recommendation
46

57
### Use CDS-based authorization
68

79
CDL provides two annotations to declare access controls `@requires` and `@restrict` with the latter providing more granularity than the former. For example, to check if a request is being made by an authenticated user to the CDL entity or service, annotate it with `@requires: 'authenticated-user'`. On the other hand, if it needs to be read only via a certain group of users where the user has level greater than 2, use `@restrict: { grant: 'READ', to: 'SomeUser', where: { $user.level > 2 } }` (note the leading `$`).
8-
10+
911
#### Check the original CDS entity it is derived from
1012

1113
CDS entities may be derived from other entities by means of selection and projection. These derived definitions inherit its identical conditions for access control or can choose to override them. Therefore, in order to accurately determine what authorization an entity requires, the access control of the parent entity should be transitively inspected (that is, the inspection should go up the chain of derivation).
@@ -80,6 +82,6 @@ module.exports = class Service1 extends cds.ApplicationService {
8082
[@requires](https://cap.cloud.sap/docs/guides/security/authorization#requires).
8183
- SAP CAPire Documentation: [Protecting Certain Entries](https://cap.cloud.sap/docs/cds/common#protecting-certain-entries).
8284
- SAP CAPire Documentation: [Inheritance of Restrictions](https://cap.cloud.sap/docs/guides/security/authorization#inheritance-of-restrictions).
85+
- SAP CAPire Documentation: [Authentication Enforced in Production](https://cap.cloud.sap/docs/node.js/authentication#authentication-enforced-in-production).
8386
- Common Weakness Enumeration: [CWE-862](https://cwe.mitre.org/data/definitions/862.html).
84-
- Commoon Weakness Enumeration: [CWE-306](https://cwe.mitre.org/data/definitions/306.html).
85-
87+
- Common Weakness Enumeration: [CWE-306](https://cwe.mitre.org/data/definitions/306.html).

0 commit comments

Comments
 (0)