-
Notifications
You must be signed in to change notification settings - Fork 2
Adds XSJS CSRF and authorization queries #144
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
Changes from 4 commits
62f61b7
061bb78
e828e1d
105d6ad
bd546bc
51f421b
75378b2
e322c39
32e3e78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import javascript | ||
|
||
class ExposedServiceAccessSpec extends File { | ||
ExposedServiceAccessSpec() { | ||
this.getBaseName() = "xs-app.json" | ||
or | ||
// we are only interested in exposed services | ||
this.getBaseName() = ".xsaccess" and | ||
any(JsonValue v | this = v.getJsonFile()).getPropValue("exposed").getBooleanValue() = false | ||
mbaluda marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Broken XSJS authentication | ||
|
||
If you choose to use server-side JavaScript to write your application code, you need to bear in mind the potential for (and risk of) attack against authentication infrastructure. Leaks or flaws in the authentication or session management functions allow attackers to impersonate users and gain access to unauthorized systems and data. | ||
mbaluda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Recommendation | ||
|
||
Use the built-in SAP HANA XS authentication mechanism and session management (cookies). For example, use the "authentication" keyword to enable an authentication method and set it according to the authentication method you want implement, for example: SAP logon ticket, form-based, or basic (user name and password) in the application's .xsaccess file, which ensures that all objects in the application path are available only to authenticated users. | ||
mbaluda marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
## Example | ||
|
||
The following `xs-app.json` fragment shows disabled XSJS authentication. | ||
|
||
``` javascript | ||
mbaluda marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
{ | ||
"welcomeFile": "index.html", | ||
"authenticationMethod": "none", | ||
"routes": [ ... | ||
mbaluda marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
``` | ||
|
||
## References | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A link to the documentation page about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, it might be valuable if we mention that |
||
* SAP: [Server-Side JavaScript Security Considerations](https://help.sap.com/docs/SAP_HANA_PLATFORM/d89d4595fae647eabc14002c0340a999/2040c1b7e478448cb9904c55ac06cac8.html). | ||
* Common Weakness Enumeration: [CWE-287](https://cwe.mitre.org/data/definitions/287.html). | ||
mbaluda marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* @name Broken XSJS authentication | ||
* @description Disabling XSJS authentication makes the application vulnerable to | ||
* unauthorized access. | ||
* @kind problem | ||
* @problem.severity warning | ||
* @security-severity 7.5 | ||
* @precision medium | ||
* @id js/xsjs-broken-authentication | ||
* @tags security | ||
*/ | ||
|
||
import javascript | ||
import advanced_security.javascript.frameworks.xsjs.Xsaccess | ||
|
||
from JsonValue value, string msg | ||
where | ||
value.getJsonFile() instanceof ExposedServiceAccessSpec and | ||
( | ||
msg = "Authentication should not be disabled." and | ||
exists(JsonValue v | | ||
value = v.getPropValue(["authentication", "authenticationMethod", "authenticationType"]) | ||
mbaluda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| | ||
value.getStringValue() = "none" | ||
or | ||
value instanceof JsonNull | ||
) | ||
or | ||
// the authentication specification is missing from .xsaccess | ||
msg = "Authentication is missing from the configuration." and | ||
value.isTopLevel() and | ||
value.getJsonFile().getBaseName() = ".xsaccess" and | ||
not exists(JsonValue p | | ||
p.getJsonFile() = value.getJsonFile() and | ||
p.getPropValue("authentication") = any(JsonValue v) | ||
mbaluda marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
) | ||
) | ||
select value, msg |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Disabled XSJS CSRF protection | ||
|
||
When you set up a web server to receive a request from a client without any mechanism for verifying that it was intentionally sent, then it is vulnerable to attack. An attacker can trick a client into making an unintended request to the web server that will be treated as an authentic request. This can be done via a URL, image load, XMLHttpRequest, etc. and can result in exposure of data or unintended code execution. | ||
mbaluda marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
## Recommendation | ||
|
||
When you use XSJS, Cross-Site Request Forgery (CSRF) protection is enabled by default. SAP’s recommendation is to use CSRF protection for any request that could be processed by a browser client by normal users. | ||
mbaluda marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
## Example | ||
|
||
The following `xs-app.json` fragment enables CSRF protection in XSJS. | ||
|
||
``` javascript | ||
"routes": [ | ||
{ | ||
"source": "/bad/(.*)", | ||
"destination": "srv_api", | ||
"csrfProtection": true, | ||
mbaluda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
## References | ||
|
||
* SAP: [Server-Side JavaScript Security Considerations](https://help.sap.com/docs/SAP_HANA_PLATFORM/d89d4595fae647eabc14002c0340a999/e8a6bc904c0c48a182288604f467e84a.html). | ||
* OWASP: [Cross-Site Request Forgery (CSRF)](https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)). | ||
* Common Weakness Enumeration: [CWE-352](https://cwe.mitre.org/data/definitions/352.html). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* @name Disabled XSJS CSRF protection | ||
* @description Disabling CSRF protection makes the application vulnerable to | ||
* a Cross-Site Request Forgery (CSRF) attack. | ||
* @kind problem | ||
* @problem.severity error | ||
* @security-severity 8.8 | ||
* @precision high | ||
* @id js/xsjs-disabled-csrf-protection | ||
* @tags security | ||
* external/cwe/cwe-352 | ||
*/ | ||
|
||
import javascript | ||
import advanced_security.javascript.frameworks.xsjs.Xsaccess | ||
|
||
from JsonValue value | ||
where | ||
value.getJsonFile() instanceof ExposedServiceAccessSpec and | ||
exists(JsonValue v | | ||
value = v.getPropValue(["prevent_xsrf", "csrfProtection"]) and | ||
mbaluda marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
value.getBooleanValue() = false | ||
) | ||
select value, "CSRF vulnerability due to protection being disabled." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
| service/exposed/.xsaccess:4:23:4:26 | null | Authentication should not be disabled. | | ||
| service/missing_auth/.xsaccess:1:1:4:1 | {\\n " ... true\\n} | Authentication is missing from the configuration. | | ||
| service/xs-app.json:3:29:3:34 | "none" | Authentication should not be disabled. | | ||
| service/xs-app.json:15:35:15:40 | "none" | Authentication should not be disabled. | |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
XSJSAuthentication/XSJSAuthentication.ql |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
| service/exposed/.xsaccess:3:21:3:25 | false | CSRF vulnerability due to protection being disabled. | | ||
| service/xs-app.json:14:31:14:35 | false | CSRF vulnerability due to protection being disabled. | |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
XSJSCsrfDisabled/XSJSCsrfDisabled.ql |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"exposed": true, | ||
"prevent_xsrf": false, | ||
"authentication": null | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"exposed": false, | ||
"prevent_xsrf": false, | ||
|
||
"authentication": null | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"exposed": false, | ||
"prevent_xsrf": true | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
var webRequest1 = $.request; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"welcomeFile": "index.html", | ||
"authenticationMethod": "none", | ||
|
||
"routes": [ | ||
{ | ||
"source": "/good/(.*)", | ||
"destination": "srv_api", | ||
"csrfProtection": true, | ||
"authenticationType": "xsuaa" | ||
}, | ||
{ | ||
"source": "/bad/(.*)", | ||
"destination": "srv_api", | ||
"csrfProtection": false, | ||
|
||
"authenticationType": "none" | ||
|
||
} | ||
] | ||
} |
Uh oh!
There was an error while loading. Please reload this page.