-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Insufficient authorization query #100
Comments
A standard library query: User-controlled bypass of security check. Related CWEs: |
Authorization enforcement in Node.js: service CustomerService @(requires: 'authenticated-user'){
entity Orders @(restrict: [
{ grant: ['READ','WRITE'], to: 'admin' },
]){/*...*/}
entity Approval @(restrict: [
{ grant: 'WRITE', where: '$user.level > 2' }
]){/*...*/}
} is equivalent to const cds = require('@sap/cds')
cds.serve ('CustomerService') .with (function(){
this.before ('*', req =>
req.user.is('authenticated') || req.reject(403)
)
this.before (['READ', 'CREATE'], 'Orders', req =>
req.user.is('admin') || req.reject(403)
)
this.before ('*', 'Approval', req =>
req.user.attr.level > 2 || req.reject(403)
)
}) Note that |
Sample CDS entity Orders @(restrict: [
{ grant: 'READ', to: 'Auditor', where: 'AuditBy = $user' }
]) {/*...*/}
entity Reviews @(restrict: [
{ grant:['READ', 'WRITE'], to: ['Reviewer', 'Customer'] }
]) {/*...*/}
entity Orders @(restrict: [
{ grant: ['READ','WRITE'], to: 'Admin' },
{ grant: 'READ', where: 'buyer = $user' }
]) {/*...*/}
entity Orders @(restrict: [
{ grant: 'READ', to: 'Auditor', where: 'country = $user.country' },
{ grant: ['READ','WRITE'], where: 'CreatedBy = $user' },
]) {/*...*/}
service CatalogService {
entity Products as projection on db.Products { ... }
actions {
@(requires: 'Admin')
action addRating (stars: Integer);
}
function getViewsCount @(restrict: [{ to: 'Admin' }]) () returns Integer;
}
service CustomerService @(requires: 'authenticated-user') {
entity Products @(restrict: [
{ grant: 'READ' },
{ grant: 'WRITE', to: 'Vendor' },
{ grant: 'addRating', to: 'Customer'}
]) {/*...*/}
actions {
action addRating (stars: Integer);
}
entity Orders @(restrict: [
{ grant: '*', to: 'Customer', where: 'CreatedBy = $user' }
]) {/*...*/}
action monthlyBalance @(requires: 'Vendor') ();
}
Key takeaways:
So checking if the service is protected in terms of authentication requires:
|
My misunderstanding: The difference between |
The services / entities / actions / functions can be protected with JS implementation code as well. Protection with
|
Relevant sources:
https://cap.cloud.sap/docs/guides/security/aspects#secure-authorization
https://cap.cloud.sap/docs/guides/authorization#restrict-annotation
CWE-862: Missing Authorization
CWE-842: Placement of User into Incorrect Group
CWE-266: Incorrect Privilege Assignment
The text was updated successfully, but these errors were encountered: