Skip to content

Commit 20e00ef

Browse files
authored
feat(api): add allowWrite and allowExec options to api (#9350)
1 parent 76c4397 commit 20e00ef

File tree

41 files changed

+502
-674
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+502
-674
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ jobs:
120120
- name: Test Examples
121121
run: pnpm run test:examples
122122

123-
- name: Unit Test UI
124-
run: pnpm run -C packages/ui test:ui
125-
126123
- uses: actions/upload-artifact@v6
127124
if: ${{ !cancelled() }}
128125
with:

docs/api/browser/commands.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ By default, Vitest uses `utf-8` encoding but you can override it with options.
1717

1818
::: tip
1919
This API follows [`server.fs`](https://vitejs.dev/config/server-options.html#server-fs-allow) limitations for security reasons.
20+
21+
If [`browser.api.allowWrite`](/config/browser/api) or [`api.allowWrite`](/config/api#api-allowwrite) are disabled, `writeFile` and `removeFile` functions won't do anything.
2022
:::
2123

2224
```ts

docs/api/browser/locators.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ outline: [2, 3]
77

88
A locator is a representation of an element or a number of elements. Every locator is defined by a string called a selector. Vitest abstracts this selector by providing convenient methods that generate them behind the scenes.
99

10-
The locator API uses a fork of [Playwright's locators](https://playwright.dev/docs/api/class-locator) called [Ivya](https://npmjs.com/ivya). However, Vitest provides this API to every [provider](/config/browser#browser-provider), not just playwright.
10+
The locator API uses a fork of [Playwright's locators](https://playwright.dev/docs/api/class-locator) called [Ivya](https://npmjs.com/ivya). However, Vitest provides this API to every [provider](/config/browser/provider), not just playwright.
1111

1212
::: tip
1313
This page covers API usage. To better understand locators and their usage, read [Playwright's "Locators" documentation](https://playwright.dev/docs/locators).

docs/config/api.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,28 @@ outline: deep
55

66
# api
77

8-
- **Type:** `boolean | number`
8+
- **Type:** `boolean | number | object`
99
- **Default:** `false`
1010
- **CLI:** `--api`, `--api.port`, `--api.host`, `--api.strictPort`
1111

1212
Listen to port and serve API for [the UI](/guide/ui) or [browser server](/guide/browser/). When set to `true`, the default port is `51204`.
13+
14+
## api.allowWrite <Version>4.1.0</Version> {#api-allowwrite}
15+
16+
- **Type:** `boolean`
17+
- **Default:** `true` if not exposed to the network, `false` otherwise
18+
19+
Vitest server can save test files or snapshot files via the API. This allows anyone who can connect to the API the ability to run any arbitary code on your machine.
20+
21+
::: danger SECURITY ADVICE
22+
Vitest does not expose the API to the internet by default and only listens on `localhost`. However if `host` is manually exposed to the network, anyone who connects to it can run arbitrary code on your machine, unless `api.allowWrite` and `api.allowExec` are set to `false`.
23+
24+
If the host is set to anything other than `localhost` or `127.0.0.1`, Vitest will set `api.allowWrite` and `api.allowExec` to `false` by default. This means that any write operations (like changing the code in the UI) will not work. However, if you understand the security implications, you can override them.
25+
:::
26+
27+
## api.allowExec <Version>4.1.0</Version> {#api-allowexec}
28+
29+
- **Type:** `boolean`
30+
- **Default:** `true` if not exposed to the network, `false` otherwise
31+
32+
Allows running any test file via the API. See the security advice in [`api.allowWrite`](#api-allowwrite).

0 commit comments

Comments
 (0)