Skip to content

Remove FPs of js/ui5-log-injection-to-http #190

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

Merged
merged 27 commits into from
May 15, 2025

Conversation

jeongsoolee09
Copy link
Contributor

@jeongsoolee09 jeongsoolee09 commented May 5, 2025

What this PR contributes

Eliminate FPs

The query js/ui5-log-injection-to-http yielded false positives on code that does not depend on UI5, because the query did not check if the data being sent via HTTP is indeed derived from a UI5 log entry (by means of onLogEntry or getLogEntries). Therefore, enforce it by using flow labels.

Tidy up code

Factor out various type trackers into one (hasDependency/1)

There were sapControl/0, sapController/0, sapRenderer/0, and sapComponent/0 that gives rise to classes such as CustomControl, CustomController, and so on. However, all of them differed in only the dependency paths they referred to, and keeping them more or less pollluted the code. Therefore, add a hasDependency/1 parameterized with the dependency path.

Split up log-entry-flows-to-sinks

The unit test case log-entry-flows-to-sinks combined several kinds of sinks all in one test case (hence the name). Split it up into several smaller ones:

  1. log-entry-flows-to-http-getLogEntries: getLogEntries is used to fetch a log entry to be sent in an XmlHttpRequest.
  2. log-entry-flows-to-http-log-listener-js-object: a log listener as a plain JS object (that implements it implicitly) has a method onLogEntries which pulls a log entry on a log event and sends it in an XmlHttpRequest.
  3. log-entry-flows-to-http-log-listener-sap-module: Same as the example right above, instead it's a UI5 module that explicitly implements it.
  4. log-entry-flows-to-http-log-listener-sap-module-imported: See Future Work below.

Miscellaneous

Fix access path of SapLogEntries in the library model

One of the rows contributing to the type SapLogEntries had this row:

["SapLogEntries", "SapLogger", "Member[addLogListener].Parameter[0].Member[onLogEntry].Argument[0]"]

It confused Parameter with Argument and vice versa, so put them in the right places.

Also, as per the UI5 documentation on sap/base/Log.Logger, all of the various logging functions do not return another Logger (they are of void type), so delete this row:

["SapLogger", "SapLogger", "Member[debug,error,fatal,info,setLevel,trace,warning,getLogger].ReturnValue"]

Separate out UI5LogInjectionQuery into a library module

This is to reuse the configuration in UI5LogsToHttp.

Future work

  • Replace flow labels with flow states when migrating to the new data flow library (should be before January 2026).
  • Make the query also cover cases where a custom log listener is imported and used (log-entry-flows-to-http-log-listener-sap-module-imported). This is currently partially blocked as of now due to limitations in AmdModuleDefinition::Range (see github/codeql, PR #19359); this prevents us from modeling sap.ui.require, an another way of requiring a UI5 module.

"use strict";
return BaseObject.extend("codeql-sap-js.log.CustomLogListener", {
constructor: function () {
let message = Log.getLogEntries()[0].message;

Check warning

Code scanning / CodeQL

Access to user-controlled UI5 Logs Medium test

Accessed log entries depend on
user-provided data
.
const http = new XMLHttpRequest();
const url = "https://some.remote.server/location";
http.open("POST", url);
http.send(message); // js/ui5-log-injection-to-http

Check warning

Code scanning / CodeQL

UI5 Log injection in outbound network request Medium test

Outbound network request depends on
user-provided
log data.
Log.debug(input); //
/* 2. Create a JS object that implements Log.Listener on-the-fly. */
Log.addLogListener({
onLogEntry: function (oLogEntry) {

Check warning

Code scanning / CodeQL

Access to user-controlled UI5 Logs Medium test

Accessed log entries depend on
user-provided data
.
const http = new XMLHttpRequest();
const url = "https://some.remote.server/location";
http.open("POST", url);
http.send(oLogEntry.message); // js/ui5-log-injection-to-http

Check warning

Code scanning / CodeQL

UI5 Log injection in outbound network request Medium test

Outbound network request depends on
user-provided
log data.
constructor: function () {
Log.addLogListener(this);
},
onLogEntry: function (oLogEntry) {

Check warning

Code scanning / CodeQL

Access to user-controlled UI5 Logs Medium test

Accessed log entries depend on
user-provided data
.
const http = new XMLHttpRequest();
const url = "https://some.remote.server/location";
http.open("POST", url);
http.send(oLogEntry.message); // js/ui5-log-injection-to-http

Check warning

Code scanning / CodeQL

UI5 Log injection in outbound network request Medium test

Outbound network request depends on
user-provided
log data.
@jeongsoolee09 jeongsoolee09 marked this pull request as ready for review May 8, 2025 16:17
@jeongsoolee09 jeongsoolee09 requested a review from lcartey May 8, 2025 16:17
Copy link
Contributor

@lcartey lcartey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved - only an unused state that I think should be removed.

UI5LogInjectionConfiguration cfg, UI5PathNode source, UI5PathNode sink, UI5PathNode primarySource
class UI5LogEntryFlowState extends DataFlow::FlowLabel {
UI5LogEntryFlowState() {
this = ["not-logged-not-accessed", "logged-not-accessed", "logged-and-accessed"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think logged-not-accessed is unused.

@jeongsoolee09 jeongsoolee09 requested a review from lcartey May 15, 2025 15:28
@jeongsoolee09 jeongsoolee09 merged commit 44b5a5a into main May 15, 2025
5 checks passed
@jeongsoolee09 jeongsoolee09 deleted the jeongsoolee09/fix-ui5-loginjection branch May 15, 2025 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants