Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5705)

Unified Diff: chrome/browser/resources/pdf/pdf.js

Issue 1316803003: Prevent leaking PDF data cross-origin (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2454
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/pdf/pdf_extension_test.cc ('k') | pdf/out_of_process_instance.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/pdf/pdf.js
diff --git a/chrome/browser/resources/pdf/pdf.js b/chrome/browser/resources/pdf/pdf.js
index 43e085e434bd50f113f8197f616c8c9d63dfc721..c4975746d57387fb492f79b5d8d67052a71f5424 100644
--- a/chrome/browser/resources/pdf/pdf.js
+++ b/chrome/browser/resources/pdf/pdf.js
@@ -84,6 +84,7 @@ function PDFViewer(browserApi) {
this.browserApi_ = browserApi;
this.loadState_ = LoadState.LOADING;
this.parentWindow_ = null;
+ this.parentOrigin_ = null;
this.delayedScriptingMessages_ = [];
@@ -674,6 +675,7 @@ PDFViewer.prototype = {
handleScriptingMessage: function(message) {
if (this.parentWindow_ != message.source) {
this.parentWindow_ = message.source;
+ this.parentOrigin_ = message.origin;
// Ensure that we notify the embedder if the document is loaded.
if (this.loadState_ != LoadState.LOADING)
this.sendDocumentLoadedMessage_();
@@ -760,11 +762,22 @@ PDFViewer.prototype = {
* @param {Object} message the message to send.
*/
sendScriptingMessage_: function(message) {
- if (this.parentWindow_)
- this.parentWindow_.postMessage(message, '*');
+ if (this.parentWindow_ && this.parentOrigin_) {
+ var targetOrigin;
+ // Only send data back to the embedder if it is from the same origin,
+ // unless we're sending it to ourselves (which could happen in the case
+ // of tests). We also allow documentLoaded messages through as this won't
+ // leak important information.
+ if (this.parentOrigin_ == window.location.origin)
+ targetOrigin = this.parentOrigin_;
+ else if (message.type == 'documentLoaded')
+ targetOrigin = '*';
+ else
+ targetOrigin = this.browserApi_.getStreamInfo().originalUrl;
+ this.parentWindow_.postMessage(message, targetOrigin);
+ }
},
-
/**
* @type {Viewport} the viewport of the PDF viewer.
*/
« no previous file with comments | « chrome/browser/pdf/pdf_extension_test.cc ('k') | pdf/out_of_process_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698