Skip to content

fix: keep generated files inside outDir and stop output collisions - #84

Merged
rachfop merged 1 commit into
mainfrom
fix/path-safety
Oct 2, 2026
Merged

rachfop merged 1 commit into
mainfrom
fix/path-safety

Conversation

@rachfop

@rachfop rachfop commented Oct 2, 2026

Copy link
Copy Markdown
Owner

Generated files could land outside the build directory or overwrite each other:

  • A front matter slug with .. segments (slug: ../../../x) wrote .md files above outDir. .. segments are now dropped, and any path outside outDir falls back to the title-based name with a warning.
  • customLLMFiles[].filename, versions[].path, and the standard filenames could point outside outDir. Validation rejects absolute paths and .. segments, and writes are guarded.
  • Output files with the same name (llmsTxtFilename equal to llmsFullTxtFilename, or a custom file named llms.txt) overwrote each other silently. Validation rejects them.
  • The custom-file pass reassigned .md paths from scratch, so it could overwrite a file the standard pass wrote and leave llms.txt linking to another page's content. Each doc now gets one path per version, shared by both passes.
  • With versions and generateMarkdownFiles, files for a version at path: 'stable' were written to build/stable/stable/, so its links 404'd.

tests/test-path-safety.js covers each case (18 of 30 checks fail on main). The docs site build output is unchanged.

- A frontmatter slug such as `../../../escaped` wrote its markdown file
  above outDir. Markdown paths drop `.`, `..` and empty segments, and a
  path that still resolves outside the output directory falls back to a
  filename from the page title.
- customLLMFiles[].filename (top-level and per version), llmsTxtFilename,
  llmsFullTxtFilename and versions[].path accepted absolute paths and `..`
  segments. Option validation rejects them; a write-time check skips any
  llms file or version directory outside outDir.
- Output files with the same name overwrote each other (llms.txt vs
  llms-full.txt, custom vs standard, custom vs custom). Option validation
  rejects collisions among the files that are generated, per version.
- Each generateIndividualMarkdownFiles call assigned paths from scratch,
  so the custom-file pass overwrote markdown files the standard pass
  wrote (two sections' intro.md with preserveDirectoryStructure: false).
  A per-version registry assigns each doc one file, reused by later passes.
- With versions and generateMarkdownFiles, /stable/get-started was written
  to build/stable/stable/get-started.md. The version path is stripped from
  URLs before mapping to files under the version directory and added back
  to the links.

Adds tests/test-path-safety.js covering each case.
@rachfop
rachfop merged commit df44bff into main Oct 2, 2026
5 checks passed
@rachfop
rachfop deleted the fix/path-safety branch October 2, 2026 22:43
rachfop added a commit that referenced this pull request Oct 2, 2026
- A frontmatter slug such as `../../../escaped` wrote its markdown file
  above outDir. Markdown paths drop `.`, `..` and empty segments, and a
  path that still resolves outside the output directory falls back to a
  filename from the page title.
- customLLMFiles[].filename (top-level and per version), llmsTxtFilename,
  llmsFullTxtFilename and versions[].path accepted absolute paths and `..`
  segments. Option validation rejects them; a write-time check skips any
  llms file or version directory outside outDir.
- Output files with the same name overwrote each other (llms.txt vs
  llms-full.txt, custom vs standard, custom vs custom). Option validation
  rejects collisions among the files that are generated, per version.
- Each generateIndividualMarkdownFiles call assigned paths from scratch,
  so the custom-file pass overwrote markdown files the standard pass
  wrote (two sections' intro.md with preserveDirectoryStructure: false).
  A per-version registry assigns each doc one file, reused by later passes.
- With versions and generateMarkdownFiles, /stable/get-started was written
  to build/stable/stable/get-started.md. The version path is stripped from
  URLs before mapping to files under the version directory and added back
  to the links.

Adds tests/test-path-safety.js covering each case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant