Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Extensions] Do not load scripts that exceed a maximum size
This CL enforces maximum sizes for individual content scripts and all scripts in an extension. The maximum sizes are: - 500 MB per script - 1 GB for all content scripts (manifest and dynamic) for a single extension Any file in a script entry that would exceed one of these limits will not be loaded and will generate an install warning for the extension if it's a manifest script. For dynamic scripts, the registerContentScripts function should return an error and be a no-op if a limit is exceeded. This will be tackled in a follow up. Bug: 1379187 Change-Id: I2de4f123f85783350b10415c5cee022355f47f1f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4095461 Commit-Queue: Kelvin Jiang <kelvinjiang@chromium.org> Reviewed-by: Devlin Cronin <rdevlin.cronin@chromium.org> Cr-Commit-Position: refs/heads/main@{#1084757}
- Loading branch information
1 parent
a793cc9
commit d17176a
Showing
14 changed files
with
315 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
chrome/test/data/extensions/api_test/content_scripts/large_scripts/big.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2022 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
var div = document.createElement('div'); | ||
div.id = 'BIG'; | ||
document.body.appendChild(div); | ||
/* | ||
PADDING OUT THE FILE TO BE OVER 800 BYTES | ||
PADDING OUT THE FILE TO BE OVER 800 BYTES | ||
PADDING OUT THE FILE TO BE OVER 800 BYTES | ||
PADDING OUT THE FILE TO BE OVER 800 BYTES | ||
PADDING OUT THE FILE TO BE OVER 800 BYTES | ||
PADDING OUT THE FILE TO BE OVER 800 BYTES | ||
PADDING OUT THE FILE TO BE OVER 800 BYTES | ||
PADDING OUT THE FILE TO BE OVER 800 BYTES | ||
PADDING OUT THE FILE TO BE OVER 800 BYTES | ||
PADDING OUT THE FILE TO BE OVER 800 BYTES | ||
PADDING OUT THE FILE TO BE OVER 800 BYTES | ||
PADDING OUT THE FILE TO BE OVER 800 BYTES | ||
PADDING OUT THE FILE TO BE OVER 800 BYTES | ||
PADDING OUT THE FILE TO BE OVER 800 BYTES | ||
*/ |
5 changes: 5 additions & 0 deletions
5
chrome/test/data/extensions/api_test/content_scripts/large_scripts/change_title.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Copyright 2022 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
document.title = 'I CHANGED TITLE!!!'; |
7 changes: 7 additions & 0 deletions
7
chrome/test/data/extensions/api_test/content_scripts/large_scripts/inject_element.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Copyright 2022 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
var div = document.createElement('div'); | ||
div.id = 'injected'; | ||
document.body.appendChild(div); |
20 changes: 20 additions & 0 deletions
20
chrome/test/data/extensions/api_test/content_scripts/large_scripts/inject_element_2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2022 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
var div = document.createElement('div'); | ||
div.id = 'injected_2'; | ||
document.body.appendChild(div); | ||
/* | ||
PADDING OUT THE FILE TO BE OVER 700 BYTES | ||
PADDING OUT THE FILE TO BE OVER 700 BYTES | ||
PADDING OUT THE FILE TO BE OVER 700 BYTES | ||
PADDING OUT THE FILE TO BE OVER 700 BYTES | ||
PADDING OUT THE FILE TO BE OVER 700 BYTES | ||
PADDING OUT THE FILE TO BE OVER 700 BYTES | ||
PADDING OUT THE FILE TO BE OVER 700 BYTES | ||
PADDING OUT THE FILE TO BE OVER 700 BYTES | ||
PADDING OUT THE FILE TO BE OVER 700 BYTES | ||
PADDING OUT THE FILE TO BE OVER 700 BYTES | ||
PADDING OUT THE FILE TO BE OVER 700 BYTES | ||
*/ |
29 changes: 29 additions & 0 deletions
29
chrome/test/data/extensions/api_test/content_scripts/large_scripts/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "Large content scripts", | ||
"version": "1.0", | ||
"manifest_version": 3, | ||
"description": "Content scripts that surpass the size limit are not loaded.", | ||
"background": { | ||
"service_worker": "worker.js", | ||
"type": "module" | ||
}, | ||
"permissions": ["scripting", "tabs"], | ||
"host_permissions": ["*://example.com/*"], | ||
"content_scripts": [ | ||
{ | ||
"matches": ["<all_urls>"], | ||
"js": ["big.js"], | ||
"run_at": "document_end" | ||
}, | ||
{ | ||
"matches": ["<all_urls>"], | ||
"js": ["inject_element.js", "change_title.js"], | ||
"run_at": "document_end" | ||
}, | ||
{ | ||
"matches": ["<all_urls>"], | ||
"js": ["inject_element_2.js"], | ||
"run_at": "document_end" | ||
} | ||
] | ||
} |
40 changes: 40 additions & 0 deletions
40
chrome/test/data/extensions/api_test/content_scripts/large_scripts/worker.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2022 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import {openTab} from '/_test_resources/test_util/tabs_util.js'; | ||
|
||
function getInjectedElementIds() { | ||
let childIds = []; | ||
for (const child of document.body.children) | ||
childIds.push(child.id); | ||
return childIds.sort(); | ||
}; | ||
|
||
chrome.test.runTests([ | ||
async function checkContentScriptInjectionResults() { | ||
async function getTitleForTab(tabId) { | ||
let results = await chrome.scripting.executeScript( | ||
{target: {tabId}, func: () => document.title}); | ||
chrome.test.assertEq(1, results.length); | ||
return results[0].result; | ||
}; | ||
|
||
const config = await chrome.test.getConfig(); | ||
const url = `http://example.com:${config.testServer.port}/simple.html`; | ||
const tab = await openTab(url); | ||
const title = await getTitleForTab(tab.id); | ||
chrome.test.assertEq('I CHANGED TITLE!!!', title); | ||
|
||
let results = await chrome.scripting.executeScript( | ||
{target: {tabId: tab.id}, func: getInjectedElementIds}); | ||
|
||
// Only inject_element_1.js and change_title.js should be loaded/injected as | ||
// big.js exceeds the individual script size limit, and loading | ||
// inject_element_2.js would exceed the extension's total script size limit. | ||
chrome.test.assertEq(1, results.length); | ||
chrome.test.assertEq(['injected'], results[0].result); | ||
|
||
chrome.test.succeed(); | ||
}, | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.