-
Notifications
You must be signed in to change notification settings - Fork 3
Ensure sanitizeContent attribute is respected #257
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
Open
mbaluda
wants to merge
15
commits into
main
Choose a base branch
from
mbaluda/sanitize-content
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d52a0c7
Ensure sanitizeContent attribute is respected
mbaluda 1ec8bfa
Ensure sanitizeContent attribute is respected
mbaluda 0a7b668
Add more tests
mbaluda 6a00000
Exclude sanitized HTML views from XSS sinks
mbaluda 807ea34
Fix ql-4-ql alerts
mbaluda 02c4537
Fix workflow
mbaluda 235c441
Update expected file
mbaluda f108236
fix README
mbaluda ee49547
Address review comments
mbaluda 9b50447
Fix conflict
mbaluda ddf7a6e
Merge branch 'main' into mbaluda/sanitize-content
mbaluda 1a2c5cc
update expected sile
mbaluda 0929f6e
fix expected file
mbaluda 6baa2d7
Merge branch 'main' into mbaluda/sanitize-content
mbaluda 744bf21
Update javascript/frameworks/ui5/lib/advanced_security/javascript/fra…
mbaluda 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
245 changes: 245 additions & 0 deletions
245
javascript/frameworks/ui5/lib/advanced_security/javascript/frameworks/ui5/UI5Control.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,245 @@ | ||
| import advanced_security.javascript.frameworks.ui5.UI5 | ||
|
|
||
| private newtype TUI5Control = | ||
| TXmlControl(XmlElement control) or | ||
| TJsonControl(JsonObject control) { | ||
| exists(JsonView view | control.getParent() = view.getRoot().getPropValue("content")) | ||
| } or | ||
| TJsControl(NewNode control) { | ||
| exists(JsView view | | ||
| control.asExpr().getParentExpr() = | ||
| view.getRoot() | ||
| .getArgument(1) | ||
| .getALocalSource() | ||
| .(ObjectLiteralNode) | ||
| .getAPropertyWrite("createContent") | ||
| .getRhs() | ||
| .(FunctionNode) | ||
| .getReturnNode() | ||
| .getALocalSource() | ||
| .(ArrayLiteralNode) | ||
| .asExpr() | ||
| ) | ||
| } | ||
|
|
||
| class UI5Control extends TUI5Control { | ||
| XmlElement asXmlControl() { this = TXmlControl(result) } | ||
|
|
||
| JsonObject asJsonControl() { this = TJsonControl(result) } | ||
|
|
||
| NewNode asJsControl() { this = TJsControl(result) } | ||
|
|
||
| string toString() { | ||
| result = this.asXmlControl().toString() | ||
| or | ||
| result = this.asJsonControl().toString() | ||
| or | ||
| result = this.asJsControl().toString() | ||
| } | ||
|
|
||
| predicate hasLocationInfo( | ||
| string filepath, int startcolumn, int startline, int endcolumn, int endline | ||
| ) { | ||
| this.asXmlControl().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) | ||
| or | ||
| /* Since JsonValue does not implement `hasLocationInfo`, we use `getLocation` instead. */ | ||
| exists(Location location | location = this.asJsonControl().getLocation() | | ||
| location.getFile().getAbsolutePath() = filepath and | ||
| location.getStartColumn() = startcolumn and | ||
| location.getStartLine() = startline and | ||
| location.getEndColumn() = endcolumn and | ||
| location.getEndLine() = endline | ||
| ) | ||
| or | ||
| this.asJsControl().hasLocationInfo(filepath, startcolumn, startline, endcolumn, endline) | ||
| } | ||
|
|
||
| /** | ||
| * Gets the qualified type string, e.g. `sap.m.SearchField`. | ||
| */ | ||
| string getQualifiedType() { | ||
| exists(XmlElement control | control = this.asXmlControl() | | ||
| result = control.getNamespace().getUri() + "." + control.getName() | ||
| ) | ||
| or | ||
| exists(JsonObject control | control = this.asJsonControl() | | ||
| result = control.getPropStringValue("Type") | ||
| ) | ||
| or | ||
| exists(NewNode control | control = this.asJsControl() | | ||
| result = this.asJsControl().asExpr().getAChildExpr().(DotExpr).getQualifiedName() | ||
| ) | ||
| } | ||
|
|
||
| File getFile() { | ||
| result = this.asXmlControl().getFile() or | ||
| result = this.asJsonControl().getFile() or | ||
| result = this.asJsControl().getFile() | ||
| } | ||
|
|
||
| /** | ||
| * Gets the `id` property of this control. | ||
| */ | ||
| string getId() { result = this.getProperty("id").getValue() } | ||
|
|
||
| /** | ||
| * Gets the qualified type name, e.g. `sap/m/SearchField`. | ||
| */ | ||
| string getImportPath() { result = this.getQualifiedType().replaceAll(".", "/") } | ||
|
|
||
| /** | ||
| * Gets the definition of this control if this is a custom one. | ||
| */ | ||
| CustomControl getDefinition() { | ||
| result.getName() = this.getQualifiedType() and | ||
| inSameWebApp(this.getFile(), result.getFile()) | ||
| } | ||
|
|
||
| /** | ||
| * Gets a reference to this control. Currently supports only such references made through `byId`. | ||
| */ | ||
| ControlReference getAReference() { | ||
| result.getMethodName() = "byId" and | ||
| result.getArgument(0).getALocalSource().asExpr().(StringLiteral).getValue() = | ||
| this.getProperty("id").getValue() | ||
| } | ||
|
|
||
| /** Gets a property of this control having the name. */ | ||
| UI5ControlProperty getProperty(string propName) { | ||
| result.asXmlControlProperty() = this.asXmlControl().getAttribute(propName) | ||
| or | ||
| result.asJsonControlProperty() = this.asJsonControl().getPropValue(propName) | ||
| or | ||
| result.asJsControlProperty() = | ||
| this.asJsControl() | ||
| .getArgument(0) | ||
| .getALocalSource() | ||
| .asExpr() | ||
| .(ObjectExpr) | ||
| .getPropertyByName(propName) | ||
| .getAChildExpr() | ||
| .flow() and | ||
| not exists(Property property | result.asJsControlProperty() = property.getNameExpr().flow()) | ||
| } | ||
|
|
||
| /** Gets a property of this control. */ | ||
| UI5ControlProperty getAProperty() { result = this.getProperty(_) } | ||
|
|
||
| bindingset[propName] | ||
| MethodCallNode getARead(string propName) { | ||
| // TODO: in same view | ||
| inSameWebApp(this.getFile(), result.getFile()) and | ||
| result.getMethodName() = "get" + capitalize(propName) | ||
| } | ||
|
|
||
| bindingset[propName] | ||
| MethodCallNode getAWrite(string propName) { | ||
| // TODO: in same view | ||
| inSameWebApp(this.getFile(), result.getFile()) and | ||
| result.getMethodName() = "set" + capitalize(propName) | ||
| } | ||
|
|
||
| /** Holds if this control reads from or writes to a model. */ | ||
| predicate accessesModel(UI5Model model) { this.accessesModel(model, _) } | ||
|
|
||
| /** Holds if this control reads from or writes to a model with regards to a binding path. */ | ||
| predicate accessesModel(UI5Model model, XmlBindingPath bindingPath) { | ||
| // Verify that the controller's model has the referenced property | ||
| exists(XmlView view | | ||
| // Both this control and the model belong to the same view | ||
| this = view.getControl() and | ||
| model = view.getController().getModel() and | ||
| model.(UI5InternalModel).getPathString() = bindingPath.getPath() and | ||
| bindingPath.getBindingTarget() = this.asXmlControl().getAnAttribute() | ||
| ) | ||
| } | ||
|
|
||
| /** Get the view that this control is part of. */ | ||
| UI5View getView() { result = this.asXmlControl().getFile() } | ||
|
|
||
| /** Get the controller that manages this control. */ | ||
| CustomController getController() { result = this.getView().getController() } | ||
|
|
||
| /** | ||
| * Gets the full import path of the associated control. | ||
| */ | ||
| string getControlTypeName() { result = this.getQualifiedType().replaceAll(".", "/") } | ||
|
|
||
| /** | ||
| * Holds if the attribute `sanitizeContent` | ||
| * in controls `sap.ui.core.HTML` and `sap.ui.richttexteditor.RichTextEditor` | ||
| * is set to true and never set to false anywhere | ||
| */ | ||
| predicate isSanitizedControl() { | ||
| not this = this.sanitizeContentSetTo(false) and | ||
| ( | ||
| this.getControlTypeName() = "sap/ui/richttexteditor/RichTextEditor" | ||
| or | ||
| this.getControlTypeName() = "sap/ui/core/HTML" and | ||
| this = this.sanitizeContentSetTo(true) | ||
| ) | ||
| } | ||
|
|
||
| bindingset[val] | ||
| private UI5Control sanitizeContentSetTo(boolean val) { | ||
| // `sanitizeContent` attribute is set declaratively | ||
jeongsoolee09 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| result.getProperty("sanitizeContent").toString() = val.toString() | ||
| or | ||
| //or | ||
| // `sanitizeContent` attribute is set programmatically (not sufficient) | ||
| //result | ||
| // .getAReference() | ||
| // .hasPropertyWrite("sanitizeContent", | ||
| // any(DataFlow::Node n | not n.mayHaveBooleanValue(val.booleanNot()))) | ||
jeongsoolee09 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // `sanitizeContent` attribute is set programmatically using setProperty() | ||
jeongsoolee09 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| exists(CallNode node | node = result.getAReference().getAMemberCall("setProperty") | | ||
| node.getArgument(0).getStringValue() = "sanitizeContent" and | ||
| not node.getArgument(1).mayHaveBooleanValue(val.booleanNot()) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| class SanitizedUI5Control extends UI5Control { | ||
| SanitizedUI5Control() { super.isSanitizedControl() } | ||
| } | ||
|
|
||
| private newtype TUI5ControlProperty = | ||
| TXmlControlProperty(XmlAttribute property) or | ||
| TJsonControlProperty(JsonValue property) or | ||
| TJsControlProperty(ValueNode property) | ||
|
|
||
| class UI5ControlProperty extends TUI5ControlProperty { | ||
| XmlAttribute asXmlControlProperty() { this = TXmlControlProperty(result) } | ||
|
|
||
| JsonValue asJsonControlProperty() { this = TJsonControlProperty(result) } | ||
|
|
||
| ValueNode asJsControlProperty() { this = TJsControlProperty(result) } | ||
|
|
||
| string toString() { | ||
| result = this.asXmlControlProperty().getValue().toString() or | ||
mbaluda marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| result = this.asJsonControlProperty().toString() or | ||
| result = this.asJsControlProperty().toString() | ||
| } | ||
|
|
||
| UI5Control getControl() { | ||
| result.asXmlControl() = this.asXmlControlProperty().getElement() or | ||
| result.asJsonControl() = this.asJsonControlProperty().getParent() or | ||
| result.asJsControl().getArgument(0).asExpr() = this.asJsControlProperty().getEnclosingExpr() | ||
| } | ||
|
|
||
| string getName() { | ||
| result = this.asXmlControlProperty().getName() | ||
| or | ||
| exists(JsonValue parent | parent.getPropValue(result) = this.asJsonControlProperty()) | ||
| or | ||
| exists(Property property | | ||
| property.getAChildExpr() = this.asJsControlProperty().asExpr() and result = property.getName() | ||
| ) | ||
| } | ||
|
|
||
| string getValue() { | ||
| result = this.asXmlControlProperty().getValue() or | ||
| result = this.asJsonControlProperty().getStringValue() or | ||
| result = this.asJsControlProperty().asExpr().(StringLiteral).getValue() | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.