@sap/cds 7.9.1 → 7.9.2
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 +10 -0
- package/lib/env/cds-requires.js +1 -0
- package/lib/ql/DELETE.js +1 -1
- package/lib/ql/SELECT.js +1 -1
- package/lib/ql/UPDATE.js +1 -1
- package/lib/ql/Whereable.js +1 -1
- package/libx/_runtime/common/generic/auth/index.js +48 -0
- package/libx/_runtime/common/generic/auth/utils.js +7 -3
- package/libx/_runtime/common/utils/resolveView.js +3 -0
- package/libx/_runtime/db/generic/rewrite.js +6 -1
- package/libx/_runtime/db/utils/generateAliases.js +1 -1
- package/libx/_runtime/remote/utils/client.js +4 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,16 @@
|
|
|
4
4
|
- The format is based on [Keep a Changelog](http://keepachangelog.com/).
|
|
5
5
|
- This project adheres to [Semantic Versioning](http://semver.org/).
|
|
6
6
|
|
|
7
|
+
## Version 7.9.2 - 2024-05-22
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- Server crash in case of certain errors in Cloud SDK
|
|
12
|
+
- Bug in restriction of entities modeled as composition of aspects
|
|
13
|
+
- `$search`: resolve an exception accessing `req.query.elements`
|
|
14
|
+
- Ignore flattened associations in projection on remote entities
|
|
15
|
+
- Falsy keys in `cds.ql` were ignored in usage like `SELECT.from(Books, 0)`
|
|
16
|
+
|
|
7
17
|
## Version 7.9.1 - 2024-05-13
|
|
8
18
|
|
|
9
19
|
### Fixed
|
package/lib/env/cds-requires.js
CHANGED
package/lib/ql/DELETE.js
CHANGED
package/lib/ql/SELECT.js
CHANGED
|
@@ -76,7 +76,7 @@ module.exports = class Query extends Whereable {
|
|
|
76
76
|
|
|
77
77
|
from (target, second, third) {
|
|
78
78
|
this.SELECT.from = target === '*' || this._target_ref4 (...arguments)
|
|
79
|
-
if (!target.raw && second) {
|
|
79
|
+
if (!target.raw && second !== undefined) {
|
|
80
80
|
if (third) {
|
|
81
81
|
this.byKey(second)
|
|
82
82
|
this.columns(third)
|
package/lib/ql/UPDATE.js
CHANGED
package/lib/ql/Whereable.js
CHANGED
|
@@ -41,7 +41,7 @@ class Query extends require('./Query') {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
byKey(key) {
|
|
44
|
-
if (typeof key !== 'object') key = { [Object.keys(this._target.keys||{ID:1})[0]]: key }
|
|
44
|
+
if (typeof key !== 'object' || key === null) key = { [Object.keys(this._target.keys||{ID:1})[0]]: key }
|
|
45
45
|
if (this.SELECT) this.SELECT.one = true
|
|
46
46
|
if (cds.env.features.keys_into_where) return this.where(key)
|
|
47
47
|
if (this.UPDATE) { this.UPDATE.entity = { ref: [{ id: cds.env.ql.quirks_mode ? this.UPDATE.entity : this.UPDATE.entity.ref.at(-1), where: predicate4([key]) }] }; return this }
|
|
@@ -9,6 +9,54 @@ const restrictHandler = require('./restrict')
|
|
|
9
9
|
const restrictExpandHandler = require('./expand')
|
|
10
10
|
|
|
11
11
|
module.exports = cds.service.impl(function authorization() {
|
|
12
|
+
// REVISIT: general approach to dependent auth:
|
|
13
|
+
// add restrictions to auth-dependent entities as if modeled to allow static access during request processing
|
|
14
|
+
// // TODO: where to do?
|
|
15
|
+
// // add restrictions to auth-dependent entities
|
|
16
|
+
// const defs = this.model.definitions
|
|
17
|
+
// const deps = []
|
|
18
|
+
// for (const each of this.entities) {
|
|
19
|
+
// for (const k in each.compositions) {
|
|
20
|
+
// const c = each.compositions[k]
|
|
21
|
+
// const ct = defs[c.target]
|
|
22
|
+
// if (defs[ct?.elements.up_?.target] === each && !ct['@requires'] && !ct['@restrict']) {
|
|
23
|
+
// deps.push(c.target)
|
|
24
|
+
// }
|
|
25
|
+
// }
|
|
26
|
+
// }
|
|
27
|
+
// for (const each of deps) {
|
|
28
|
+
// const e = defs[each]
|
|
29
|
+
// let rstr
|
|
30
|
+
// let cur = defs[e.elements.up_.target]
|
|
31
|
+
// while (cur && !rstr) {
|
|
32
|
+
// rstr = cur['@requires'] || cur['@restrict']
|
|
33
|
+
// cur = defs[cur.elements.up_?.target]
|
|
34
|
+
// }
|
|
35
|
+
// if (rstr) {
|
|
36
|
+
// // TODO: normalize restriction to @restrict syntax
|
|
37
|
+
// // TODO: add rewrite paths in instance-based auth
|
|
38
|
+
// e['@restrict'] = rstr
|
|
39
|
+
// }
|
|
40
|
+
// }
|
|
41
|
+
|
|
42
|
+
// mark entities that depend on ancestor for auth with that ancestor
|
|
43
|
+
const defs = this.model.definitions
|
|
44
|
+
for (const each of this.entities) {
|
|
45
|
+
for (const k in each.compositions) {
|
|
46
|
+
const c = each.compositions[k]
|
|
47
|
+
const ct = defs[c.target]
|
|
48
|
+
if (defs[ct?.elements.up_?.target] === each && !ct['@requires'] && !ct['@restrict']) {
|
|
49
|
+
let rstr
|
|
50
|
+
let cur = defs[ct.elements.up_.target]
|
|
51
|
+
while (!rstr && cur) {
|
|
52
|
+
if (cur['@requires'] || cur['@restrict']) rstr = cur
|
|
53
|
+
cur = defs[cur.elements.up_?.target]
|
|
54
|
+
}
|
|
55
|
+
if (rstr) Object.defineProperty(ct, '_auth_depends_on', { value: rstr })
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
12
60
|
/*
|
|
13
61
|
* @requires
|
|
14
62
|
*/
|
|
@@ -140,9 +140,10 @@ const resolveUserAttrs = (restrict, req) => {
|
|
|
140
140
|
return restrict
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
const
|
|
143
|
+
const _authDependsOnAncestor = (entity, annotations) => {
|
|
144
144
|
// @cds.autoexposed and not @cds.autoexpose -> not explicitly exposed by modeling
|
|
145
145
|
return (
|
|
146
|
+
entity._auth_depends_on ||
|
|
146
147
|
entity.name.match(/\.DraftAdministrativeData$/) ||
|
|
147
148
|
(entity['@cds.autoexposed'] && !entity['@cds.autoexpose'] && !annotations.some(a => a in entity))
|
|
148
149
|
)
|
|
@@ -159,7 +160,10 @@ const cqnFrom = req => {
|
|
|
159
160
|
|
|
160
161
|
const getAuthRelevantEntity = (req, model, annotations) => {
|
|
161
162
|
if (!req.target || !(req.event in CRUD_EVENTS)) return
|
|
162
|
-
|
|
163
|
+
|
|
164
|
+
const it = _authDependsOnAncestor(req.target, annotations)
|
|
165
|
+
if (!it) return req.target
|
|
166
|
+
if (it?.kind === 'entity' && req.subject.ref?.length === 1) return it
|
|
163
167
|
|
|
164
168
|
let cqn = cqnFrom(req)
|
|
165
169
|
|
|
@@ -188,7 +192,7 @@ const getAuthRelevantEntity = (req, model, annotations) => {
|
|
|
188
192
|
let authRelevantEntity
|
|
189
193
|
for (let i = segments.length - 1; i >= 0; i--) {
|
|
190
194
|
const segment = segments[i]
|
|
191
|
-
if (segment.kind === 'entity' && !
|
|
195
|
+
if (segment.kind === 'entity' && !_authDependsOnAncestor(segment, annotations)) {
|
|
192
196
|
authRelevantEntity = segment
|
|
193
197
|
break
|
|
194
198
|
}
|
|
@@ -33,6 +33,9 @@ const _inverseTransition = transition => {
|
|
|
33
33
|
|
|
34
34
|
const ref0 = value.ref[0]
|
|
35
35
|
if (value.ref.length > 1) {
|
|
36
|
+
// ignore flattened columns like author.name
|
|
37
|
+
if (transition.target.elements[ref0].isAssociation) continue
|
|
38
|
+
|
|
36
39
|
const nested = inverseTransition.mapping.get(ref0) || {}
|
|
37
40
|
if (!nested.transition) nested.transition = { mapping: new Map() }
|
|
38
41
|
let current = nested.transition.mapping
|
|
@@ -14,8 +14,13 @@ const _restoreLink = req => {
|
|
|
14
14
|
function handler(req) {
|
|
15
15
|
if (typeof req.query === 'string') return
|
|
16
16
|
|
|
17
|
-
// invoke req.subject before it gets modified
|
|
17
|
+
// invoke req.subject and req.query.elements before it gets modified
|
|
18
18
|
req.subject
|
|
19
|
+
try {
|
|
20
|
+
req.query.elements
|
|
21
|
+
} catch {
|
|
22
|
+
// ignore potential errors (no x4 support in req.query.elements)
|
|
23
|
+
}
|
|
19
24
|
|
|
20
25
|
if (!this.model) {
|
|
21
26
|
// best-effort rewrite of path in from
|
|
@@ -205,8 +205,10 @@ const _getSanitizedError = (e, reqOptions, options = { suppressRemoteResponseBod
|
|
|
205
205
|
}
|
|
206
206
|
|
|
207
207
|
// AxiosError's toJSON() method doesn't include the request and response objects
|
|
208
|
-
e.toJSON
|
|
209
|
-
|
|
208
|
+
if (e.__proto__.toJSON) {
|
|
209
|
+
e.toJSON = function () {
|
|
210
|
+
return { ...this.__proto__.toJSON(), request: this.request, response: this.response }
|
|
211
|
+
}
|
|
210
212
|
}
|
|
211
213
|
|
|
212
214
|
return e
|