Closed Bug 1748870 Opened 4 years ago Closed 4 years ago

Filename validation leaves pending exception on JSContext

Categories

(Firefox :: Security, defect)

defect

Tracking

()

RESOLVED FIXED
98 Branch
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)

(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.

Attached patch Test.patch — — Splinter Review

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...

Assignee: nobody → mgaudet
Assignee: mgaudet → nobody
Flags: needinfo?(tom)

I've unblocked myself with

[bug-1387503-1.js]
prefs=
  security.allow_parent_unrestricted_js_loads=true

in the xpcshell.ini

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

Assignee: nobody → tom
Status: NEW → ASSIGNED

Set release status flags based on info from the regressing bug 1746231

Pushed by tritter@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/8ba31aff94a2 Do not leave a pending JS Exception on the stack r=mgaudet
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 98 Branch
Flags: needinfo?(tom)
Has Regression Range: --- → yes
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: