[Privacy] Use of __contentFilePath query param for gatsby-plugin-mdx leaks absolute file paths #37677
Closed
2 tasks done
Labels
status: confirmed
Issue with steps to reproduce the bug that’s been verified by at least one reviewer.
type: bug
An issue or pull request relating to a bug in Gatsby
Preliminary Checks
Description
The documentation for gatsby-plugin-mdx describes attaching a query param when creating a page so that the plugin can access the path to the original MDX file.
Normally when Gatsby generates component chunk names, it converts the absolute component path to a path relative to the project root before applying the kebab transformation. However, it doesn't have any special handling to alter or remove query parameters. Since
contentFilePath
is an absolute path, attaching it as a query param results in the chunk names containing the entire absolute path structure. Chunk names are referenced repeatedly in the HTML and JS files meant for clients, so this leaks the names of the developer or build machine's directories outside the project folder.For example,
component = C:\my\privates\mywebsite\src\components\page.tsx?__contentFilePath=C:/my/privates/mywebsite/src/pages/about.md
creates the chunk namecomponent---src-components-page-tsx-content-file-path-c-my-privates-mywebsite-src-pages-about-md
, createspublic\<chunkName>.js
and references the string in the window.___chunkMapping of every HTML file.While the issue of Gatsby including paths in component names has come up before (#18791), this case is particularly egregious since it includes path information outside of the project directory and results in excessively long chunk names.
Reproduction Link
https://github.com/gatsbyjs/gatsby/tree/master/examples/using-mdx
Steps to Reproduce
Expected Result
Generated files and chunk names do not contain absolute path information
Actual Result
Generated files and chunk names contain absolute path information
Environment
Config Flags
No response
The text was updated successfully, but these errors were encountered: