forked from SAP/project-foxhound
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Report taint sink non string #8
Open
alexbara2000
wants to merge
10
commits into
tmbrbr:primitaint-merge
Choose a base branch
from
alexbara2000:report-taint-sink-non-string
base: primitaint-merge
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 all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
67f4baf
Trying to get values of an JS object
alexbara2000 183a856
Adding support for number and object taint report
alexbara2000 37c0ed8
Fixed some bugs
alexbara2000 2905031
Added message port as sink
alexbara2000 b51763a
Removed debug statements
alexbara2000 50ae5cc
refactored report taint sink to remove code duplication. Logic is the…
alexbara2000 b066ec5
removed commented code
alexbara2000 98f80a1
Added tests for message port sink and non string sinks
alexbara2000 ac1bd0e
Added message port sink to all.js
alexbara2000 e2033d3
Added 2 new sinks for post messages
alexbara2000 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 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 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 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 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 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 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 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 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,77 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Test HTML Message Port Taint Sink</title> | ||
<script src="/tests/SimpleTest/SimpleTest.js"></script> | ||
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/> | ||
<script> | ||
|
||
let string_content = "hello"; | ||
let sink_name = "MessagePort.PostMessage"; | ||
let number_of_tainted_flows = 1; | ||
|
||
let i = 0; | ||
|
||
SimpleTest.waitForExplicitFinish(); | ||
addEventListener("__taintreport", (report) => { | ||
is(report.detail.str, string_content, "Check sink string content"); | ||
|
||
let flow = report.detail.str.taint[0].flow; | ||
is(flow[0].operation, sink_name); | ||
|
||
i += 1; | ||
if (i >= number_of_tainted_flows) { | ||
SimpleTest.finish(); | ||
} | ||
}, false); | ||
|
||
let taint_string = String.tainted(string_content); | ||
|
||
// Worker script as a Blob | ||
const workerScript = ` | ||
self.onmessage = (event) => { | ||
if (event.data === 'initialize') { | ||
// Retrieve the port from the message | ||
const port = event.ports[0]; | ||
|
||
// Listen for messages on the port | ||
port.onmessage = (event) => { | ||
console.log(JSON.stringify(event)); | ||
port.postMessage("Received the event"); | ||
}; | ||
|
||
// Send an initial message back to the main page | ||
port.postMessage('Worker initialized and ready.'); | ||
} | ||
}; | ||
`; | ||
if (window.Worker) { | ||
const blob = new Blob([workerScript], { type: 'application/javascript' }); | ||
const workerUrl = URL.createObjectURL(blob); | ||
|
||
const worker = new Worker(workerUrl); | ||
|
||
const channel = new MessageChannel(); | ||
|
||
// Send one of the ports to the worker | ||
worker.postMessage('initialize', [channel.port1]); | ||
|
||
// Listen for messages from the worker | ||
channel.port2.onmessage = (event) => { | ||
console.log('Message received from worker:', event.data); | ||
}; | ||
|
||
channel.port2.postMessage(taint_string); | ||
} else { | ||
console.error('No support for workers'); | ||
} | ||
</script> | ||
</head> | ||
<body> | ||
<p id="display"></p> | ||
<div id="content" style="display: none"></div> | ||
<p id="test"></p> | ||
<button id="btn"></button> | ||
</body> | ||
</html> |
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.
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.
I see what you want to do here, but this could be fairly spammy. Is this missing a check for taintedness?
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.
I do agree that it could be pretty spammy going over an object recursively to see if it is tainted. However, I don't see a better way of doing it. The JSObject does not hold a flag to say if it is tainted or not. So, to know if a value inside this object is tainted, we have to go over it recursively. On the bright side, this piece of code will not be called often. Most sinks like XML Http request will automatically convert JSObjects to nsACString before calling the report taint sinks.
Under the hood, XML Http request will take an object and do the equivalent of JSON.Stringify before calling the send function. So from a report taint sink perspective, it will see this as a string not an object and the the recursive code will not be called.
This change is to support the new sink that I have added for MessagePort.postMessage. This is one of the only sinks that sends the JSValue itself instead of the nsACString. For this case, we have to look over the object and check to see if it is tainted or not.
That being I am open to suggestions on how to make this code better. Maybe add a flag to JSObject to keep track if it is tainted or not?