-
Notifications
You must be signed in to change notification settings - Fork 2
POC: PII with cds #135
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
Closed
Closed
POC: PII with cds #135
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"parser-directories": [ | ||
"node_modules/@cap-js-community" | ||
] | ||
} |
37 changes: 37 additions & 0 deletions
37
javascript/frameworks/cap/src/sensitive-exposure/CdsTreeSitterXml.qll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import javascript | ||
|
||
class TreeSitterXmlElement extends XmlElement { | ||
TreeSitterXmlElement() { this.getFile().getName().matches("%.ts.xml") } | ||
|
||
string getURL() { | ||
result = | ||
"file://" + this.getFile().getName().regexpCapture("^(.*)\\.ts\\.xml$", 1) + ":" + | ||
(this.getAttributeValue("srow").toInt() + 1) + ":" + | ||
(this.getAttributeValue("scol").toInt() + 1) + ":" + | ||
(this.getAttributeValue("erow").toInt() + 1) + ":" + this.getAttributeValue("ecol").toInt() | ||
} | ||
} | ||
|
||
class CdsAnnotateElement extends TreeSitterXmlElement { | ||
CdsAnnotateElement() { this.hasName("annotate_element") } | ||
|
||
CdsAnnotation getAnnotation() { result = this.getAChild() } | ||
|
||
CdsIdentifier getIdentifier() { result = this.getAChild() } | ||
} | ||
|
||
class CdsAnnotation extends TreeSitterXmlElement { | ||
CdsAnnotation() { this.hasName("annotation") } | ||
|
||
CdsAnnotationPath getAnnotationPath() { result = this.getAChild() } | ||
} | ||
|
||
class CdsAnnotationPath extends TreeSitterXmlElement { | ||
CdsAnnotationPath() { this.hasName("annotation_path") } | ||
|
||
CdsIdentifier getIdentifier() { result = this.getAChild() } | ||
} | ||
|
||
class CdsIdentifier extends TreeSitterXmlElement { | ||
CdsIdentifier() { this.hasName("identifier") } | ||
} |
48 changes: 48 additions & 0 deletions
48
javascript/frameworks/cap/src/sensitive-exposure/SensitiveExposureCds.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# CAP Insertion of Sensitive Information into Log File | ||
|
||
If sensitive information is written to a log entry using the CAP Node.js logging API, a malicious user may be able to gain access to user data. | ||
|
||
Data annotated as `@PersonalData` should not be logged. | ||
|
||
## Recommendation | ||
|
||
CAP applications should not log sensitive information. Check CDS declarations for annotations before logging certain data types or fields. | ||
|
||
## Examples | ||
|
||
This CAP service directly logs the sensitive information. | ||
|
||
```cds | ||
namespace advanced_security.log_exposure.sample_entities; | ||
|
||
entity Sample { | ||
name : String(111); | ||
} | ||
|
||
// annotations for Data Privacy | ||
annotate Sample with | ||
@PersonalData : { DataSubjectRole : 'Sample', EntitySemantics : 'DataSubject' } | ||
{ | ||
name @PersonalData.IsPotentiallySensitive; | ||
} | ||
``` | ||
|
||
``` javascript | ||
import cds from '@sap/cds' | ||
const LOG = cds.log("logger"); | ||
|
||
const { Sample } = cds.entities('advanced_security.log_exposure.sample_entities') | ||
|
||
class SampleVulnService extends cds.ApplicationService { | ||
init() { | ||
LOG.info("Received: ", Sample.name); // CAP log exposure alert | ||
} | ||
} | ||
``` | ||
|
||
## References | ||
|
||
- OWASP 2021: [Security Logging and Monitoring Failures](https://owasp.org/Top10/A09_2021-Security_Logging_and_Monitoring_Failures/). | ||
- OWASP: [Logging Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Logging_Cheat_Sheet.html). | ||
- OWASP: [User Privacy Protection Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/User_Privacy_Protection_Cheat_Sheet.html). | ||
- SAP CAPire Documentation: [PersonalData Annotations](https://cap.cloud.sap/docs/guides/data-privacy/annotations). |
51 changes: 51 additions & 0 deletions
51
javascript/frameworks/cap/src/sensitive-exposure/SensitiveExposureCds.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* @name Insertion of sensitive information into log files | ||
* @description Writing sensitive information to log files can allow that | ||
* information to be leaked to an attacker more easily. | ||
* @kind path-problem | ||
* @problem.severity warning | ||
* @security-severity 7.5 | ||
* @precision medium | ||
* @id javascript/sensitive-log-cds | ||
* @tags security | ||
* external/cwe/cwe-532 | ||
*/ | ||
|
||
import javascript | ||
import advanced_security.javascript.frameworks.cap.CDS | ||
import advanced_security.javascript.frameworks.cap.CAPLogInjectionQuery | ||
import DataFlow::PathGraph | ||
import CdsTreeSitterXml | ||
|
||
class SensitiveExposureSource extends DataFlow::Node { | ||
SensitiveExposureSource() { | ||
exists(PropRead p, SensitiveAnnotatedElement c | | ||
p.getPropertyName() = c.getName() and | ||
this = p | ||
) | ||
} | ||
} | ||
|
||
class SensitiveLogExposureConfig extends TaintTracking::Configuration { | ||
SensitiveLogExposureConfig() { this = "SensitiveLogExposure" } | ||
|
||
override predicate isSource(DataFlow::Node source) { source instanceof SensitiveExposureSource } | ||
|
||
override predicate isSink(DataFlow::Node sink) { sink instanceof CdsLogSink } | ||
} | ||
|
||
CdsAnnotateElement getSensitiveAnnotation(PropRead s) { | ||
result.getAnnotation().getAnnotationPath().getIdentifier().getTextValue() = "PersonalData" and | ||
result.getIdentifier().getTextValue() = s.getPropertyName() | ||
} | ||
|
||
from | ||
SensitiveLogExposureConfig config, DataFlow::PathNode source, DataFlow::PathNode sink, | ||
TreeSitterXmlElement annotation | ||
where | ||
config.hasFlowPath(source, sink) and | ||
annotation.getFile().getRelativePath().regexpCapture("^(.*)\\.cds\\.ts\\.xml$", 1) = | ||
source.getNode().asExpr().getFile().getRelativePath().regexpCapture("^(.*)\\.js$", 1) and | ||
annotation = getSensitiveAnnotation(source.getNode()) | ||
select sink, source, sink, "Log entry depends on a $@ piece of information.", annotation, | ||
"potentially sensitive" |
14 changes: 14 additions & 0 deletions
14
javascript/frameworks/cap/test/queries/sensitive-exposure-cds/sensitive-exposure.cds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace advanced_security.log_exposure.sample_entities; | ||
|
||
entity Sample { | ||
name : String(111); | ||
dateOfBirth : Date; | ||
} | ||
|
||
// annotations for Data Privacy | ||
annotate Sample with | ||
@PersonalData : { DataSubjectRole : 'Sample', EntitySemantics : 'DataSubject' } | ||
{ | ||
name @PersonalData.IsPotentiallySensitive; | ||
dateOfBirth @PersonalData.IsPotentiallyPersonal; | ||
} |
8 changes: 8 additions & 0 deletions
8
javascript/frameworks/cap/test/queries/sensitive-exposure-cds/sensitive-exposure.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
nodes | ||
| sensitive-exposure.js:10:32:10:42 | Sample.name | | ||
| sensitive-exposure.js:10:32:10:42 | Sample.name | | ||
| sensitive-exposure.js:10:32:10:42 | Sample.name | | ||
edges | ||
| sensitive-exposure.js:10:32:10:42 | Sample.name | sensitive-exposure.js:10:32:10:42 | Sample.name | | ||
#select | ||
| sensitive-exposure.js:10:32:10:42 | Sample.name | sensitive-exposure.js:10:32:10:42 | Sample.name | sensitive-exposure.js:10:32:10:42 | Sample.name | Log entry depends on a $@ piece of information. | sensitive-exposure.cds:12:3:12:45 | annotate_element | potentially sensitive | |
13 changes: 13 additions & 0 deletions
13
javascript/frameworks/cap/test/queries/sensitive-exposure-cds/sensitive-exposure.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import cds from '@sap/cds' | ||
const LOG = cds.log("logger"); | ||
|
||
const { Sample } = cds.entities('advanced_security.log_exposure.sample_entities') | ||
|
||
class SampleVulnService extends cds.ApplicationService { | ||
init() { | ||
/* A sensitive info log sink. */ | ||
|
||
LOG.info("Received: ", Sample.name); // CAP log exposure alert | ||
Check failureCode scanning / CodeQL Insertion of sensitive information into log files High test
Log entry depends on a potentially sensitive piece of information.
|
||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
javascript/frameworks/cap/test/queries/sensitive-exposure-cds/sensitive-exposure.qlref
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sensitive-exposure/SensitiveExposureCds.ql |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / CodeQL
Insertion of sensitive information into log files High test