{"id":"CVE-2026-47712","aliases":["CVE-2026-47712","GHSA-555p-6grf-mh7f","PYSEC-2026-2462"],"related":[],"kind":"vulnerability","state":"published","title":"Dulwich doesn't sanitize commit subjects in `porcelain.format_patch`","summary":"Dulwich is a pure-Python implementation of the Git file formats and protocols. Starting in version 0.24.0 and prior to version 1.2.5, dulwich.porcelain.format_patch(outdir=...) derives each patch filename from the commit's subject line. Prior to this fix, get_summary only replaced spaces with dashes - path separators (/, \\), parent-directory components (..), and other filename-hostile characters (e.g. :) were preserved verbatim and passed straight into os.path.join(outdir, f\"{i:04d}-{summary}.patch\"). A malicious commit subject could therefore direct the generated patch file outside the requested outdir. This is fixed in Dulwich 1.2.5. Users should upgrade to 1.2.5 or later. dulwich.patch.get_summary now mirrors git's format_sanitized_subject: only `[A-Za-z0-9._]` are kept, runs of other characters collapse to a single -, consecutive . collapse to a single ., trailing ./- are stripped, and the result is length-limited. This makes the returned string safe to embed as a filename component, so format_patch can no longer be steered out of outdir via the commit subject. Until upgrading, callers that pass untrusted commits to   porcelain.format_patch can use stdout=True and write the patch to a destination they control, rather than letting format_patch choose the filename; validate the chosen path before opening - e.g. compare os.path.realpath(returned_path) against  os.path.realpath(outdir) and reject any patch whose resolved path is not inside outdir; and/or pre-screen commits and refuse to format any whose subject's first line contains /, \\, .., or other characters that are not safe on the target filesystem.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"Dulwich is a pure-Python implementation of the Git file formats and protocols. Starting in version 0.24.0 and prior to version 1.2.5, dulwich.porcelain.format_patch(outdir=...) derives each patch filename from the commit's subject line. Prior to this fix, get_summary only replaced spaces with dashes - path separators (/, \\), parent-directory components (..), and other filename-hostile characters (e.g. :) were preserved verbatim and passed straight into os.path.join(outdir, f\"{i:04d}-{summary}.patch\"). A malicious commit subject could therefore direct the generated patch file outside the requested outdir. This is fixed in Dulwich 1.2.5. Users should upgrade to 1.2.5 or later. dulwich.patch.get_summary now mirrors git's format_sanitized_subject: only `[A-Za-z0-9._]` are kept, runs of other characters collapse to a single -, consecutive . collapse to a single ., trailing ./- are stripped, and the result is length-limited. This makes the returned string safe to embed as a filename component, so format_patch can no longer be steered out of outdir via the commit subject. Until upgrading, callers that pass untrusted commits to   porcelain.format_patch can use stdout=True and write the patch to a destination they control, rather than letting format_patch choose the filename; validate the chosen path before opening - e.g. compare os.path.realpath(returned_path) against  os.path.realpath(outdir) and reject any patch whose resolved path is not inside outdir; and/or pre-screen commits and refuse to format any whose subject's first line contains /, \\, .., or other characters that are not safe on the target filesystem.","source":"cvelist"},{"lang":"en","text":"### Impact\n\ndulwich.porcelain.format_patch(outdir=...) derives each patch filename from the commit's subject line. Prior to this fix, get_summary only replaced spaces with dashes - path separators (/, \\),   parent-directory components (..), and   other filename-hostile characters (e.g. :)  were preserved verbatim and passed   straight into os.path.join(outdir,   f\"{i:04d}-{summary}.patch\").\n\nA malicious commit subject could therefore direct the generated patch file outside the requested outdir. Reduced examples:\n\n- x/../../x produced <outdir>/0001-x/../../x.patch, resolving\n  two directories above outdir.\n- x\\..\\..\\x produced the equivalent escape on Windows, here \\ is also a path separator.\n\nRelated issues from the same root cause:\n\n- Subjects containing characters that are illegal in Windows filenames (e.g. :) caused format_patch to fail outright on  Windows, where git would have succeeded.\n- Very long subjects produced excessively long filenames that could exceed filesystem limits; git truncates them.\n\nAnyone calling porcelain.format_patch (or the dulwich format-patch CLI) against untrusted commits - for example, a service that runs format-patch over user-supplied repositories or pull requests - could have patch files written to attacker-chosen locations within the process's write permissions.\n\n### Patches\n\nFixed in Dulwich 1.2.5. Users should upgrade.\n\n dulwich.patch.get_summary now mirrors git's format_sanitized_subject: only `[A-Za-z0-9._]` are kept, runs of other characters collapse to a single -, consecutive . collapse to a single ., trailing ./- are stripped, and the result is length-limited. This makes the returned string safe to embed as a filename component, so format_patch can no longer be steered out of outdir via the commit subject.\n\n###  Workarounds\n\nUntil upgrading, callers that pass untrusted commits to   porcelain.format_patch can:\n\n- Use stdout=True and write the patch to a destination they control, rather than letting format_patch choose the filename.\n- Validate the chosen path before opening - e.g. compare os.path.realpath(returned_path) against  os.path.realpath(outdir) and reject any patch whose resolved path is not inside outdir.\n- Pre-screen commits and refuse to format any whose subject's first line contains /, \\, .., or other characters that are not safe on the target filesystem.\n\n### Resources\n\n- Fix commit: https://github.com/jelmer/dulwich/commit/c2446e51b\n- Affected API: dulwich.porcelain.format_patch / dulwich format-patch\n- Reference behavior: git's format_sanitized_subject in pretty.c","format":"markdown","source":"ghsa"},{"lang":"es","text":"Dulwich es una implementación puramente en Python de los formatos de archivo y protocolos de Git. A partir de la versión 0.24.0 y antes de la versión 1.2.5, dulwich.porcelain.format_patch(outdir=...) deriva cada nombre de archivo de parche de la línea de asunto del commit. Antes de esta corrección, get_summary solo reemplazaba los espacios con guiones - los separadores de ruta (/, \\), los componentes de directorio padre (..), y otros caracteres hostiles para nombres de archivo (p. ej. :) se conservaban textualmente y se pasaban directamente a os.path.join(outdir, f\"{i:04d}-{summary}.patch\"). Un asunto de commit malicioso podría, por lo tanto, dirigir el archivo de parche generado fuera del outdir solicitado. Esto se corrige en Dulwich 1.2.5. Los usuarios deberían actualizar a la versión 1.2.5 o posterior. dulwich.patch.get_summary ahora refleja el format_sanitized_subject de git: solo se mantienen '[A-Za-z0-9._]', las secuencias de otros caracteres se colapsan a un solo -, los puntos consecutivos se colapsan a un solo ., los ./- finales se eliminan, y el resultado tiene una longitud limitada. Esto hace que la cadena devuelta sea segura para incrustar como un componente de nombre de archivo, por lo que format_patch ya no puede ser dirigido fuera de outdir a través del asunto del commit. Hasta que se actualice, los llamadores que pasan commits no confiables a porcelain.format_patch pueden usar stdout=True y escribir el parche en un destino que controlen, en lugar de dejar que format_patch elija el nombre de archivo; validar la ruta elegida antes de abrir - p. ej. comparar os.path.realpath(returned_path) con os.path.realpath(outdir) y rechazar cualquier parche cuya ruta resuelta no esté dentro de outdir; y/o pre-filtrar commits y negarse a formatear cualquiera cuya primera línea del asunto contenga /, \\, .., u otros caracteres que no sean seguros en el sistema de archivos de destino.","source":"nvd"}],"published":"2026-06-08T23:04:48.000Z","modified":"2026-07-21T19:10:00.107Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:L/A:N","score":3.3,"rating":"LOW"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:L/A:N","score":3.3,"rating":"LOW"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:L/A:N","score":3.3,"rating":"LOW"},{"scorer":"PyPA Advisory Database","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:L/A:N","score":3.3,"rating":"LOW"}],"cwes":["CWE-22"],"affected":[{"ranges":[{"version":">= 0.24.0, < 1.2.5","status":"affected"}],"vendor":"jelmer","product":"dulwich","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0.24.0","status":"affected","fixed":"1.2.5"}],"ecosystem":"PyPI","package":"dulwich","purl":"pkg:pypi/dulwich","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"0.24.0","status":"affected","fixed":"1.2.5"}],"ecosystem":"PyPI","package":"dulwich","purl":"pkg:pypi/dulwich","source":"pysec"}],"references":[{"url":"https://github.com/jelmer/dulwich/security/advisories/GHSA-555p-6grf-mh7f","tags":["web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/jelmer/dulwich/commit/c2446e51b","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/jelmer/dulwich/releases/tag/dulwich-1.2.5","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-47712","tags":["advisory"],"sources":["ghsa","pysec"]},{"url":"https://github.com/jelmer/dulwich","tags":["package"],"sources":["ghsa","pysec"]},{"url":"https://pypi.org/project/dulwich","tags":["package"],"sources":["pysec"]},{"url":"https://github.com/advisories/GHSA-555p-6grf-mh7f","tags":["advisory"],"sources":["pysec"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"none","automatable":"no","technicalImpact":"partial","date":"2026-06-11T12:41:02.775Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-47712","url":"https://www.cve.org/CVERecord?id=CVE-2026-47712","licence":"CVE Terms of Use","modified":"2026-06-11T12:42:40.209Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-555p-6grf-mh7f","url":"https://github.com/advisories/GHSA-555p-6grf-mh7f","licence":"CC-BY-4.0","modified":"2026-07-13T16:43:37.445Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-47712","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-47712","licence":"Public domain","modified":"2026-07-21T19:10:00.107Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2026-2462","url":"https://osv.dev/vulnerability/PYSEC-2026-2462","licence":"CC-BY-4.0","modified":"2026-07-13T16:31:45.177Z"}],"updatedAt":"2026-11-25T22:59:24.400Z","epss":{"score":0.00139,"percentile":0.03445,"date":"2026-12-01T12:00:22.000Z"}}