Skip to content

Arbitrary Code Execution via JavaScript Queries (CVE-2021-42057) #615

@tivey-scwx

Description

@tivey-scwx

Describe the bug

I discovered a way to craft malicious markdown files that will cause the obsidian-dataview plugin to execute arbitrary commands on users’ systems. This is due to the unsafe use of eval within the evalInContext function located in src/api/inline-api.ts.

This has been assigned a CVE of CVE-2021-42057 for tracking.

To Reproduce

The following proof-of-concept can be used to display a file on a user’s system by executing the cat command:

```dataviewjs
require("child_process").exec("cat /etc/passwd",(_0,stdout,_1) => dv.span(stdout));""
```

A malicious user could leverage this vulnerability to execute arbitrary code on other users' systems by getting them to open an untrusted markdown file. This is especially dangerous in environments where users share vaults.

Expected behavior

DataviewJS should not make an unsafe call to eval using user supplied input.

Additional Context

Shortly after we privately disclosed this issue, @blacksmithgu promptly changed the default behavior of Dataview to no longer enable JavaScript Queries by default (see release 0.4.13). This helps protect new dataview users and provides a way for existing dataview users to mitigate this issue by disabling the JavaScript Query functionality when opening untrusted markdown.

@blacksmithgu is currently working on additional solutions and provided permission for us to open a public issue here for tracking.

Metadata

Metadata

Labels

bugSomething isn't working.effort-highThis is a challenging issue that requires architectural changes to Dataview.priority-highA fix is incoming for this in an upcoming patch version.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions