From 991ac1eae70dab38d6b06943d50320d7c131986f Mon Sep 17 00:00:00 2001 From: agentflow-marathon Date: Thu, 12 Nov 2026 23:19:23 -0800 Subject: [PATCH] Validate reviewed branding paths across Windows and POSIX --- scripts/apply_chromium_patches.py | 11 ++++++--- scripts/test_apply_chromium_patches.py | 32 ++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/scripts/apply_chromium_patches.py b/scripts/apply_chromium_patches.py index 9d2e45aecc..1bba11120d 100644 --- a/scripts/apply_chromium_patches.py +++ b/scripts/apply_chromium_patches.py @@ -13,6 +13,13 @@ from chromium_git import git_environment +def check_branding_asset_paths(relative, source_name): + """Keep branding paths relative and inside the theme tree on every host.""" + if (relative.anchor or source_name.anchor or '..' in relative.parts + or '..' in source_name.parts or not relative.as_posix().startswith('chrome/app/theme/')): + raise RuntimeError('Invalid reviewed branding asset path') + + def combined_patch(chromium, patches): """Validate ordered, overlapping patches in a private partial source tree.""" environment = git_environment() @@ -82,9 +89,7 @@ def main(): raise RuntimeError('Branding dependency revision differs from the reviewed manifest') for item in manifest['files']: relative, source_name = Path(item['destination']), Path(item['source']) - if (relative.is_absolute() or source_name.is_absolute() or '..' in relative.parts - or '..' in source_name.parts or not str(relative).startswith('chrome/app/theme/')): - raise RuntimeError('Invalid reviewed branding asset path') + check_branding_asset_paths(relative, source_name) destination = chromium / relative if not destination.resolve().is_relative_to(chromium): raise RuntimeError('Branding destination escapes Chromium source') diff --git a/scripts/test_apply_chromium_patches.py b/scripts/test_apply_chromium_patches.py index 33556e739b..677d75763e 100644 --- a/scripts/test_apply_chromium_patches.py +++ b/scripts/test_apply_chromium_patches.py @@ -1,10 +1,38 @@ """Validate ordered patch checking without writing partial source changes.""" -from pathlib import Path +from pathlib import Path, PurePosixPath, PureWindowsPath import subprocess import tempfile from unittest.mock import patch import unittest -from apply_chromium_patches import combined_patch +from apply_chromium_patches import check_branding_asset_paths, combined_patch + + +class BrandingPathTests(unittest.TestCase): + def test_theme_assets_accept_posix_and_windows_separators(self): + for flavor in (PurePosixPath, PureWindowsPath): + with self.subTest(flavor=flavor): + check_branding_asset_paths(flavor('chrome/app/theme/win/chromium.ico'), + flavor('theme/chromium/win/chromium.ico')) + + def test_traversal_and_theme_siblings_are_rejected_for_both_path_flavors(self): + for flavor in (PurePosixPath, PureWindowsPath): + for destination, source in ( + ('chrome/app/theme/../outside.ico', 'theme/icon.ico'), + ('chrome/app/theme/icon.ico', '../outside.ico'), + ('chrome/app/theme-sibling/icon.ico', 'theme/icon.ico'), + ('chrome/app/theme', 'theme/icon.ico'), + ('/chrome/app/theme/icon.ico', 'theme/icon.ico'), + ('chrome/app/theme/icon.ico', '/theme/icon.ico')): + with self.subTest(flavor=flavor, destination=destination, source=source): + with self.assertRaisesRegex(RuntimeError, 'Invalid reviewed branding asset path'): + check_branding_asset_paths(flavor(destination), flavor(source)) + + def test_windows_drive_and_unc_sources_are_rejected(self): + for source in ('C:/theme/icon.ico', 'C:theme/icon.ico', '//server/share/icon.ico'): + with self.subTest(source=source): + with self.assertRaisesRegex(RuntimeError, 'Invalid reviewed branding asset path'): + check_branding_asset_paths(PureWindowsPath('chrome/app/theme/icon.ico'), + PureWindowsPath(source)) class OrderedPatchTests(unittest.TestCase):