Attachment #288598: block inherited loads from unsafe docshells for bug #369814

View | Details | Raw Unified | Return to bug 369814
Collapse All | Expand All

(-)a/docshell/base/nsDocShell.cpp (-6 / +24 lines)
Line     Link Here 
 Lines 1293-1301   nsDocShell::SetDocumentCharsetInfo(nsIDo Link Here 
1293
    return NS_OK;
1293
    return NS_OK;
1294
}
1294
}
1295
1295
1296
1296
NS_IMETHODIMP
1297
nsresult
1297
nsDocShell::GetChannelIsUnsafe(PRBool *aUnsafe)
1298
nsDocShell::ChannelIsUnsafe(PRBool *aUnsafe)
1299
{
1298
{
1300
    *aUnsafe = PR_FALSE;
1299
    *aUnsafe = PR_FALSE;
1301
1300
 Lines 1324-1330   nsDocShell::GetAllowPlugins(PRBool * aAl Link Here 
1324
    }
1323
    }
1325
1324
1326
    PRBool unsafe;
1325
    PRBool unsafe;
1327
    *aAllowPlugins = NS_SUCCEEDED(ChannelIsUnsafe(&unsafe)) && !unsafe;
1326
    *aAllowPlugins = NS_SUCCEEDED(GetChannelIsUnsafe(&unsafe)) && !unsafe;
1328
    return NS_OK;
1327
    return NS_OK;
1329
}
1328
}
1330
1329
 Lines 1347-1353   nsDocShell::GetAllowJavascript(PRBool * Link Here 
1347
    }
1346
    }
1348
1347
1349
    PRBool unsafe;
1348
    PRBool unsafe;
1350
    *aAllowJavascript = NS_SUCCEEDED(ChannelIsUnsafe(&unsafe)) && !unsafe;
1349
    *aAllowJavascript = NS_SUCCEEDED(GetChannelIsUnsafe(&unsafe)) && !unsafe;
1351
    return NS_OK;
1350
    return NS_OK;
1352
}
1351
}
1353
1352
 Lines 1368-1374   NS_IMETHODIMP nsDocShell::GetAllowMetaRe Link Here 
1368
    }
1367
    }
1369
1368
1370
    PRBool unsafe;
1369
    PRBool unsafe;
1371
    *aReturn = NS_SUCCEEDED(ChannelIsUnsafe(&unsafe)) && !unsafe;
1370
    *aReturn = NS_SUCCEEDED(GetChannelIsUnsafe(&unsafe)) && !unsafe;
1372
    return NS_OK;
1371
    return NS_OK;
1373
}
1372
}
1374
1373
 Lines 6585-6590   nsDocShell::InternalLoad(nsIURI * aURI, Link Here 
6585
            (aFlags & INTERNAL_LOAD_FLAGS_INHERIT_OWNER) &&
6584
            (aFlags & INTERNAL_LOAD_FLAGS_INHERIT_OWNER) &&
6586
            NS_SUCCEEDED(URIInheritsSecurityContext(aURI, &inherits)) &&
6585
            NS_SUCCEEDED(URIInheritsSecurityContext(aURI, &inherits)) &&
6587
            inherits) {
6586
            inherits) {
6587
6588
            // Don't allow loads that would inherit our security context
6589
            // if this document came from an unsafe channel.
6590
            nsCOMPtr<nsIDocShellTreeItem> treeItem = this;
6591
            do {
6592
                nsCOMPtr<nsIDocShell> itemDocShell =
6593
                    do_QueryInterface(treeItem);
6594
                PRBool isUnsafe;
6595
                if (itemDocShell &&
6596
                    NS_SUCCEEDED(itemDocShell->GetChannelIsUnsafe(&isUnsafe)) &&
6597
                    isUnsafe) {
6598
                    return NS_ERROR_FAILURE;
6599
                }
6600
6601
                nsCOMPtr<nsIDocShellTreeItem> parent;
6602
                treeItem->GetSameTypeParent(getter_AddRefs(parent));
6603
                parent.swap(treeItem);
6604
            } while (treeItem);
6605
6588
            owner = GetInheritedPrincipal(PR_TRUE);
6606
            owner = GetInheritedPrincipal(PR_TRUE);
6589
        }
6607
        }
6590
    }
6608
    }
(-)a/docshell/base/nsDocShell.h (-4 lines)
Line     Link Here 
 Lines 513-522   protected: Link Here 
513
513
514
    // Check whether aURI is about:blank
514
    // Check whether aURI is about:blank
515
    static PRBool IsAboutBlank(nsIURI* aURI);
515
    static PRBool IsAboutBlank(nsIURI* aURI);
516
517
    // Check for a suspicious channel (such as a JAR channel where the
518
    // server-returned content type isn't a known JAR type)
519
    nsresult ChannelIsUnsafe(PRBool *aUnsafe);
520
protected:
516
protected:
521
    // Override the parent setter from nsDocLoader
517
    // Override the parent setter from nsDocLoader
522
    virtual nsresult SetDocLoaderParent(nsDocLoader * aLoader);
518
    virtual nsresult SetDocLoaderParent(nsDocLoader * aLoader);
(-)a/docshell/base/nsIDocShell.idl (+7 lines)
Line     Link Here 
 Lines 448-452   interface nsIDocShell : nsISupports Link Here 
448
   * document has been set up)
448
   * document has been set up)
449
   */
449
   */
450
  readonly attribute boolean isInUnload;
450
  readonly attribute boolean isInUnload;
451
452
  /**
453
   * Find out if the currently loaded document came from a suspicious channel
454
   * (such as a JAR channel where the server-returned content type isn't a
455
   * known JAR type).
456
   */
457
  readonly attribute boolean channelIsUnsafe;
451
};
458
};
452
459

Return to bug 369814