Filename validation leaves pending exception on JSContext
Categories
(Firefox :: Security, defect)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox-esr91 | --- | unaffected |
| firefox95 | --- | unaffected |
| firefox96 | --- | unaffected |
| firefox97 | --- | wontfix |
| firefox98 | --- | fixed |
People
(Reporter: mgaudet, Assigned: tjr)
References
(Regression)
Details
(Keywords: regression)
Attachments
(1 file, 1 external file)
|
2.96 KB,
patch
|
Details | Diff | Splinter Review |
(Found using local branch, so I can't quite provide an STR)
Bug 1746231 added this
// If we got here we are going to return false, so set the error context
const char* utf8Filename;
if (mozilla::IsUtf8(mozilla::MakeStringSpan(aFilename))) {
utf8Filename = aFilename;
} else {
utf8Filename = "(invalid UTF-8 filename)";
}
JS_ReportErrorNumberUTF8(cx, js::GetErrorMessage, nullptr,
JSMSG_UNSAFE_FILENAME, utf8Filename);
}
The problem is that immediately following, we have this code:
// Presently we are not enforcing any restrictions for the script filename,
// we're only reporting Telemetry. In the future we will assert in debug
// builds and return false to prevent execution in non-debug builds.
return true;
We can't have a JS_ReportErrror* without returning false, or else this leaves a pending exception on the JS Context, which then will assert at the next AutoAssertNoPendingException.
There's currently no coverage of this path, so I seem to have tripped over it accidentally.
In my case:
#7 0x00007f23c546322b in nsContentSecurityUtils::ValidateScriptFilename(JSContext*, char const*)
(cx=0x7f23b0023200, aFilename=0x7f23ae272700 "/home/matthew/unified/obj-debug-browser-x86_64-pc-linux-gnu/_tests/xpcshell/dom/streams/test/xpcshell/head.js line 12 > eval") at /home/matthew/unified/dom/security/nsContentSecurityUtils.cpp:1393
is the call, and the associated file name.
| Reporter | ||
Comment 1•4 years ago
|
||
This is the test patch I'm evaluating. This used to run before the regressing bug landed.
If I tweak ValidateFilename to correctly return false, what I then see is
Unexpected exception InternalError: unsafe filename: /home/matthew/unified/obj-debug-browser-x86_64-pc-linux-gnu/_tests/xpcshell/dom/streams/test/xpcshell/head.js line 12 > eval at /home/matthew/unified/obj-debug-browser-x86_64-pc-linux-gnu/_tests/xpcshell/dom/streams/test/xpcshell/head.js:12"
from this eval:
+function addTestingFunctionsToGlobal(global) {
+ global.eval(
+ `
+ const testingFunctions = Cu.getJSTestingFunctions();
+ for (let k in testingFunctions) {
+
+ this[k] = testingFunctions[k];
+ }
+ `
+ );
Of course, I can't control the filename here, so not sure what the right fix is here...
| Reporter | ||
Updated•4 years ago
|
| Reporter | ||
Comment 2•4 years ago
|
||
I've unblocked myself with
[bug-1387503-1.js]
prefs=
security.allow_parent_unrestricted_js_loads=true
in the xpcshell.ini
| Assignee | ||
Comment 3•4 years ago
|
||
In 1746231 the JS Exception stuff was moved from the
callback call site into the callback itself.
However, when it was moved, an exception could be
added even if we were going to permit the script
execution. This is wrong.
Move the exception stuff back to the callback site
and use the result of the callback to determine if
we add anything to the stack or not
Updated•4 years ago
|
Updated•4 years ago
|
Comment 4•4 years ago
|
||
Set release status flags based on info from the regressing bug 1746231
Comment 6•4 years ago
|
||
| bugherder | ||
Updated•4 years ago
|
Updated•4 years ago
|
Description
•