Closed
Bug 367055
Opened 19 years ago
Closed 18 years ago
Cmd-Click / "Open Link in New foo" should not open file URLs from non-local pages
Categories
(Camino Graveyard :: Security, defect)
Tracking
(Not tracked)
RESOLVED
FIXED
Camino1.5
People
(Reporter: alqahira, Assigned: nick.kreeger)
References
()
Details
(Keywords: fixed1.8.1.4)
Attachments
(2 files, 6 obsolete files)
|
637 bytes,
text/html
|
Details | |
|
7.90 KB,
patch
|
stuart.morgan+bugzilla
:
review+
mikepinkerton
:
superreview+
|
Details | Diff | Splinter Review |
In bug 155132, we discovered that normal-click of a file:// url link from an online web page fails (and philippe mentioned on the forum he sees some sort of security message in his console), but Cmd-click (and presumably middle-click), drag-and-drop to a (new) tab, and "Open Link in New foo" in the context menu all open file://Volumes/ from the bmo-hosted testcase.
Firefox correctly disallows non-local pages to open file://Volumes/ using all of these methods (but allows local pages), and we need to do the same (check to see if the page with the link is local before allowing it to work).
Flags: camino1.1?
Comment 1•19 years ago
|
||
For the record, the message I get in the console.log (left click):
Camino[281] JS error: Security Error: Content at http://lab.phiw.dev/camino/155132testcase.html may not load or link to file:///Volumes/.
(testing with test case loaded on my local dev server).
In Minefields error console, I get the same error (it is actually a warning).
When command clicking this type of link, Minefield logs two messages:
Security Error: Content at http://lab.phiw.dev/camino/155132testcase.html may not load or link to file:///users/phiw/path/to/file/filename.html.
Error: uncaught exception: Load of file:///Volumes/ from http://lab.phiw.dev/camino/155132testcase.html denied.
Comment 2•18 years ago
|
||
It looks like somehow we need to be running these loads through something that uses CheckLoadURIWithPrincipal, but I haven't looked enough to see where (if anywhere) that would be at a level that is reasonable for us to use.
| Assignee | ||
Comment 3•18 years ago
|
||
Here is a new test case:
http://nkreeger.com/misc/bug367055test.html
| Assignee | ||
Comment 4•18 years ago
|
||
Here is the first version of the patch. Here we use the security manager to check out URI's. This not only disables "file://", but several other unsafe loads according to the source:
http://lxr.mozilla.org/mozilla1.8/source/caps/src/nsScriptSecurityManager.cpp#1314
This patch requires a build path include to "dist/include/caps".
The window or new tab will still open with this patch, but loading is disabled. If we need a different behavior, this code can be relocated elsewhere.
Assignee: dveditz → nick.kreeger
Status: NEW → ASSIGNED
Attachment #260775 -
Flags: review?(stuart.morgan)
| Assignee | ||
Updated•18 years ago
|
Attachment #260775 -
Attachment is patch: true
Attachment #260775 -
Attachment mime type: application/octet-stream → text/plain
Comment 5•18 years ago
|
||
(In reply to comment #4)
> The window or new tab will still open with this patch, but loading is disabled.
> If we need a different behavior, this code can be relocated elsewhere.
This seems like rather odd behaviour at best. How about we just plain don't open the window?
A better solution would probably be for Core to have a pretty error page that can be thrown in situations like this. Does such a thing exist?
cl
| Assignee | ||
Comment 6•18 years ago
|
||
FYI Firefox 2 doesn't open the window or tab.
| Reporter | ||
Comment 7•18 years ago
|
||
(In reply to comment #4)
> This patch requires a build path include to "dist/include/caps".
The project patches in bug 372020 do this.
Comment 8•18 years ago
|
||
Comment on attachment 260775 [details] [diff] [review]
Patch V1
We should handle this in our command-click handler so that we don't open the new window.
Attachment #260775 -
Flags: review?(stuart.morgan) → review-
| Assignee | ||
Comment 9•18 years ago
|
||
Patch round 2. This time, I checked the call at the event-handler.
Attachment #260775 -
Attachment is obsolete: true
Attachment #260957 -
Flags: review?(stuart.morgan)
Comment 10•18 years ago
|
||
Could this be factored somewhere re-usable and hook it up to the "Open Link in..." context menu items without too much pain? I'm fine with punting DnD for now, but it would be nice to cover the other cases.
| Assignee | ||
Comment 11•18 years ago
|
||
This kinda gives us an idea of how to not show a menu item. I left in the ContentClickListener checking code as a fail-safe measure...
I might move this code down to at least BrowserWrapper in the next version.
Comment 12•18 years ago
|
||
Comment on attachment 261521 [details] [diff] [review]
WIP 3
>+ nsCOMPtr<nsIURI> referrerURI;
>+ NS_NewURI(getter_AddRefs(referrerURI), [referrerURL UTF8String]);
>+ nsCOMPtr<nsIURI> targetURI;
>+ NS_NewURI(getter_AddRefs(targetURI), hrefURL);
>+
>+ nsCOMPtr<nsIScriptSecurityManager> secManager = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID);
>+ if (secManager && referrerURI && targetURI) {
>+ nsresult rv = secManager->CheckLoadURI(referrerURI, targetURI, NSLoadFlagsNone);
>+ if (NS_SUCCEEDED(rv)) {
>+ menuPrototype = mLinkMenu;
>+ }
>+ }
How about moving all this duplicate code into GeckoUtils as something like
PRBool GeckoUtils::CanLoadURIFromURI(nsACString sourceURI, nsACString targetURI);
(or whatever form of Gecko string type that makes it easy to call with [foo UTF8String] as a parameter).
Updated•18 years ago
|
Attachment #260957 -
Flags: review?(stuart.morgan)
| Assignee | ||
Comment 13•18 years ago
|
||
This moves the shared code to |GeckoUtils|. For now, I'm not showing the popup menu for bad links.
Attachment #260957 -
Attachment is obsolete: true
Attachment #261521 -
Attachment is obsolete: true
Comment 14•18 years ago
|
||
Probably disabling the dangerous actions in the menu would be the least surprising thing, but if removing them is easier that would work too.
| Reporter | ||
Comment 15•18 years ago
|
||
(In reply to comment #7)
> (In reply to comment #4)
> > This patch requires a build path include to "dist/include/caps".
>
> The project patches in bug 372020 do this.
These have landed.
(In reply to comment #14)
> Probably disabling the dangerous actions in the menu would be the least
> surprising thing, but if removing them is easier that would work too.
Per the meeting, we should just remove "Open Link in New Window" and "Open Link in New Tab" from the context menu for local links (and local image links).
| Reporter | ||
Comment 16•18 years ago
|
||
kreeger's testcase with image links added.
| Assignee | ||
Comment 17•18 years ago
|
||
Here is an updated patch, it needs a new BrowserWindow.nib for the new menu keys.
Attachment #261618 -
Attachment is obsolete: true
Attachment #262064 -
Flags: review?(stuart.morgan)
| Reporter | ||
Comment 18•18 years ago
|
||
Can this be done at all without a new nib (other than just not showing the CM entirely)?
Comment 19•18 years ago
|
||
Unfortunately doing this without a new nib would require bug 363895 to be fixed, which I suppose means we have to wait until after 1.5 to fix the context menu portion of this (due to l10n freeze). I personally suggest we go with the CM solution in WIP4 (don't show the CM at all for the links in question) in the 1.5 timeframe, and file a followup to be fixed after release.
| Assignee | ||
Comment 20•18 years ago
|
||
(In reply to comment #18)
> Can this be done at all without a new nib (other than just not showing the CM
> entirely)?
>
We could remove the 0 index item 3 times...
Comment 21•18 years ago
|
||
(In reply to comment #20)
> We could remove the 0 index item 3 times...
Let's do that with a comment as to why, and file a follow-up to fix it correctly right after 1.5.
| Assignee | ||
Comment 22•18 years ago
|
||
Here it is... I filed bug 378081 as a followup and documented it in the code.
Attachment #262064 -
Attachment is obsolete: true
Attachment #262170 -
Flags: review?(stuart.morgan)
Attachment #262064 -
Flags: review?(stuart.morgan)
Comment 23•18 years ago
|
||
Comment on attachment 262170 [details] [diff] [review]
V6
>+const int kOpenLinkInNewWindowTag = 106;
>+const int kOpenLinkInNewTabTag = 107;
Remove these; no need to create tags we aren't using at the moment.
>+ BOOL isBadLink = NO;
isUnsafeLink
>+ NSString* referrerURL = [[mBrowserView getBrowserView] getFocusedURLString];
>+ nsCOMPtr<nsIDOMElement> linkElement;
>+ nsAutoString hrefURL;
>+ GeckoUtils::GetEnclosingLinkElementAndHref(mDataOwner->mContextMenuNode,
>+ getter_AddRefs(linkElement),
>+ hrefURL);
>+ if (!GeckoUtils::GetIsUriSafe([referrerURL UTF8String], NS_ConvertUTF16toUTF8(hrefURL).get()))
>+ isBadLink = YES;
Put a comment before this block to the effect of "Verify that it's safe to open this link"
>+ // To avoid updating the BrowserWindow.nib close to release time, the
>+ // menu items to remove will be removed from index 0 three times. After
>+ // the 1.1 release, this needs to be changed (see bug 378081).
>+ [result removeItemAtIndex:0];
>+ [result removeItemAtIndex:0];
>+ [result removeItemAtIndex:0]; // remove separator
Also add a comment above all this that says that you are removing the "Open Link in *" items here, since it's not clear from the codes.
>+ // Fail-safe for safe URI loading (see bug 367055).
I'm not clear on why you say it's a fail-safe; isn't this the one and only check for command-clicked links?
>+GeckoUtils::GetIsUriSafe(const char* aReferrerUri, const char* aTargetUri)
This name is too vague. Use something descriptive like CanLoadURIFromURI, or better IsSafeToOpenURIFromURI (and reverse the order of the arguments if you use one of those names).
Also, please make sure there's no whitespace on blank lines when you respin.
Attachment #262170 -
Flags: review?(stuart.morgan) → review-
| Assignee | ||
Comment 24•18 years ago
|
||
Respin to meet all comments.
Attachment #262170 -
Attachment is obsolete: true
Attachment #262215 -
Flags: review?(stuart.morgan)
| Reporter | ||
Comment 25•18 years ago
|
||
I filed bug 378301 to spin off the drag-drop case.
Summary: Cmd-Click / drag-drop / "Open Link in New foo" should not open file URLs from non-local pages → Cmd-Click / "Open Link in New foo" should not open file URLs from non-local pages
Comment 26•18 years ago
|
||
Comment on attachment 262215 [details] [diff] [review]
V7
Looks great! r=me.
Attachment #262215 -
Flags: superreview?(mikepinkerton)
Attachment #262215 -
Flags: review?(stuart.morgan)
Attachment #262215 -
Flags: review+
Comment 27•18 years ago
|
||
Comment on attachment 262215 [details] [diff] [review]
V7
can you expand on what "safe" means in the GeckoUtils header comment? Might be nice to have it documented a little better.
sr=pink
Attachment #262215 -
Flags: superreview?(mikepinkerton) → superreview+
| Assignee | ||
Comment 29•18 years ago
|
||
Checked into HEAD, sorry bout the delay...
Status: ASSIGNED → RESOLVED
Closed: 18 years ago
Resolution: --- → FIXED
| Reporter | ||
Updated•18 years ago
|
Flags: camino1.5? → camino1.5+
You need to log in
before you can comment on or make changes to this bug.
Description
•