Commit 64bb5633 authored by Naoki Fukino's avatar Naoki Fukino Committed by Commit Bot

Use origin to check if the request to ImageLoader is from eligible clients.

When ImageLoader get requests to process image files, it checks message
sender's id to disallow requests from unknown clients.
However, sender's id is currently not trustworthy (issue 982361). We
should use sender's origin instead as a short-term fix.

Bug: 10321587
Test: Manual test on Files/Gallery to show thumbnails from ImageLoader.
Change-Id: Idb61850795828a63b37aa43b66d4875ad7abbfc4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1989728
Commit-Queue: Naoki Fukino <fukino@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#733918}
parent 86119575
...@@ -65,10 +65,10 @@ function ImageLoader() { ...@@ -65,10 +65,10 @@ function ImageLoader() {
* @const * @const
* @type {Array<string>} * @type {Array<string>}
*/ */
ImageLoader.ALLOWED_CLIENTS = [ ImageLoader.ALLOWED_CLIENT_ORIGINS = [
'hhaomjibdihmijegdhdafkllkbggdgoj', // File Manager's extension id. 'chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj', // File Manager
'nlkncpkkdoccmpiclbokaimcnedabhhm', // Gallery's extension id. 'chrome-extension://nlkncpkkdoccmpiclbokaimcnedabhhm', // Gallery
'jcgeabjmjgoblfofpppfkcoakmfobdko', // Video Player's extension id. 'chrome-extension://jcgeabjmjgoblfofpppfkcoakmfobdko', // Video Player
]; ];
/** /**
...@@ -80,10 +80,10 @@ ImageLoader.ALLOWED_CLIENTS = [ ...@@ -80,10 +80,10 @@ ImageLoader.ALLOWED_CLIENTS = [
*/ */
ImageLoader.prototype.onIncomingRequest_ = function( ImageLoader.prototype.onIncomingRequest_ = function(
request_data, sender, sendResponse) { request_data, sender, sendResponse) {
if (!sender.id || !request_data) { if (!sender.origin || !request_data) {
return; return;
} }
if (ImageLoader.ALLOWED_CLIENTS.indexOf(sender.id) === -1) { if (ImageLoader.ALLOWED_CLIENT_ORIGINS.indexOf(sender.origin) === -1) {
return; return;
} }
...@@ -108,14 +108,14 @@ ImageLoader.prototype.onIncomingRequest_ = function( ...@@ -108,14 +108,14 @@ ImageLoader.prototype.onIncomingRequest_ = function(
} else { } else {
request.orientation = new ImageOrientation(1, 0, 0, 1); request.orientation = new ImageOrientation(1, 0, 0, 1);
} }
return this.onMessage_(sender.id, request, failSafeSendResponse); return this.onMessage_(sender.origin, request, failSafeSendResponse);
}; };
/** /**
* Handles a request. Depending on type of the request, starts or stops * Handles a request. Depending on type of the request, starts or stops
* an image task. * an image task.
* *
* @param {string} senderId Sender's extension id. * @param {string} senderOrigin Sender's extension origin.
* @param {!LoadImageRequest} request Pre-processed request. * @param {!LoadImageRequest} request Pre-processed request.
* @param {function(!LoadImageResponse)} callback Callback to be called to * @param {function(!LoadImageResponse)} callback Callback to be called to
* return response. * return response.
...@@ -123,8 +123,8 @@ ImageLoader.prototype.onIncomingRequest_ = function( ...@@ -123,8 +123,8 @@ ImageLoader.prototype.onIncomingRequest_ = function(
* callback is called. * callback is called.
* @private * @private
*/ */
ImageLoader.prototype.onMessage_ = function(senderId, request, callback) { ImageLoader.prototype.onMessage_ = function(senderOrigin, request, callback) {
const requestId = senderId + ':' + request.taskId; const requestId = senderOrigin + ':' + request.taskId;
if (request.cancel) { if (request.cancel) {
// Cancel a task. // Cancel a task.
this.scheduler_.remove(requestId); this.scheduler_.remove(requestId);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment