Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

copy_logo_images: do not render dynamic Sphinx template content #1204

Merged
merged 2 commits into from
Feb 20, 2023
Merged
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
6 changes: 6 additions & 0 deletions src/pydata_sphinx_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,12 @@ def copy_logo_images(app: Sphinx, exception=None) -> None:
continue
if not (Path(app.srcdir) / path_image).exists():
logger.warning(f"Path to {kind} image logo does not exist: {path_image}")
# Ensure templates cannot be passed for logo path to avoid security vulnerability
if path_image.lower().endswith("_t"):
choldgraf marked this conversation as resolved.
Show resolved Hide resolved
raise ExtensionError(
f"The {kind} logo path '{path_image}' looks like a Sphinx template; "
"please provide a static logo image."
)
copy_asset_file(path_image, staticdir)


Expand Down
14 changes: 14 additions & 0 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,20 @@ def test_logo_external_image(sphinx_build_factory):
assert f'src="{test_url}"' in index_str


def test_logo_template_rejected(sphinx_build_factory):
"""Test that dynamic Sphinx templates are not accepted as logo files"""
# Test with a specified external logo image source
confoverrides = {
"html_theme_options": {
"logo": {
"image_dark": "image_dark_t",
}
},
}
with pytest.raises(sphinx.errors.ExtensionError, match="static logo image"):
sphinx_build_factory("base", confoverrides=confoverrides).build()


def test_favicons(sphinx_build_factory):
"""Test that arbitrary favicons are included."""
html_theme_options_favicons = {
Expand Down