fix(worker): validate URL origin before importScripts#5198
fix(worker): validate URL origin before importScripts#5198marcoscaceres wants to merge 5 commits intomainfrom
Conversation
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
|
@copilot see the CI error about the commit message. Can you fix that please? |
…ad-lang Co-authored-by: marcoscaceres <870154+marcoscaceres@users.noreply.github.com>
Done in commit Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot Can you fix the lint error from ci? |
Agent-Logs-Url: https://github.com/speced/respec/sessions/eaf97df3-cfd4-4999-92cf-047f0b3b3ca4 Co-authored-by: marcoscaceres <870154+marcoscaceres@users.noreply.github.com>
Fixed in commit |
Potential fix for https://github.com/speced/respec/security/code-scanning/24
The safest fix is to enforce strict validation/allowlisting of
langURLbefore callingimportScripts, and reject anything not matching expected trusted URLs. Also validatepropNameto prevent unsafe property access, and ensure the loaded language registration function exists before use.Best single approach without changing intended behavior:
worker/respec-worker.js, inside the"highlight-load-lang"case, replace directimportScripts(langURL)with:new URL(langURL, self.location.href).http:/https:schemes.url.origin === self.location.origin) so only locally hosted language files load./) and.jsextension.propNameas a safe identifier and ensureself[propName]is a function before registering.try/catch, log and skip on invalid input.This keeps dynamic language loading, but removes attacker-controlled arbitrary script URL loading.
Suggested fixes powered by Copilot Autofix. Review carefully before merging.