mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-27 09:37:31 +09:00
Avoid drag-and-drop of javascript: URIs
This commit is contained in:
parent
e8e804ec97
commit
d49f17dcbc
2 changed files with 34 additions and 21 deletions
|
|
@ -5688,7 +5688,7 @@ function middleMousePaste(event) {
|
||||||
function stripUnsafeProtocolOnPaste(pasteData) {
|
function stripUnsafeProtocolOnPaste(pasteData) {
|
||||||
// Don't allow pasting javascript URIs since we don't support
|
// Don't allow pasting javascript URIs since we don't support
|
||||||
// LOAD_FLAGS_DISALLOW_INHERIT_PRINCIPAL for those.
|
// LOAD_FLAGS_DISALLOW_INHERIT_PRINCIPAL for those.
|
||||||
return pasteData.replace(/^(?:\s*javascript:)+/i, "");
|
return pasteData.replace(/\r?\n/g, "").replace(/^(?:\s*javascript:)+/i, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleDroppedLink has the following 2 overloads:
|
// handleDroppedLink has the following 2 overloads:
|
||||||
|
|
|
||||||
|
|
@ -701,38 +701,51 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
]]></body>
|
]]></body>
|
||||||
</method>
|
</method>
|
||||||
|
|
||||||
<method name="onDragOver">
|
<method name="_getDroppableLink">
|
||||||
<parameter name="aEvent"/>
|
|
||||||
<body>
|
|
||||||
var types = aEvent.dataTransfer.types;
|
|
||||||
if (types.includes("application/x-moz-file") ||
|
|
||||||
types.includes("text/x-moz-url") ||
|
|
||||||
types.includes("text/uri-list") ||
|
|
||||||
types.includes("text/unicode"))
|
|
||||||
aEvent.preventDefault();
|
|
||||||
</body>
|
|
||||||
</method>
|
|
||||||
|
|
||||||
<method name="onDrop">
|
|
||||||
<parameter name="aEvent"/>
|
<parameter name="aEvent"/>
|
||||||
<body><![CDATA[
|
<body><![CDATA[
|
||||||
let links = browserDragAndDrop.dropLinks(aEvent);
|
let links = browserDragAndDrop.dropLinks(aEvent);
|
||||||
|
|
||||||
// The URL bar automatically handles inputs with newline characters,
|
// The URL bar automatically handles inputs with newline characters,
|
||||||
// so we can get away with treating text/x-moz-url flavours as text/plain.
|
// so we can get away with treating text/x-moz-url flavours as text/plain.
|
||||||
if (links.length > 0 && links[0].url) {
|
if (links.length > 0 && links[0].url) {
|
||||||
let url = links[0].url;
|
|
||||||
aEvent.preventDefault();
|
aEvent.preventDefault();
|
||||||
this.value = url;
|
let url = links[0].url;
|
||||||
SetPageProxyState("invalid");
|
let strippedURL = stripUnsafeProtocolOnPaste(url);
|
||||||
this.focus();
|
if (strippedURL != url) {
|
||||||
|
aEvent.stopImmediatePropagation();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
urlSecurityCheck(url,
|
urlSecurityCheck(url,
|
||||||
gBrowser.contentPrincipal,
|
gBrowser.contentPrincipal,
|
||||||
Ci.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL);
|
Ci.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
]]></body>
|
||||||
|
</method>
|
||||||
|
|
||||||
|
<method name="onDragOver">
|
||||||
|
<parameter name="aEvent"/>
|
||||||
|
<body><![CDATA[
|
||||||
|
// We don't need the link here, so we ignore the return value.
|
||||||
|
if (!this._getDroppableLink(aEvent)) {
|
||||||
|
aEvent.dataTransfer.dropEffect = "none";
|
||||||
|
}
|
||||||
|
]]></body>
|
||||||
|
</method>
|
||||||
|
|
||||||
|
<method name="onDrop">
|
||||||
|
<parameter name="aEvent"/>
|
||||||
|
<body><![CDATA[
|
||||||
|
let url = this._getDroppableLink(aEvent);
|
||||||
|
if (url) {
|
||||||
|
this.value = url;
|
||||||
|
SetPageProxyState("invalid");
|
||||||
|
this.focus();
|
||||||
this.handleCommand();
|
this.handleCommand();
|
||||||
// Force not showing the dropped URI immediately.
|
// Force not showing the dropped URI immediately.
|
||||||
gBrowser.userTypedValue = null;
|
gBrowser.userTypedValue = null;
|
||||||
|
|
@ -932,7 +945,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
// Unfortunately we're not allowed to set the bits being pasted
|
// Unfortunately we're not allowed to set the bits being pasted
|
||||||
// so cancel this event:
|
// so cancel this event:
|
||||||
aEvent.preventDefault();
|
aEvent.preventDefault();
|
||||||
aEvent.stopPropagation();
|
aEvent.stopImmediatePropagation();
|
||||||
|
|
||||||
this.inputField.value = oldStart + pasteData + oldEnd;
|
this.inputField.value = oldStart + pasteData + oldEnd;
|
||||||
// Fix up cursor/selection:
|
// Fix up cursor/selection:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue