mirror of
https://github.com/pvrzz/Portage.git
synced 2026-11-29 05:22:26 +00:00
audit: close remaining source-isolation, memory and lock gaps
- Copy the Firefox profile with reflinks but refuse data symlinks inside the clone, and reject source/destination path containment, so the original profile cannot be written through an internal symlink or a nested target. - Cap ArrayBuffer/typed-array values at 8 MiB before they expand into number arrays and enforce the 32 MiB encoded budget incrementally during snapshot. - Resolve symlinks before the root/home target guard (a symlink to $HOME no longer bypasses it). - Detect legacy `lock` PID symlinks in addition to .parentlock in both the Node and Python tools. - Canonicalise the IndexedDB origin inventory with the same normalisation as the LocalStorage exporter instead of aborting on one odd origin. - Kill the browser we started and drop its SingletonLock on SIGINT/SIGTERM in the LocalStorage and cookie importers; cap passphrase stdin size. - Document source isolation, interrupted-import state, and the fact that the temporary IDB clone contains the whole profile (cookies/passwords/history).
This commit is contained in:
@@ -145,6 +145,15 @@ class FirefoxLocalStorageTest(unittest.TestCase):
|
||||
finally:
|
||||
os.close(descriptor)
|
||||
self.assertFalse(firefox_profile_in_use(profile))
|
||||
# Legacy `lock` symlinks encode the owner PID instead of holding
|
||||
# an open descriptor; a live PID must still be detected.
|
||||
lock.unlink()
|
||||
legacy = profile / 'lock'
|
||||
os.symlink(f'somehost:{os.getpid()}', legacy)
|
||||
self.assertTrue(firefox_profile_in_use(profile))
|
||||
legacy.unlink()
|
||||
os.symlink('somehost:99999999', legacy)
|
||||
self.assertFalse(firefox_profile_in_use(profile))
|
||||
|
||||
def test_cli_refuses_a_running_profile(self):
|
||||
with tempfile.TemporaryDirectory() as t:
|
||||
|
||||
@@ -23,6 +23,11 @@ const {encode,decode}=require('../tools/indexeddb_codec.js');
|
||||
}
|
||||
const cycle={};cycle.self=cycle;
|
||||
await assert.rejects(()=>encode(cycle),/cyclic/);
|
||||
const shared={shared:true};
|
||||
await assert.rejects(()=>encode([shared,shared]),/Shared\/cyclic/);
|
||||
// Binary values are rejected before Array.from() expands them.
|
||||
await assert.rejects(()=>encode(new ArrayBuffer(9*1024*1024)),/8 MiB/);
|
||||
await assert.rejects(()=>encode(new Uint8Array(9*1024*1024)),/8 MiB/);
|
||||
const special=Object.create(null);Object.defineProperty(special,'__proto__',{value:{safe:1},enumerable:true});
|
||||
const recovered=decode(JSON.parse(JSON.stringify(await encode(special))));
|
||||
assert.equal(Object.getPrototypeOf(recovered),null);
|
||||
|
||||
@@ -44,6 +44,14 @@ async function main() {
|
||||
apply: false,
|
||||
}), /must differ|looks like a Firefox profile/);
|
||||
|
||||
// A destination nested inside the Firefox source is refused (it would let
|
||||
// Chromium write into the source profile).
|
||||
await assert.rejects(() => migrate({
|
||||
firefoxProfile: source, chromiumProfile: path.join(source, 'Default'),
|
||||
firefox: path.join(root, 'missing-firefox'), chromium: path.join(root, 'missing-chromium'),
|
||||
apply: false,
|
||||
}), /inside the Firefox source/);
|
||||
|
||||
// A Firefox-looking Chromium target is refused before anything is written.
|
||||
fs.writeFileSync(path.join(target, 'prefs.js'), '');
|
||||
await assert.rejects(() => migrate({
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import sqlite3
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from contextlib import closing
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'tools'))
|
||||
from list_firefox_idb_origins import list_origins
|
||||
|
||||
|
||||
class FirefoxIdbOriginListTest(unittest.TestCase):
|
||||
def test_origins_are_canonicalised_and_filtered(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
profile = Path(root)
|
||||
with closing(sqlite3.connect(profile / 'storage.sqlite')) as connection, connection:
|
||||
connection.execute('CREATE TABLE origin (origin TEXT, client_usages TEXT)')
|
||||
connection.executemany('INSERT INTO origin VALUES (?,?)', [
|
||||
('HTTPS://Example.test:443/', 'I123'),
|
||||
('https://example.test', 'I456'),
|
||||
('https://caret.test^userContextId=1', 'I789'),
|
||||
('https://no-idb.test', 'L1'),
|
||||
('moz-extension://some-uuid', 'I999'),
|
||||
('not a url', 'I111'),
|
||||
])
|
||||
self.assertEqual(list_origins(profile), ['https://example.test'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -4,7 +4,8 @@ const fs = require('node:fs');
|
||||
const os = require('node:os');
|
||||
const path = require('node:path');
|
||||
const cp = require('node:child_process');
|
||||
const {assertSafeTargetProfile, chromiumLaunchProfileOptions, chromiumLockPath, assertChromiumClosed, firefoxLockPath, isLockHeld, assertFirefoxClosed} =
|
||||
const {transfer} = require('../tools/chromium_cookie_import.cjs');
|
||||
const {assertSafeTargetProfile, assertDisjointProfiles, cloneFirefoxProfile, chromiumLaunchProfileOptions, chromiumLockPath, assertChromiumClosed, firefoxLockPath, isLockHeld, assertFirefoxClosed} =
|
||||
require('../tools/profile_safety.cjs');
|
||||
|
||||
function waitFor(predicate, timeoutMs = 3000) {
|
||||
@@ -34,6 +35,45 @@ async function main() {
|
||||
assert.equal(assertSafeTargetProfile(chromiumProfile), chromiumProfile);
|
||||
assert.equal(assertSafeTargetProfile(path.join(root, 'not-created-yet')),
|
||||
path.join(root, 'not-created-yet'));
|
||||
|
||||
// A symlink to home or root must not bypass the target guard.
|
||||
const homeLink = path.join(root, 'home-link');
|
||||
fs.symlinkSync(os.homedir(), homeLink);
|
||||
assert.throws(() => assertSafeTargetProfile(homeLink), /root or home/);
|
||||
const rootLink = path.join(root, 'root-link');
|
||||
fs.symlinkSync('/', rootLink);
|
||||
assert.throws(() => assertSafeTargetProfile(rootLink), /root or home/);
|
||||
|
||||
// Profiles that contain each other are unsafe even when each path is
|
||||
// individually acceptable.
|
||||
assert.throws(() => assertDisjointProfiles(firefoxProfile, path.join(firefoxProfile, 'Default')),
|
||||
/inside the Firefox source/);
|
||||
assert.throws(() => assertDisjointProfiles(path.join(root, 'parent', 'child'), path.join(root, 'parent')),
|
||||
/inside Chromium user-data-dir/);
|
||||
assertDisjointProfiles(firefoxProfile, chromiumProfile);
|
||||
await assert.rejects(() => transfer({
|
||||
sourceProfile: firefoxProfile,
|
||||
targetProfile: path.join(firefoxProfile, 'Default'),
|
||||
browserPath: process.execPath,
|
||||
}), /inside the Firefox source/);
|
||||
|
||||
// A dangling legacy `lock` symlink is a stale marker and is dropped from
|
||||
// the clone, but a data symlink makes the copy unsafe and is refused so
|
||||
// Firefox can never write through it into the source or another directory.
|
||||
fs.symlinkSync('somehost:4242', path.join(firefoxProfile, 'lock'));
|
||||
const clone = path.join(root, 'firefox-clone');
|
||||
cloneFirefoxProfile(firefoxProfile, clone);
|
||||
assert.equal(fs.existsSync(path.join(clone, 'lock')), false);
|
||||
fs.unlinkSync(path.join(firefoxProfile, 'lock'));
|
||||
|
||||
const outside = path.join(root, 'outside-storage');
|
||||
fs.mkdirSync(outside);
|
||||
fs.writeFileSync(path.join(outside, 'token.txt'), 'synthetic');
|
||||
fs.symlinkSync(outside, path.join(firefoxProfile, 'storage'));
|
||||
assert.throws(() => cloneFirefoxProfile(firefoxProfile, path.join(root, 'unsafe-clone')),
|
||||
/contains symlinks/);
|
||||
assert.equal(fs.readFileSync(path.join(outside, 'token.txt'), 'utf8'), 'synthetic');
|
||||
fs.unlinkSync(path.join(firefoxProfile, 'storage'));
|
||||
// Fresh disposable profiles keep Puppeteer's --password-store=basic, while
|
||||
// existing profiles must not be switched to the fallback cookie key store.
|
||||
assert.deepEqual(chromiumLaunchProfileOptions(chromiumProfile), {});
|
||||
@@ -70,6 +110,14 @@ async function main() {
|
||||
}
|
||||
await waitFor(() => !isLockHeld(path.join(firefoxProfile, '.parentlock')));
|
||||
assertFirefoxClosed(firefoxProfile);
|
||||
|
||||
// Legacy `lock` symlinks encode the PID; a live PID means the profile is
|
||||
// in use even though realpath() cannot resolve the symlink target.
|
||||
fs.unlinkSync(path.join(firefoxProfile, '.parentlock'));
|
||||
const legacyLock = path.join(firefoxProfile, 'lock');
|
||||
fs.symlinkSync(`somehost:${process.pid}`, legacyLock);
|
||||
assert.equal(isLockHeld(legacyLock), true);
|
||||
fs.unlinkSync(legacyLock);
|
||||
console.log('PASS: profile target and Firefox lock safety checks');
|
||||
} finally {
|
||||
fs.rmSync(root, {recursive: true, force: true});
|
||||
|
||||
Reference in New Issue
Block a user