-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The exit condition is finding a day the excludes list misses\n\n`fixTaskDates` lives in `packages/mermaid/src/diagrams/gantt/ganttDb.js`. The pre-patch body, lines 253 through 267:\n\n```javascript\nconst fixTaskDates = function (startTime, endTime, dateFormat, excludes, includes) {\n let invalid = false;\n let renderEndTime = null;\n while (startTime <= endTime) {\n if (!invalid) {\n renderEndTime = endTime.toDate();\n }\n invalid = isInvalidDate(startTime, dateFormat, excludes, includes);\n if (invalid) {\n endTime = endTime.add(1, 'd');\n }\n startTime = startTime.add(1, 'd');\n }\n return [endTime, renderEndTime];\n};\n```\n\nThe loop iterates while `startTime <= endTime`. Each iteration: `isInvalidDate` decides whether the current `startTime` is on the excludes list. If it is, `endTime` advances by one day. `startTime` also advances by one day at the bottom of the loop. The two pointers move together.\n\nThe intended semantics is to stretch the task's end time forward over excluded days until enough non-excluded days have elapsed to cover the original task duration. A task that should span three working days, scheduled in a chart whose excludes covers weekends, becomes a task that runs five calendar days. The loop's exit condition `startTime <= endTime` depends on at least one day along the way being non-excluded. When a non-excluded day shows up, `invalid` becomes false, `endTime` stops advancing, and `startTime` catches up.\n\n`isInvalidDate` is the predicate the loop checks against. From the same file, lines 169 through 187:\n\n```javascript\nexport const isInvalidDate = function (date, dateFormat, excludes, includes) {\n const formattedDate = date.format(dateFormat.trim());\n const dateOnly = date.format('YYYY-MM-DD');\n\n if (includes.includes(formattedDate) || includes.includes(dateOnly)) {\n return false;\n }\n if (\n excludes.includes('weekends') &&\n (date.isoWeekday() === WEEKEND_START_DAY[weekend] ||\n date.isoWeekday() === WEEKEND_START_DAY[weekend] + 1)\n ) {\n return true;\n }\n if (excludes.includes(date.format('dddd').toLowerCase())) {\n return true;\n }\n return excludes.includes(formattedDate) || excludes.includes(dateOnly);\n};\n```\n\nThe penultimate clause is the relevant one. The current day's lower-cased English name (`monday`, `tuesday`, and so on) is checked against the excludes list. Any day whose name is in excludes is invalid.\n\nThe GHSA writeup names the four-line gantt source that triggers the CVE:\n\n```\ngantt\n excludes monday,tuesday,wednesday,thursday,friday,saturday,sunday\n DoS :2025-01-01, 1d\n```\n\nEvery day of the week is in excludes. Every date `isInvalidDate` is asked about returns true. Inside `fixTaskDates`, `invalid` is true on every iteration; `endTime` advances every iteration; `startTime` advances every iteration; the loop's exit condition `startTime <= endTime` continues to hold because both sides advance by the same amount. The loop has no exit.\n\nThe advisory's separate note about `mermaid.parse` being unaffected unless `ganttDb.getTasks()` is then called maps to this. Parsing produces the AST, and the AST is safe to walk. Rendering is what invokes `checkTaskDates` per task, which invokes `fixTaskDates`, which is the function with no exit. A pipeline that parses markdown without rendering does not hit the bug. A pipeline that renders does.\n\n## The patch is a circuit breaker, not a contract\n\nThe 10.9.6 and 11.15.0 fix is commit [faafb5d49106dd32c367f3882505f2dd625aa30e](https://github.com/mermaid-js/mermaid/commit/faafb5d49106dd32c367f3882505f2dd625aa30e):\n\n```diff\n const fixTaskDates = function (startTime, endTime, dateFormat, excludes, includes) {\n let invalid = false;\n let renderEndTime = null;\n+ const maxEndTime = endTime.add(10000, 'd');\n while (startTime <= endTime) {\n if (!invalid) {\n renderEndTime = endTime.toDate();\n }\n invalid = isInvalidDate(startTime, dateFormat, excludes, includes);\n if (invalid) {\n endTime = endTime.add(1, 'd');\n+ if (endTime > maxEndTime) {\n+ throw new Error(\n+ 'Failed to find a valid date that was not excluded by `excludes` after 10,000 iterations.'\n+ );\n+ }\n }\n startTime = startTime.add(1, 'd');\n }\n return [endTime, renderEndTime];\n };\n```\n\nA `maxEndTime` is computed once at function entry as the original `endTime` plus ten thousand days. Each iteration of the inner `invalid` branch checks whether the running `endTime` has crossed it. If so, the function throws.\n\nThe commit message explains the constant's derivation:\n\n> I've picked 10k days, in case some users are using `dateFormat` and `excludes` to exclude entire years, since 10k days is 27 years, and anything above that starts to have noticable lag.\n\nThe number is chosen by intuition about which legitimate gantt charts the author is willing to break. Twenty-seven years is the budget. A chart whose excludes legitimately covers many years (entire calendar years marked as excluded, the example the author cites) needs the loop to keep running through them. A chart whose excludes covers all seven weekday names needs the loop to stop. The cap separates the two by the number of iterations, not by the structure of `excludes`.\n\nThe structural fact about the bug is that no caller of `fixTaskDates` asserts the upstream invariant the loop depends on, that at least one day inside the working window is not in the excludes list. The patch does not install that invariant. It installs a clock. The function's exit condition before the patch was the patience of the caller's render pipeline. The function's exit condition after the patch is the patience of the caller's render pipeline, bounded above at twenty-seven years.\n\n## The TODO is still in the file\n\nThe post-patch docblock for `fixTaskDates`, lines 242 through 253 of the same file after the fix landed:\n\n```javascript\n/**\n * TODO: what does this function do?\n *\n * @param {dayjs.Dayjs} startTime - The start time.\n * @param {dayjs.Dayjs} endTime - The original end time (will return a different end time if it's invalid).\n * @param {string} dateFormat - Dayjs date format string.\n * @param {string[]} excludes - Dates or days to exclude.\n * @param {string[]} includes - Dates to always include, even if they match the excludes.\n * @returns {[endTime: dayjs.Dayjs, renderEndTime: Date | null]} The new `endTime`, and the end time to render.\n * `renderEndTime` may be `null` if `startTime` is newer than `endTime`.\n * @throws {Error} If a valid end time cannot be found after 10,000 iterations.\n */\n```\n\nThe patch tightened the `@param {*} excludes` and `@param {*} includes` annotations into proper `string[]` types with one-line descriptions. The patch added a `@throws` clause naming the new failure mode. The patch did not delete the `TODO: what does this function do?` line standing above all of it.\n\nThe author who wrote the security fix improved the parameter documentation, added a throws clause for the new failure mode, and left in place the line above them asking what the function does.\n\nThe TODO is not isolated. The same file carries three sibling TODOs on the function directly above `fixTaskDates`, `checkTaskDates`:\n\n```javascript\n/**\n * TODO: fully document what this function does and what types it accepts\n *\n * @param {object} task - The task to check.\n * @param {string | Date} task.startTime - Might be a `Date` or a `string`.\n * TODO: is this always a Date?\n * @param {string | Date} task.endTime - Might be a `Date` or a `string`.\n * TODO: is this always a Date?\n * @param {string} dateFormat - Dayjs date format string.\n * @param {*} excludes\n * @param {*} includes\n */\nconst checkTaskDates = function (task, dateFormat, excludes, includes) {\n```\n\nFour TODOs in two adjacent functions, all documenting the maintainers' uncertainty about what the code does and what types its arguments are. The functions belong to the gantt's date-arithmetic path. Both ship in every release of mermaid that supports gantt charts.\n\n`git log -S \"TODO: what does this function do\"` traces the line back to commit `a5db04b0`, dated February 26 2023, the `refactor(deps): replace moment with dayjs` commit. The author who wrote the TODO was performing a moment-to-dayjs migration on a function whose original author had already left the codebase, did not understand what it did, annotated their incomprehension, and migrated it anyway. Three years and one month later, the function shipped CVE-2026-41150 because no later maintainer understood it well enough to ask whether `excludes` could legitimately cover every day of the week.\n\n## Gantt rendering is a design-debt driver\n\nCVE-2026-41150's patch is the third denial-of-service-class fix to gantt rendering inside six months on the `develop` branch.\n\n| Date | Commit | Subject |\n|------|--------|---------|\n| 2025-09-15 | `525a7de8` | fix: gant chart crashing in browser |\n| 2025-11-26 | `6025ec66` | 5496: fixed UI crash from excessive tick generation with invalid dates/intervals |\n| 2026-03-30 | `faafb5d4` | fix(gantt): limit loop if excluding all dates |\n\nThree different code paths in the gantt rendering subsystem, three different attacker-influenced inputs (date format, tick interval, excludes list), three different unbounded operations. Each fix closes the specific path. The component continues to ship the underlying design: gantt rendering accepts user-supplied scheduling constraints and walks them out as iterations whose termination depends on the constraints being internally consistent. The November 2025 fix added error handling around tick generation. The March 2026 fix added a 10,000-iteration cap to date fixing. The next instance is one new attacker-supplied scheduling primitive away.\n\nThe four `TODO` comments in `ganttDb.js` are the substrate made legible. The component is fertile for this bug family because nobody owns it well enough to install upstream invariants. Patches address the specific symptom; the design holds the primitive.\n\n## The blast radius is wherever markdown renders mermaid server-side\n\nThe advisory's affected range is mermaid 10.0 through 10.9.5 and 11.0.0-alpha.1 through 11.14.0. The npm package is installed by the markdown rendering pipelines for mkdocs-material via `mkdocs-mermaid2-plugin`, Docusaurus via `@docusaurus/theme-mermaid`, mintlify, hashnode, and a long list of static-site generators that ship mermaid as the optional or default diagrammer. The mermaid CLI, `@mermaid-js/mermaid-cli`, ships a Puppeteer-backed renderer that takes mermaid source and produces SVG; documentation pipelines that pre-render at build time use it.\n\nThe CVSS vector `AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L` rates this as availability-only, network-reachable, no-privilege, no-interaction. The composition is: anyone who can submit markdown to a pipeline that renders mermaid server-side can wedge the pipeline's renderer with an eight-line gantt snippet. Pipelines that parse-but-not-render are unaffected. Pipelines that render block on the rendering thread until the host kills the process or the patch's 10,000-iteration ceiling fires.\n\nClient-side renderers (GitHub's in-browser mermaid render, GitLab's in-browser mermaid render, viewers that ship mermaid as a JavaScript bundle) push the cost onto the viewer's browser instead of the server. The bug is the same. The victim is different. The CVSS scope is `S:U`; the actual scope is whatever process is unlucky enough to call `ganttDb.getTasks()` on attacker-supplied input.\n\n## What the function does\n\nThe function walks forward from a start date, advancing the end date past excluded days, until it finds a day the excludes list does not eliminate. The patch does not say this in the docblock. The patch leaves the question.","closing_line":"The TODO survived the patch.","hook_md":"Mermaid's gantt renderer contains a function called `fixTaskDates`. It walks forward from a task's start date one day at a time, looking for an end date the chart's `excludes` list does not eliminate. The docblock above the function, added on February 26 2023 during a refactor that migrated the file from `moment` to `dayjs`, reads verbatim: `TODO: what does this function do?`.\n\nCVE-2026-41150 is what happens when a chart's `excludes` covers every day of the week. The function walks forward forever. The patch that closes the CVE adds a ten-thousand-iteration cap and updates the param documentation. The TODO is still in the file.","post_id":566,"slug":"mermaid-cve-2026-41150-todo-survived-the-patch","title":"CVE-2026-41150: Mermaid's Gantt Loop Got an Iteration Cap. The TODO Above It Survived the Patch.","type":"initial","unreadable_sentence":"The author who wrote the security fix improved the parameter documentation, added a throws clause for the new failure mode, and left in place the line above them asking what the function does."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCaq7J3QAKCRDeZjl4jgkQ Jnk5AP4sOSCUvkpFgtgtZQQZ1IEQEFWb4Ra/+bTuJMFX+YCUrAD/aqJ3JtX6FV2r mXN7bY8XqGkmNQ0Dv/XnF2rx9+0S6ws= =bRIK -----END PGP SIGNATURE-----