Open snowbagoly opened 8 months ago
How would it work then?
Thanks for looking into this! As far as I understood from other similar issues, they usually add a precompile step, resulting in directly adding the relevant functions, instead of serializing it and then deserializing it from a string. Would this be possible?
Ah good idea. We can do that.
Describe the bug
We have set the Content Security Policy not to allow
unsafe-eval
. This worked until we added a customtokenize
function for the search. Now the page fails to load the scripts with this error, which results in broken navigation:The stacktrace points to the
new Function
call indeserializeFunctions
(https://github.com/vuejs/vitepress/blob/main/src/node/utils/fnSerialize.ts#L42).Reproduction
To reproduce the issue, you have to create a vitepress config file that defines at least one function. In our case, we have defined a custom
tokenize
function for the search:Also you have to set the Content Security Policy not to allow
unsafe-eval
, e.g. if you use a similar configuration to us, you have to set thescript-src
to includeself
, and ansha256
for each script block.Expected behavior
Vitepress docs work with the customized search, even if the CSP does not allow
unsafe-eval
.System Info
Additional context
No response
Validations