Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions scripts/apply_chromium_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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')
Expand Down
32 changes: 30 additions & 2 deletions scripts/test_apply_chromium_patches.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
Loading