-
Notifications
You must be signed in to change notification settings - Fork 3
Model sap/ui/core/EventBus
#258
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
base: main
Are you sure you want to change the base?
Conversation
javascript/frameworks/ui5/test/queries/UI5Xss/xss-eventbus-with-data/UI5Xss.qlref
Show resolved
Hide resolved
...ipt/frameworks/ui5/lib/advanced_security/javascript/frameworks/ui5/dataflow/TypeTrackers.qll
Show resolved
Hide resolved
...ipt/frameworks/ui5/lib/advanced_security/javascript/frameworks/ui5/dataflow/TypeTrackers.qll
Show resolved
Hide resolved
| result = getOwnerComponentRef(TypeTracker::end(), customController) | ||
| } | ||
|
|
||
| private class ObjFieldStep extends SharedTypeTrackingStep { |
Check warning
Code scanning / CodeQL-Community
Dead code
...ipt/frameworks/ui5/lib/advanced_security/javascript/frameworks/ui5/dataflow/TypeTrackers.qll
Show resolved
Hide resolved
...rameworks/ui5/test/queries/UI5Xss/xss-eventbus-with-data/webapp/controller/app.controller.js
Fixed
Show fixed
Hide fixed
sap/ui/core/EventBussap/ui/core/EventBus
The previously uploaded javascript.sarif.expected file had its encoding broken and chocked the job. We make it turn back to the previous version to unblock it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds support for modeling message passing through SAP UI5's EventBus API, enabling CodeQL to detect data flow vulnerabilities that traverse the publish-subscribe pattern. The implementation tracks data from EventBus.publish() calls to the corresponding callback parameters in EventBus.subscribe() handlers.
Key Changes
- Added data flow step connecting published event data to subscription handler parameters
- Refactored TypeTrackers module into a separate file for better code organization
- Created comprehensive test case demonstrating XSS vulnerability through EventBus
Reviewed changes
Copilot reviewed 13 out of 15 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
ui5.model.yml |
Adds model definitions for UI5PublishedEventData and UI5EventSubscriptionHandlerDataParameter |
FlowSteps.qll |
Implements PublishedEventToEventSubscribedEventData flow step |
TypeTrackers.qll |
New file containing refactored type tracking predicates |
UI5.qll |
Removes TypeTrackers module and imports it from new location |
xss-eventbus-with-data/ |
Complete test case demonstrating XSS through EventBus publish/subscribe |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...ipt/frameworks/ui5/lib/advanced_security/javascript/frameworks/ui5/dataflow/TypeTrackers.qll
Show resolved
Hide resolved
mbaluda
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Can you add a reference to the new test in
ui5/test/README.md? - Can you comment what is new in
TypeTrackers.qll?
mbaluda
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Support the following way of getting an EventBus instance:
this.getOwnerComponent().getEventBus()
sap.ui.getCore().getEventBus()
…ced-security/codeql-sap-js into jeongsoolee09/add-eventbus-example
...ameworks/ui5/test/queries/UI5Xss/xss-eventbus-with-data/webapp/controller/App1.controller.js
Dismissed
Show dismissed
Hide dismissed
...ameworks/ui5/test/queries/UI5Xss/xss-eventbus-with-data/webapp/controller/App2.controller.js
Dismissed
Show dismissed
Hide dismissed
...ameworks/ui5/test/queries/UI5Xss/xss-eventbus-with-data/webapp/controller/App4.controller.js
Dismissed
Show dismissed
Hide dismissed
javascript/frameworks/ui5/lib/advanced_security/javascript/frameworks/ui5/RemoteFlowSources.qll
Show resolved
Hide resolved
javascript/frameworks/ui5/lib/advanced_security/javascript/frameworks/ui5/UI5.qll
Show resolved
Hide resolved
javascript/frameworks/ui5/lib/advanced_security/javascript/frameworks/ui5/UI5.qll
Outdated
Show resolved
Hide resolved
javascript/frameworks/ui5/lib/advanced_security/javascript/frameworks/ui5/UI5View.qll
Show resolved
Hide resolved
knewbury01
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
approving with an eye on checks yet to pass, and one small convo to resolve still on PR doc improvement
What This PR Contributes
Add support for message passing through EventBus, where there are event publishers and ones that subscribe to those events. EventBus is a singleton object that has
publishandsubscribemethods which are used by the publishers and subscribers, respectively:EventBus.getInstance().publish("someChannel", "someMessageType", data)EventBus.getInstance().subscribe("someChannel", "someMessageType", function(channel, event, data) { ... }, this). Here, the callback argument handles the message with parameters bound to the message's channel, event, and data.Note that for a channel and message type pair, there may be multiple subscribers to a publisher, establishing a broadcasting mechanism.
Three different types of EventBuses supported
EventBus.getInstance()sap.ui.core.getEventBus()oController.getOwnerComponent().getEventBus()(Important!) Global tracking of CustomControl / CustomController using MaD + API Graphs
This PR heavily uses MaD + API graphs to track the APIs pertaining to event buses, and moves the QL-driven definition of
CustomControl/CustomControllerto using the combination. The corollary of this is that given this code:The existing definition could not infer that
this.bus.publishcallsthis.getOwnerComponent().getEventBus().publishsince the code that connects both (this.bus = this.getOwnerComponent().getEventBus()) is in another method. Hacking withisAdditionalFlowStepcan go only far, since it deals with access paths (this.bus).Therefore, instead of dealing with this in QL, we use MaD instead, since the resolution mechanism of MaD is much more powerful yet incredibly succinct compared to describing the same matter in QL.
Rationale of removing
ControlTypeInHandlerModelThe ControlTypeInHandlerModel was a subclass of
ModelInput::TypeModel:ModelInput::TypeModelis a singleton (Unit) class, so extending this class has the effect of adding rows to the class. OverridinggetASourceis the extension point to adding data to the class.In the above code, we were adding two things into the class:
Then, the handler parameter or the UI5 control in the JS code would have the same type as declared in the
typeModelextensible predicate. This enables, for example, a reference tosap.m.Inputin the JS code fetched by thebyIdAPIthis.getView().byId("id-of-Input-control"")to act as its surrogate andthis.getView().byId("id-of-Input-control"").getValue()would be recognized as aRemoteFlowSource, and similarly the argumentargas in the referencethis.getView().byId("id-of-HTML-control").setContent(arg)tosap.m.HTMLto be recognized as a sink.It's proved itself useful until it's discovered that this has is twofold:
sap.m.Button), its reference (e.g.this.getView().byId("id-of-Button-control")) will be recognized asRemoteFlowSource; it's obviously unsound.CustomController, and makes it impossible forCustomControllerto use API graphs + MaD in any way. This is problematic since delegating API tracking to MaD as much as possible and using QL only sparingly is the direction this repo would want to take (see thethis.bus.subscribeexample above to see why).Therefore, we remove the class altogether and define classes that defines remote flow sources / sinks for the above:
UserDataFromRemoteControlAPISourcefor handler parameter + UI5 reference that is associated with an input control capable of being an XSS source, andUI5HTMLControlReferenceContentAPIfor HTML control reference whosecontentproperty and its setter acts as XSS sinks.Morale of this: In general, avoid contributing back to MaD using
ModelInput::TypeModeland its friends, and only consume from it.Future Works
(Won't implement)
EventBus.unsubscribeEventBus.unsubscribeallows unsubscribing from a channel for an event (message) type. Exactly when the event bus unsubscribes from a(channel, event type)pair is strictly runtime property and impossible to accurately determine statically. Therefore, we exclude it from our consideration.