Skip to content

Name Collision & Unintentional Link Leak #5143

@zhangyx1998

Description

@zhangyx1998

Describe the bug

1. Name Collision

Currently vitepress plugin flattens nested chunk paths by replacig / with _. This will naturally cause name conflict for certain file structures and fail the build with no clear indication of real cause:

.
├─ hello
│  └─ world.md    // [name] = hello_world
└─ hello_world.md // [name] = hello_world

This causes build error:

$ npx vitepress build docs

✗ rendering pages...
build error:
Cannot read properties of undefined (reading 'imports')
TypeError: Cannot read properties of undefined (reading 'imports')
    at resolvePageImports (file:///home/projects/vite-sffsehzv/node_modules/vitepress/dist/node/chunk-CCYAX98b.js:45416:18)
    at renderPage (file:///home/projects/vite-sffsehzv/node_modules/vitepress/dist/node/chunk-CCYAX98b.js:45307:10)
    at async pMap.concurrency (file:///home/projects/vite-sffsehzv/node_modules/vitepress/dist/node/chunk-CCYAX98b.js:45542:11)
    at async eval (file:///home/projects/vite-sffsehzv/node_modules/vitepress/dist/node/chunk-CCYAX98b.js:4240:20)

2. Unintentional Leak of Unlisted/Private links

Vitepress embeds a global hashmap __VP_HASH_MAP__ to every page containing the normalized file id, which can easily map back to links for the entire site, even if a page is intentionally left unlisted.

Some users might not be aware of this fact, and they might assume it safe to host an unlisted page with complex names to keep it private. This can result in unintentional leaks. In addition, some use cases require public unlisted hosting for limited circulation (e.g. peer review of a draft research paper).

Reproduction

  1. Name Conflict Reproduction
  2. Unlisted Page Leak Demo

Expected behavior

  1. Should build without error since /hello_world.html and /hello/world.html are both valid URL.
  2. Should not allow trivial scrapping.

System Info

Not relevant

Additional context

I've drafted a PR that potentially solves both issues.

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    buildRelated to the build system

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions