chartbook.conf_validation#

Security validation for user-provided configuration values.

This module provides validation for values that will be inserted into conf.py templates. Since conf.py is executed as Python code by Sphinx, all user input must be validated to prevent code injection attacks.

Module Contents#

Classes#

SiteConfig

Validated site configuration for conf.py template rendering.

Functions#

validate_conf_py_values

Validate configuration values intended for conf.py template.

validate_source_files

Validate that all source files referenced in the manifest exist.

API#

class chartbook.conf_validation.SiteConfig[source]#

Validated site configuration for conf.py template rendering.

All string values are validated against security patterns to prevent Python code injection when rendered into conf.py templates.

Attributes: title: Project title (alphanumeric, spaces, basic punctuation). author: Author name (alphanumeric, spaces, basic punctuation). copyright: Copyright text (alphanumeric, spaces, basic punctuation). sphinx_theme: Sphinx theme name (must be from allowed list).

ALLOWED_THEMES: ClassVar[frozenset[str]]#

‘frozenset(…)’

MAX_TEXT_LENGTH: ClassVar[int]#

200

SAFE_TEXT_PATTERN: ClassVar[re.Pattern]#

‘compile(…)’

TOML_KEYS: ClassVar[dict[str, str]]#

None

author: str#

None

copyright: str#

None

classmethod from_manifest(manifest: dict, pipeline_theme: str) chartbook.conf_validation.SiteConfig[source]#

Create a validated SiteConfig from manifest dictionary.

Parameters:
  • manifest (dict) – The manifest dictionary from chartbook.toml.

  • pipeline_theme (str) – Either “catalog” or “pipeline”.

Returns:

Validated SiteConfig instance.

Return type:

SiteConfig

Raises:

ValidationError – If any value fails validation.

sphinx_theme: str#

None

title: str#

None

chartbook.conf_validation.validate_conf_py_values(manifest: dict, pipeline_theme: str) chartbook.conf_validation.SiteConfig[source]#

Validate configuration values intended for conf.py template.

This is the main entry point for validation. It ensures all values that will be inserted into conf.py are safe from code injection.

Parameters:
  • manifest (dict) – The manifest dictionary from chartbook.toml.

  • pipeline_theme (str) – Either “catalog” or “pipeline”.

Returns:

Validated SiteConfig instance with all values safe for templating.

Return type:

SiteConfig

Raises:

ValidationError – If any value fails security validation.

chartbook.conf_validation.validate_source_files(manifest: dict, base_dir) list[source]#

Validate that all source files referenced in the manifest exist.

Checks for the existence of:

  • Dataframe parquet files (path)

  • Dataframe documentation files (docs_path, when mode=“path”)

  • Chart HTML files (path)

  • Chart documentation files (docs_path, when mode=“path”)

  • Notebook files (path)

  • Note markdown files (path)

  • README.md per pipeline

  • User-specified logo and favicon files

Parameters:
  • manifest (dict) – The manifest dictionary from chartbook.toml.

  • base_dir (Path) – The base directory of the project.

Returns:

List of MissingFile objects for any files that don’t exist.

Return type:

list[MissingFile]