Closed Bug 1747547 Opened 4 years ago Closed 10 months ago

Inject scripts in formerly-XML iframes

Categories

(WebExtensions :: General, defect, P3)

Firefox 94
defect

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: a.minyukovich, Assigned: robwu)

References

(Depends on 1 open bug)

Details

(Whiteboard: [addons-jira])

Attachments

(2 external files)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:88.0) Gecko/20100101 Firefox/88.0

Steps to reproduce:

Trying to inject content_scripts from manifest.json in an iframe that apparently started out as XML, but was transformed (not fully sure how) in a regular HTML page.

Actual results:

Scripts not injected.

Expected results:

Scripts injected, probably at the moment the transformation from XML to HTML happened - since these iframes function/appear like any regular iframe.

My current workaround is to manually inject scripts (with tabs.executeScript).

Here is a test addon I used to check I wasn't going insane: https://github.com/aliko-str/HighlightTST

It loads 2 pages. "https://www.aeroclubofindia.com/contact.html" - has red borders around iframes; "https://equitygroupholdings.com/ug/" doesn't.

I am able to reproduce this issue on FF96.0b9 using the addon found at https://github.com/aliko-str/HighlightTST .

I will mark the issue as new for further investigations.

Status: UNCONFIRMED → NEW
Ever confirmed: true

I will take a look into this.

Flags: needinfo?(lgreco)

Could this be related to bug 1744992?

The patch attached in comment 4 contains a reduced test case for the issue, based on what I observed while trying the STR from comment 0.

Based on a quick mozregression run it doesn't seem a new regression.

The issue severity may be set to S4 with the following rationale:

  • the extensions can at least workaround the issue on their side using "run_at" set to "document_start" or "document_idle"

