VDB
Sign up
MEDIUM6.5

PYSEC-2026-3412

WeasyPrint has CSS Injection via Presentational Hints

Details

### Summary A CSS injection issue exists in WeasyPrint when HTML presentational hints are enabled. Unescaped attribute values are embedded into CSS, allowing injection of arbitrary CSS declarations. This affects applications processing untrusted HTML input.

### Details File: weasyprint/css/__init__.py

The `background` attribute is used to construct CSS:

background-image:url({element.get("background")})

This string is parsed by `tinycss2.parse_blocks_contents()`.

Because the value is not escaped, additional CSS declarations can be injected.

### PoC <body background="x);background-image:url(http://169.254.169.254/latest/meta-data/)">

### Impact - CSS injection - Server-side requests via injected `url()` - Limited to cases where `presentational_hints=True`

### Suggested Fix - Escape attribute values before embedding into CSS - Restrict allowed values for presentational hints [VULN-05_css_injection_presentational_hints.md](https://github.com/user-attachments/files/26370718/VULN-05_css_injection_presentational_hints.md)

Are you affected?

Enter the version of the package you're using.

Affected packages

PyPI/weasyprint
Introduced in: 0

No fixed version published yet for weasyprint (pip). Pin to a known-safe version or switch to an alternative.

References

Check it before you install it

One call answers whether to add this package: known advisories, CISA KEV, and whether the name is a hallucinated or freshly squatted one. No key needed to try it.

curl -s https://vdb.ai.kr/v1/ai/check-packages \
  -H 'Content-Type: application/json' \
  -d '{"packages":["pkg:pypi/weasyprint"]}'