-
Notifications
You must be signed in to change notification settings - Fork 212
fix(devtools): harden RPC surface against traversal, spoofing, and dead auth UI #1086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
antfubot
wants to merge
3
commits into
nuxt:main
Choose a base branch
from
antfubot:fix/devtools-rpc-security-hardening
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+149
−33
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import type { Nuxt } from 'nuxt/schema' | ||
| import type { NuxtDevtoolsServerContext } from '../src/types' | ||
| import fsp from 'node:fs/promises' | ||
| import { tmpdir } from 'node:os' | ||
| import { join } from 'node:path' | ||
| import { afterEach, beforeEach, describe, expect, it } from 'vitest' | ||
| import { setupAssetsRPC } from '../src/server-rpc/assets' | ||
|
|
||
| function fakeContext(srcDir: string): NuxtDevtoolsServerContext { | ||
| return { | ||
| nuxt: { | ||
| options: { | ||
| srcDir, | ||
| dir: { public: 'public' }, | ||
| app: { baseURL: '/' }, | ||
| _layers: [], | ||
| }, | ||
| hook: () => {}, | ||
| } as unknown as Nuxt, | ||
| options: {}, | ||
| refresh: () => {}, | ||
| } as unknown as NuxtDevtoolsServerContext | ||
| } | ||
|
|
||
| describe('writeStaticAssets', () => { | ||
| let root: string | ||
|
|
||
| beforeEach(async () => { | ||
| root = await fsp.mkdtemp(join(tmpdir(), 'devtools-assets-')) | ||
| await fsp.mkdir(join(root, 'public'), { recursive: true }) | ||
| }) | ||
|
|
||
| afterEach(async () => { | ||
| await fsp.rm(root, { recursive: true, force: true }) | ||
| }) | ||
|
|
||
| it('writes files inside the public directory', async () => { | ||
| const { writeStaticAssets } = setupAssetsRPC(fakeContext(root)) | ||
| const [written] = await writeStaticAssets!([{ path: 'a.txt', content: 'hi' }], '') | ||
| expect(written).toBe(join(root, 'public', 'a.txt')) | ||
| expect(await fsp.readFile(written!, 'utf-8')).toBe('hi') | ||
| }) | ||
|
|
||
| it('rejects a folder that escapes the public directory', async () => { | ||
| const { writeStaticAssets } = setupAssetsRPC(fakeContext(root)) | ||
| await expect( | ||
| writeStaticAssets!([{ path: 'nuxt.config.ts', content: 'evil' }], '/../..'), | ||
| ).rejects.toThrow(/outside of the public directory/) | ||
| }) | ||
|
|
||
| it('rejects a file path that escapes the public directory', async () => { | ||
| const { writeStaticAssets } = setupAssetsRPC(fakeContext(root)) | ||
| await expect( | ||
| writeStaticAssets!([{ path: '../../etc/passwd', content: 'evil' }], ''), | ||
| ).rejects.toThrow(/outside of the public directory/) | ||
| }) | ||
|
|
||
| it('treats an absolute-looking path as relative to the public directory', async () => { | ||
| const { writeStaticAssets } = setupAssetsRPC(fakeContext(root)) | ||
| const [written] = await writeStaticAssets!([{ path: '/passwd.txt', content: 'not the real one' }], '') | ||
| expect(written).toBe(join(root, 'public', 'passwd.txt')) | ||
| }) | ||
|
|
||
| it('rejects writing through a symlinked directory that points outside the public directory', async () => { | ||
| const outside = join(root, 'outside') | ||
| await fsp.mkdir(outside, { recursive: true }) | ||
| await fsp.symlink(outside, join(root, 'public', 'linked'), 'dir') | ||
|
|
||
| const { writeStaticAssets } = setupAssetsRPC(fakeContext(root)) | ||
| await expect( | ||
| writeStaticAssets!([{ path: 'evil.txt', content: 'evil' }], '/linked'), | ||
| ).rejects.toThrow(/outside of the public directory/) | ||
| await expect(fsp.access(join(outside, 'evil.txt'))).rejects.toThrow() | ||
| }) | ||
|
|
||
| it('rejects overwriting an existing symlink target', async () => { | ||
| const outsideFile = join(root, 'secret.txt') | ||
| await fsp.writeFile(outsideFile, 'original') | ||
| await fsp.symlink(outsideFile, join(root, 'public', 'link.txt')) | ||
|
|
||
| const { writeStaticAssets } = setupAssetsRPC(fakeContext(root)) | ||
| await expect( | ||
| writeStaticAssets!([{ path: 'link.txt', content: 'evil', override: true }], ''), | ||
| ).rejects.toThrow(/symbolic link/) | ||
| expect(await fsp.readFile(outsideFile, 'utf-8')).toBe('original') | ||
| }) | ||
| }) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.