(In reply to Rob Wu [:robwu] from comment #3)

Could this be related to bug 1744992?

They looks like slightly different unexpected behaviors, but they are both clearly related to the same scenario (attaching a content script to a XML document being transformed by an XSLT stylesheet) and internals (WebExtensions internals and XSLT Processor), I wouldn't exclude that their root cause may be the same or at least in the same area.

Follows some more details from the investigation.


As the attached test also demonstrates, the issue is actually triggered when a content script run_at: "document_end" should be attached to an XML document being transformed by an XSLT linked to the XML document itself.

The injection gets stuck waiting for promiseDocumentReady which it is actually never resolved, see the Script class InjectInto method, defined in ExtensionContent.jsm here:

try {
  if (this.runAt === "document_end") {
    await promiseDocumentReady(window.document);
    ...

If the same script has run_at: "document_idle" instead, it gets injected as expected.

promiseDocumentReady (defined in ExtensionUtils.jsm here) resolves immediately if the document has readyState "complete" or "interactive", otherwise it waits for DOMContentLoaded to be fired for the document the content script is being attached to.

By recording the attached test case using rr, I did notice that the content script injection is being triggered by txMozillaXSLTProcessor, it looks that it is being triggered when we are creating a new HTML document as part of the XSLT transformation:

#30 0x00007f45ffaac99a in mozilla::ExtensionPolicyService::CheckContentScripts(mozilla::extensions::DocInfo const&, bool) (this=this@entry=0x7f45f32e17c0, aDocInfo=..., aIsPreload=false) at /builds/worker/checkouts/gecko/toolkit/components/extensions/ExtensionPolicyService.cpp:488
#31 0x00007f45ffaab25f in mozilla::ExtensionPolicyService::CheckDocument(mozilla::dom::Document*) (this=this@entry=0x7f45f32e17c0, aDocument=0x7f45f3287200) at /builds/worker/checkouts/gecko/toolkit/components/extensions/ExtensionPolicyService.cpp:442
#32 0x00007f45ffaab16b in mozilla::ExtensionPolicyService::Observe(nsISupports*, char const*, char16_t const*) (this=0x7f45f32e17c0, aSubject=0x7f45f3287200, aTopic=<optimized out>, aData=0x7f45f8c783ee u"")
    at /builds/worker/checkouts/gecko/toolkit/components/extensions/ExtensionPolicyService.cpp:234
#33 0x00007f45ffaab75f in non-virtual thunk to mozilla::ExtensionPolicyService::Observe(nsISupports*, char const*, char16_t const*) () at /builds/worker/workspace/obj-build/dist/include/nsILoadInfo.h:450
#34 0x00007f45fb83861c in nsObserverList::NotifyObservers(nsISupports*, char const*, char16_t const*) (this=<optimized out>, aSubject=0x7f45f3287200, aTopic=0x7f45f8b753e4 "initial-document-element-inserted", someData=0x7f45f8c783ee u"")
    at /builds/worker/checkouts/gecko/xpcom/ds/nsObserverList.cpp:70
#35 0x00007f45fb83bbb2 in nsObserverService::NotifyObservers(nsISupports*, char const*, char16_t const*) (this=<optimized out>, aSubject=0x7f45f3287200, aTopic=0x7f45f8b753e4 "initial-document-element-inserted", aSomeData=0x7f45f8c783ee u"")
    at /builds/worker/checkouts/gecko/xpcom/ds/nsObserverService.cpp:292
#36 0x00007f45fcb0460a in nsContentSink::NotifyDocElementCreated(mozilla::dom::Document*) (aDoc=0x7f45f3287200) at /builds/worker/checkouts/gecko/dom/base/nsContentSink.cpp:923
#37 0x00007f45fc53cbfd in nsDocElementCreatedNotificationRunner::Run() (this=<optimized out>) at /builds/worker/checkouts/gecko/dom/base/nsDocElementCreatedNotificationRunner.h:24
#38 0x00007f45fc909491 in nsContentUtils::AddScriptRunner(already_AddRefed<nsIRunnable>) (aRunnable=...) at /builds/worker/checkouts/gecko/dom/base/nsContentUtils.cpp:5768
#39 0x00007f45fc909522 in nsContentUtils::AddScriptRunner(nsIRunnable*) (aRunnable=<optimized out>) at /builds/worker/checkouts/gecko/dom/base/nsContentUtils.cpp:5774
#40 0x00007f45fe65e554 in txMozillaXMLOutput::closePrevious(bool) (this=this@entry=0x7f45f479ba00, aFlushText=<optimized out>) at /builds/worker/checkouts/gecko/dom/xslt/xslt/txMozillaXMLOutput.cpp:519
#41 0x00007f45fe65fd15 in txMozillaXMLOutput::startElementInternal(nsAtom*, nsAtom*, int) (this=0x7f45f479ba00, aPrefix=0x0, aLocalName=0x7f45f8caa070 <mozilla::detail::gGkAtoms+63156>, aNsID=3) at /builds/worker/checkouts/gecko/dom/xslt/xslt/txMozillaXMLOutput.cpp:448
#42 0x00007f45fe65fb45 in txMozillaXMLOutput::startElement(nsAtom*, nsAtom*, nsAtom*, int) (this=0x7f45f479ba00, aPrefix=<optimized out>, aLocalName=0x7f45f8caa070 <mozilla::detail::gGkAtoms+63156>, aLowercaseLocalName=<optimized out>, aNsID=-256)
/builds/worker/checkouts/gecko/dom/xslt/xslt/txMozillaXMLOutput.cpp:402
#43 0x00007f45fe657dbb in txStartLREElement::execute(txExecutionState&) (this=<optimized out>, aEs=...) at /builds/worker/checkouts/gecko/dom/xslt/xslt/txInstructions.cpp:727
#44 0x00007f45fe67834e in txXSLTProcessor::execute(txExecutionState&) (aEs=...) at /builds/worker/checkouts/gecko/dom/xslt/xslt/txXSLTProcessor.cpp:46
#45 0x00007f45fe664052 in txMozillaXSLTProcessor::TransformToDoc(mozilla::dom::Document**, bool) (this=<optimized out>, aResult=aResult@entry=0x0, aCreateDataDocument=<optimized out>) at /builds/worker/checkouts/gecko/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:654
#46 0x00007f45fe669a15 in nsTransformBlockerEvent::Run() (this=<optimized out>) at /builds/worker/checkouts/gecko/dom/xslt/xslt/txMozillaXSLTProcessor.cpp:454
Flags: needinfo?(lgreco)

The severity field is not set for this bug.
:mixedpuppy, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(mixedpuppy)
Severity: -- → S4
Flags: needinfo?(mixedpuppy)
Priority: -- → P3

When I wrote a unit test for bug 1613779, it failed (timed out) because the document_end script unexpectedly did not run. This happened because at document_start, document.write() was called, which replaced the document. Much like how XSLT transformation in this bug could replace the document during load.

The unit test here passes (I had to modify the patch to register the test in the toml file instead of ini file).

Assignee: nobody → rob
See Also: → 1613779
Whiteboard: [addons-jira]
Attachment #9258322 - Attachment description: WIP: Bug 1747547 - Add xpcshell test to cover content script injection in xslt transformed xml webpage. → Bug 1747547 - Add xpcshell test to cover content script injection in xslt transformed xml webpage.

Given the deprecation of XSLT support, we will close this bug as WontFix.

The bug for document.write above may still be useful in a separate bug, and I will move it to a new bug if needed. To support XSLT, more work-arounds were needed, which did not seem to be a worthwhile endeavor since we are going to remove XSLT support from the platform.

When XSLT support is finally removed (bug 1990759), this bug will resolve on its own, from the user's perspective.

Status: NEW → RESOLVED
Closed: 10 months ago
Depends on: 1990759
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: