Closed Bug 1404367 Opened 4 years ago Closed 2 years ago

"View Source" fails if page not in web_accessible_resources

Categories

(Toolkit :: View Source, defect, P1)

defect

Tracking

()

VERIFIED FIXED
mozilla70
Tracking Status
firefox55 --- wontfix
firefox56 --- wontfix
firefox57 --- wontfix
firefox58 --- wontfix
firefox70 --- verified

People

(Reporter: mcoman, Assigned: ckerschb)

References

Details

Attachments

(2 files)

[Affected versions]:
- Firefox Notes 1.8.0dev
- Firefox 55 and up

[Affected Platforms]:
- All Windows
- All Mac
- All Linux

[Prerequisites]:
- Have a Firefox profile with the latest "Firefox Notes" add-on version (1.8.0dev) installed.

[Steps to reproduce]:
1. Open the browser with the profiles from prerequisites.
2. Write a string in the "Notes" sidebar.
3. Select all content and right click.
4. Click  the "View Selection Source" option and observe the browser behavior.

[Expected result]:
- Another tab is opened and the source of the selection is displayed.

[Actual result]:
- Nothing happens.

[Notes]:
- Attached a screen recording of the issue.
Shane, looks like we dupe this to one of the similar "developer tools" not working in the sidebar bugs?
Flags: needinfo?(mixedpuppy)
Noting that this fails on any HTML sidebar, it's not Notes specific.
Priority: -- → P5
Summary: The "View Selection Source" does not work on "Firefox Notes" sidebar → The "View Selection Source" does not work on any sidebar
Whether it is selection (which also doesn't work on osx) or page source, view source is not working in any extension panel.  Easy fix is to disable those context menus, we should probably do that for 57 and have a followup to actually fix it, but worth taking a look at code first to make that determination.

Should also check if the selection must be clicked on to work, the gif shows the selection clicked on when in the tab.
Assignee: nobody → mixedpuppy
Flags: needinfo?(mixedpuppy)
Priority: P5 → P1
Summary: The "View Selection Source" does not work on any sidebar → "View Source" does not work
I wouldn't worry about shipping it for 57, we shipped this in a few other releases and didn't mind. It doesn't cause perf, security problems or data loss, its polish. How about a P3.
Priority: P1 → P3
Priority: P3 → P2
Summary: "View Source" does not work → "View Source" fails if page not in web_accessible_resources
Security Error: Content at moz-nullprincipal:{aa432ea6-64b0-b14d-8fc1-5bf5cf3d7e45} may not load data from moz-extension://1006c9eb-a454-4542-90a8-3c3e02e66da1/panel.html.
Security Error: Content at moz-nullprincipal:{277fc1a0-98a3-f846-9064-e8b41fa20990} may not load data from moz-extension://1006c9eb-a454-4542-90a8-3c3e02e66da1/panel.html.
NS_ERROR_DOM_BAD_URI: Component returned failure code: 0x805303f4 [nsIWebNavigation.loadURI] viewSource-content.js:291
Product: Toolkit → WebExtensions
Duplicate of this bug: 1565245
Duplicate of this bug: 1435485

This is a weird bug. Docshell complains because the channel "has been cross origin" because it thinks that some null principal'd thing (I think the about:blank page that we load before) is the thing that's loading the view-source:moz-extension page content. Stack:

#0	0x00000001171d9059 in mozilla::BasePrincipal::CheckMayLoad(nsIURI*, bool, bool) at mozilla-unified/caps/BasePrincipal.cpp:372
#1	0x00000001168104e7 in NS_HasBeenCrossOrigin(nsIChannel*, bool) at mozilla-unified/netwerk/base/nsNetUtil.cpp:2012
#2	0x0000000118aac340 in DoSOPChecks(nsIURI*, nsILoadInfo*, nsIChannel*) [inlined] at mozilla-unified/dom/security/nsContentSecurityManager.cpp:406
#3	0x0000000118aac333 in nsContentSecurityManager::CheckChannel(nsIChannel*) at mozilla-unified/dom/security/nsContentSecurityManager.cpp:1084
#4	0x0000000118aab222 in nsContentSecurityManager::doContentSecurityCheck(nsIChannel*, nsCOMPtr<nsIStreamListener>&) at mozilla-unified/dom/security/nsContentSecurityManager.cpp:966
#5	0x000000011702f0e4 in nsJARChannel::AsyncOpen(nsIStreamListener*) at mozilla-unified/modules/libjar/nsJARChannel.cpp:851
#6	0x0000000116bb6d84 in mozilla::net::NewSimpleChannel(nsIURI*, nsILoadInfo*, nsIChannel*, nsIChannel**)::$_9::operator()(nsIStreamListener*, nsIChannel*, nsIChannel*) const [inlined] at mozilla-unified/netwerk/protocol/res/ExtensionProtocolHandler.cpp:885
#7	0x0000000116bb6d75 in mozilla::net::SimpleChannelCallbacksImpl<mozilla::net::NewSimpleChannel(nsIURI*, nsILoadInfo*, nsIChannel*, nsIChannel**)::$_9, already_AddRefed<nsIChannel> NS_NewSimpleChannel<nsIChannel, mozilla::net::NewSimpleChannel(nsIURI*, nsILoadInfo*, nsIChannel*, nsIChannel**)::$_9>(nsIURI*, nsILoadInfo*, nsIChannel*, mozilla::net::NewSimpleChannel(nsIURI*, nsILoadInfo*, nsIChannel*, nsIChannel**)::$_9&&)::'lambda'(bool, nsIChannel*, nsIChannel*), nsIChannel>::StartAsyncRead(nsIStreamListener*, nsIChannel*) at mozilla-unified/netwerk/base/SimpleChannel.h:61
#8	0x00000001167dc632 in mozilla::net::SimpleChannel::BeginAsyncRead(nsIStreamListener*, nsIRequest**) at mozilla-unified/netwerk/base/SimpleChannel.cpp:50
#9	0x00000001167e393f in nsBaseChannel::BeginPumpingData() at mozilla-unified/netwerk/base/nsBaseChannel.cpp:221
#10	0x00000001167dd040 in nsBaseChannel::AsyncOpen(nsIStreamListener*) at mozilla-unified/netwerk/base/nsBaseChannel.cpp:678
#11	0x0000000116bba8ae in nsViewSourceChannel::AsyncOpen(nsIStreamListener*) at mozilla-unified/netwerk/protocol/viewsource/nsViewSourceChannel.cpp:313
#12	0x00000001171aeb17 in nsURILoader::OpenURI(nsIChannel*, unsigned int, nsIInterfaceRequestor*) at mozilla-unified/uriloader/base/nsURILoader.cpp:847
#13	0x0000000119f73aad in nsDocShell::OpenInitializedChannel(nsIChannel*, nsIURILoader*, unsigned int) at mozilla-unified/docshell/base/nsDocShell.cpp:10721
#14	0x0000000119f74192 in nsDocShell::DoChannelLoad(nsIChannel*, nsIURILoader*, bool) at mozilla-unified/docshell/base/nsDocShell.cpp:10680
#15	0x0000000119f736f6 in nsDocShell::DoURILoad(nsDocShellLoadState*, bool, nsIDocShell**, nsIRequest**) at mozilla-unified/docshell/base/nsDocShell.cpp:10483
#16	0x0000000119f55339 in nsDocShell::InternalLoad(nsDocShellLoadState*, nsIDocShell**, nsIRequest**) at mozilla-unified/docshell/base/nsDocShell.cpp:9745
#17	0x0000000119f5422c in nsDocShell::LoadHistoryEntry(nsISHEntry*, unsigned int) at mozilla-unified/docshell/base/nsDocShell.cpp:11910
#18	0x0000000119f65116 in nsDocShell::LoadPage(nsISupports*, unsigned int) at mozilla-unified/docshell/base/nsDocShell.cpp:4883

LoadPage correctly sets a system principal as the triggering principal, but somehow we end up with a null principal as the loading principal. AFAICT we should have no loading principal at all - the NS_HasBeenCrossOrigin would then bail out immediately, and this should be a TYPE_DOCUMENT load so that'd make sense to me. Of course, perhaps things have changed and some of the comments are stale...

Christoph, can you check what's going on here? I suspect this is a docshell bug despite the component...

Flags: needinfo?(ckerschb)

I just checked out the latest central and followed the STRs from comment 0.

If I write 'foobar' in the notes and then right-click->'View Selection Source' then I observe the following load:

uri: data:text/html;charset=utf-8,%3Cp%3E%EF%B7%90foobar%EF%B7%AF%3C%2Fp%3E
type: 6
loadingPrincipal: nullPtr
triggeringPrincipal: SystemPrincipal

type: 6 is a load of TYPE_DOCUMENT, the loadiingPrincipal is a nullptr and the triggeringPrincipal is system. A new tab opens and displays:
<p>foobar</p>

In other words, I can't reproduce, this seems to work correctly for me. Anything I am missing?

Flags: needinfo?(ckerschb)

(In reply to Christoph Kerschbaumer [:ckerschb] from comment #9)

I just checked out the latest central and followed the STRs from comment 0.

If I write 'foobar' in the notes and then right-click->'View Selection Source' then I observe the following load:

uri: data:text/html;charset=utf-8,%3Cp%3E%EF%B7%90foobar%EF%B7%AF%3C%2Fp%3E
type: 6
loadingPrincipal: nullPtr
triggeringPrincipal: SystemPrincipal

type: 6 is a load of TYPE_DOCUMENT, the loadiingPrincipal is a nullptr and the triggeringPrincipal is system. A new tab opens and displays:
<p>foobar</p>

In other words, I can't reproduce, this seems to work correctly for me. Anything I am missing?

Notes may have worked around this bug. Here are working STR:

  1. Install any extension which replace a New Tab and doesn't mark their content web-accessible (like https://addons.mozilla.org/en-GB/firefox/addon/new-tab-by-yahoo/).
  2. Open new tab with page from extension.
  3. Try to get source with context menu "View Page Source" (or accel-u to view source, or some other UI entry point to view page source)

Can you reproduce with that?

Flags: needinfo?(ckerschb)

(In reply to :Gijs (he/him) from comment #10)

Can you reproduce with that?

Yes, thanks for providing the STRs and sorry for the lag. The problem is that we enforce two security checks. Where the first one passes correctly but then the second one fails.

First Security check using the following arguments passes:

channelURI: view-source:moz-extension://3a214f9c-2588-4476-9083-469e235341f7/newtab.html
loadingPrincipal: nullptr
triggeringPrincipal: SystemPrincipal
principalToInherit: moz-extension://3a214f9c-2588-4476-9083-469e235341f7/
contentPolicyType: 6
securityMode: SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
initalSecurityChecksDone: no

Second Security check using the following arguments fails:

channelURI: moz-extension://3a214f9c-2588-4476-9083-469e235341f7/newtab.html
loadingPrincipal: NullPrincipal
triggeringPrincipal: NullPrincipal
principalToInherit: nullptr
contentPolicyType: 1
securityMode: SEC_REQUIRE_SAME_ORIGIN_DATA_IS_BLOCKED,
initalSecurityChecksDone: no

It seems when creating a ViewSourceChannel [1], we first create a dummy loadinfo which then gets overwritten by the real loadinfo. I guess that still predates when we had NewChannelFromURIWithLoadInfo. Anyway, it seems we cache the initially created channel (using the dummy loadinfo) which we then reuse (see stacktrace underneath for the second load). I didn't dig into the problem all too deep because of timing constraints.

I'll upload a patch in a minute which will pass the loadinfo along to the Init() method which already creates the channel using the correct loafinfo which makes the problem disappear. Again, we should have done that in the first place, but I guess that code predates the existence of NewChannelFromURIWithLoadInfo.

Doing that, right-click view-source works as expected again.

[1] https://searchfox.org/mozilla-central/source/netwerk/protocol/viewsource/nsViewSourceChannel.cpp#64-81

#0 0x00007f58ff0f89d0 in __GI___nanosleep (requested_time=requested_time@entry=0x7ffc2bd10240, remaining=remaining@entry=0x7ffc2bd10240) at ../sysdeps/unix/sysv/linux/nanosleep.c:28
#1 0x00007f58ff0f88aa in __sleep (seconds=0) at ../sysdeps/posix/sleep.c:55
#2 0x00007f58f04fde2a in ah_crap_handler(int) (signum=11) at /home/ckerschb/source/mc/toolkit/xre/nsSigHandlers.cpp:95
#3 0x00007f58f04fdf76 in child_ah_crap_handler(int) (signum=11) at /home/ckerschb/source/mc/toolkit/xre/nsSigHandlers.cpp:105
#4 0x00007f58f0debc3b in js::UnixExceptionHandler(int, siginfo_t*, void*) (signum=11, info=0x7ffc2bd104f0, context=0x7ffc2bd103c0) at /home/ckerschb/source/mc/js/src/ds/MemoryProtectionExceptionHandler.cpp:278
#5 0x00007f58f1a95dde in WasmTrapHandler(int, siginfo_t*, void*) (signum=11, info=0x7ffc2bd104f0, context=0x7ffc2bd103c0) at /home/ckerschb/source/mc/js/src/wasm/WasmSignalHandlers.cpp:962
#6 0x00007f58fff5a890 in <signal handler called> () at /lib/x86_64-linux-gnu/libpthread.so.0
#7 0x00007f58ecf1f2ed in DoSOPChecks(nsIURI*, nsILoadInfo*, nsIChannel*) (aURI=0x7f58d5fad800, aLoadInfo=0x7f58d91d3430, aChannel=0x7f58d603b5f0)
at /home/ckerschb/source/mc/dom/security/nsContentSecurityManager.cpp:719
#8 0x00007f58ecf1dc4b in nsContentSecurityManager::CheckChannel(nsIChannel*) (aChannel=0x7f58d603b5f0) at /home/ckerschb/source/mc/dom/security/nsContentSecurityManager.cpp:1509
#9 0x00007f58ecf1c31e in nsContentSecurityManager::doContentSecurityCheck(nsIChannel*, nsCOMPtr<nsIStreamListener>&) (aChannel=0x7f58d603b5f0, aInAndOutListener=...)
at /home/ckerschb/source/mc/dom/security/nsContentSecurityManager.cpp:1391
#10 0x00007f58e9845857 in nsJARChannel::AsyncOpen(nsIStreamListener*) (this=0x7f58d603b5f0, aListener=0x7f58da612130) at /home/ckerschb/source/mc/modules/libjar/nsJARChannel.cpp:851
#11 0x00007f58e8c13df4 in mozilla::net::NewSimpleChannel(nsIURI*, nsILoadInfo*, nsIChannel*, nsIChannel**)::$_9::operator()(nsIStreamListener*, nsIChannel*, nsIChannel*) const (this=0x7f58d91a05e8, listener=0x7f58da612130, simpleChannel=0x7f58da6120e8, origChannel=0x7f58d603b5f0) at /home/ckerschb/source/mc/netwerk/protocol/res/ExtensionProtocolHandler.cpp:881
#12 0x00007f58e8c13ce2 in mozilla::net::SimpleChannelCallbacksImpl<mozilla::net::NewSimpleChannel(nsIURI*, nsILoadInfo*, nsIChannel*, nsIChannel**)::$_9(already_AddRefed<nsIChannel> NS_NewSimpleChannel<nsIChannel, NS_NewSimpleChannel>(nsIURI*, nsILoadInfo*, nsIChannel*, NS_NewSimpleChannel&&)::{lambda(bool, nsIChannel*, nsIChannel*)#1}, nsIChannel)>::StartAsyncRead(nsIStreamListener*, nsIChannel*) (this=0x7f58d91a05e0, listener=0x7f58da612130, channel=0x7f58da6120e8) at /home/ckerschb/source/mc/netwerk/base/SimpleChannel.h:61
#13 0x00007f58e845abec in mozilla::net::SimpleChannel::BeginAsyncRead(nsIStreamListener*, nsIRequest**) (this=0x7f58da6120a0, listener=0x7f58da612130, request=0x7f58da612148)
at /home/ckerschb/source/mc/netwerk/base/SimpleChannel.cpp:50
#14 0x00007f58e8467428 in nsBaseChannel::BeginPumpingData() (this=0x7f58da6120a0) at /home/ckerschb/source/mc/netwerk/base/nsBaseChannel.cpp:221
#15 0x00007f58e845be7b in nsBaseChannel::AsyncOpen(nsIStreamListener*) (this=0x7f58da6120a0, aListener=0x7f58d6012a08) at /home/ckerschb/source/mc/netwerk/base/nsBaseChannel.cpp:678
#16 0x00007f58e8c28755 in nsViewSourceChannel::AsyncOpen(nsIStreamListener*) (this=0x7f58d6012a00, aListener=0x7f58d60dd220) at /home/ckerschb/source/mc/netwerk/protocol/viewsource/nsViewSourceChannel.cpp:319
#17 0x00007f58e9b98a66 in nsURILoader::OpenURI(nsIChannel*, unsigned int, nsIInterfaceRequestor*) (this=0x7f58dbf75160, channel=0x7f58d6012a00, aFlags=0, aWindowContext=0x7f58d9031830)
at /home/ckerschb/source/mc/uriloader/base/nsURILoader.cpp:840
#18 0x00007f58efd27993 in nsDocShell::OpenInitializedChannel(nsIChannel*, nsIURILoader*, unsigned int) (this=0x7f58d9031800, aChannel=0x7f58d6012a00, aURILoader=0x7f58dbf75160, aOpenFlags=0)
at /home/ckerschb/source/mc/docshell/base/nsDocShell.cpp:10615
#19 0x00007f58efd28972 in nsDocShell::DoChannelLoad(nsIChannel*, nsIURILoader*, bool) (this=0x7f58d9031800, aChannel=0x7f58d6012a00, aURILoader=0x7f58dbf75160, aBypassClassifier=false)
at /home/ckerschb/source/mc/docshell/base/nsDocShell.cpp:10574
#20 0x00007f58efd2742c in nsDocShell::DoURILoad(nsDocShellLoadState*, bool, nsIDocShell**, nsIRequest**) (this=0x7f58d9031800, aLoadState=0x7f58d60e09e0, aLoadFromExternal=false, aDocShell=0x0, aRequest=0x7ffc2bd12ab8) at /home/ckerschb/source/mc/docshell/base/nsDocShell.cpp:10377
#21 0x00007f58efcf7788 in nsDocShell::InternalLoad(nsDocShellLoadState*, nsIDocShell**, nsIRequest**) (this=0x7f58d9031800, aLoadState=0x7f58d60e09e0, aDocShell=0x0, aRequest=0x0)
at /home/ckerschb/source/mc/docshell/base/nsDocShell.cpp:9639
#22 0x00007f58efcf511f in nsDocShell::LoadHistoryEntry(nsISHEntry*, unsigned int) (this=0x7f58d9031800, aEntry=0x7f58d9ad33e0, aLoadType=4) at /home/ckerschb/source/mc/docshell/base/nsDocShell.cpp:11816
#23 0x00007f58efd0d9ef in nsDocShell::LoadPage(nsISupports*, unsigned int) (this=0x7f58d9031800, aPageDescriptor=0x7f58d60040c0, aDisplayType=1) at /home/ckerschb/source/mc/docshell/base/nsDocShell.cpp:4764
#24 0x00007f58e82e5056 in NS_InvokeByIndex () at /home/ckerschb/source/mc/xpcom/reflect/xptcall/md/unix/xptcinvoke_asm_x86_64_unix.S:106
#25 0x00007f58e982a954 in CallMethodHelper::Invoke() (this=0x7ffc2bd13348) at /home/ckerschb/source/mc/js/xpconnect/src/XPCWrappedNative.cpp:1658
#26 0x00007f58e98227ef in CallMethodHelper::Call() (this=0x7ffc2bd13348) at /home/ckerschb/source/mc/js/xpconnect/src/XPCWrappedNative.cpp:1195
#27 0x00007f58e9805919 in XPCWrappedNative::CallMethod(XPCCallContext&, XPCWrappedNative::CallMode) (ccx=..., mode=XPCWrappedNative::CALL_METHOD)
at /home/ckerschb/source/mc/js/xpconnect/src/XPCWrappedNative.cpp:1157
#28 0x00007f58e98073a2 in XPC_WN_CallMethod(JSContext*, unsigned int, JS::Value*) (cx=0x7f58ddb2f000, argc=2, vp=0x7f58d8e13280) at /home/ckerschb/source/mc/js/xpconnect/src/XPCWrappedNativeJSOps.cpp:943
#29 0x00007f58f06daaaf in CallJSNative(JSContext*, bool ()(JSContext, unsigned int, JS::Value*), JS::CallArgs const&) (cx=0x7f58ddb2f000, native=0x7f58e9806fe0 <XPC_WN_CallMethod(JSContext*, unsigned int, JS::Value*)>, args=...) at /home/ckerschb/source/mc/js/src/vm/Interpreter.cpp:447
#30 0x00007f58f06c556a in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) (cx=0x7f58ddb2f000, args=..., construct=js::NO_CONSTRUCT)
at /home/ckerschb/source/mc/js/src/vm/Interpreter.cpp:539
#31 0x00007f58f06c5c45 in InternalCall(JSContext*, js::AnyInvokeArgs const&) (cx=0x7f58ddb2f000, args=...) at /home/ckerschb/source/mc/js/src/vm/Interpreter.cpp:594
#32 0x00007f58f06c5a2d in js::CallFromStack(JSContext*, JS::CallArgs const&) (cx=0x7f58ddb2f000, args=...) at /home/ckerschb/source/mc/js/src/vm/Interpreter.cpp:598
#33 0x00007f58f06b903d in Interpret(JSContext*, js::RunState&) (cx=0x7f58ddb2f000, state=...) at /home/ckerschb/source/mc/js/src/vm/Interpreter.cpp:3084
#34 0x00007f58f06adf55 in js::RunScript(JSContext*, js::RunState&) (cx=0x7f58ddb2f000, state=...) at /home/ckerschb/source/mc/js/src/vm/Interpreter.cpp:424
#35 0x00007f58f06c5728 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) (cx=0x7f58ddb2f000, args=..., construct=js::NO_CONSTRUCT)
at /home/ckerschb/source/mc/js/src/vm/Interpreter.cpp:567
#36 0x00007f58f06c5c45 in InternalCall(JSContext*, js::AnyInvokeArgs const&) (cx=0x7f58ddb2f000, args=...) at /home/ckerschb/source/mc/js/src/vm/Interpreter.cpp:594
#37 0x00007f58f06c5cf0 in js::Call(JSContext*, JS::Handle<JS::Value>, JS::Handle<JS::Value>, js::AnyInvokeArgs const&, JS::MutableHandle<JS::Value>) (cx=0x7f58ddb2f000, fval=..., thisv=..., args=..., rval=...)
at /home/ckerschb/source/mc/js/src/vm/Interpreter.cpp:610
#38 0x00007f58f0e352f5 in JS::Call(JSContext*, JS::Handle<JS::Value>, JS::Handle<JS::Value>, JS::HandleValueArray const&, JS::MutableHandle<JS::Value>) (cx=0x7f58ddb2f000, thisv=..., fval=..., args=..., rval=...)
at /home/ckerschb/source/mc/js/src/jsapi.cpp:2722
#39 0x00007f58eae3b63d in mozilla::dom::MessageListener::ReceiveMessage(JSContext*, JS::Handle<JS::Value>, mozilla::dom::ReceiveMessageArgument const&, JS::MutableHandle<JS::Value>, mozilla::ErrorResult&) (this=
---Type <return> to continue, or q <return> to quit---

Flags: needinfo?(ckerschb)

Stealing the assignment since I have a patch - hopefully that's ok with you Shane :-)

Assignee: mixedpuppy → ckerschb
Status: NEW → ASSIGNED
Priority: P2 → P1
Component: General → View Source
Product: WebExtensions → Toolkit

Pushed by ccoroiu@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/61a0b22d978a
Pass LoadInfo of channel to nsViewSourceChannel::Init. r=Gijs

Keywords: checkin-needed
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla70
Flags: qe-verify+

Confirmed issue with 58.0a1 (2017-09-21) using steps from comment 10.
Verified fix with 70.0b8 on Windows 10, Ubuntu 16.04, macOS 10.12.

Status: RESOLVED → VERIFIED
Flags: qe-verify+
You need to log in before you can comment on or make changes to this bug.