-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix(editor): accept plugin node kinds in the scene save API #490
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
konevenkatesh
wants to merge
1
commit into
pascalorg:main
Choose a base branch
from
konevenkatesh:fix/scene-api-plugin-node-kinds
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.
+193
−2
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| import { expect, test } from 'bun:test' | ||
| import { apiGraphSchema } from './graph-schema' | ||
|
|
||
| function buildGraph(nodes: Record<string, unknown>, rootNodeIds: string[] = []) { | ||
| return { nodes, rootNodeIds } | ||
| } | ||
|
|
||
| const level = (children: string[] = []) => ({ | ||
| object: 'node', | ||
| id: 'level_a1b2c3d4e5f6g7h8', | ||
| type: 'level', | ||
| parentId: null, | ||
| children, | ||
| level: 0, | ||
| }) | ||
|
|
||
| const pluginTree = (overrides: Record<string, unknown> = {}) => ({ | ||
| object: 'node', | ||
| id: 'tree_a1b2c3d4e5f6g7h8', | ||
| type: 'trees:tree', | ||
| parentId: 'level_a1b2c3d4e5f6g7h8', | ||
| position: [1, 0, 2], | ||
| rotation: 0, | ||
| ...overrides, | ||
| }) | ||
|
|
||
| test('accepts a graph containing a plugin node kind', () => { | ||
| const graph = buildGraph({ [pluginTree().id]: pluginTree() }, ['level_a1b2c3d4e5f6g7h8']) | ||
|
|
||
| expect(apiGraphSchema.safeParse(graph).success).toBe(true) | ||
| }) | ||
|
|
||
| test('accepts a builtin level whose children include a plugin node id', () => { | ||
| const tree = pluginTree() | ||
| const graph = buildGraph( | ||
| { | ||
| [level().id]: level([tree.id]), | ||
| [tree.id]: tree, | ||
| }, | ||
| [level().id], | ||
| ) | ||
|
|
||
| expect(apiGraphSchema.safeParse(graph).success).toBe(true) | ||
| }) | ||
|
|
||
| test('keeps plugin child ids in the parsed graph', () => { | ||
| const tree = pluginTree() | ||
| const graph = buildGraph( | ||
| { | ||
| [level().id]: level([tree.id]), | ||
| [tree.id]: tree, | ||
| }, | ||
| [level().id], | ||
| ) | ||
|
|
||
| const res = apiGraphSchema.safeParse(graph) | ||
|
|
||
| expect(res.success).toBe(true) | ||
| const parsedLevel = res.data?.nodes[level().id] as { children: string[] } | ||
| expect(parsedLevel.children).toEqual([tree.id]) | ||
| }) | ||
|
|
||
| test('rejects a plugin node that fails the base envelope', () => { | ||
| const graph = buildGraph({ | ||
| tree_bad: pluginTree({ id: 42 }), | ||
| }) | ||
|
|
||
| expect(apiGraphSchema.safeParse(graph).success).toBe(false) | ||
| }) | ||
|
|
||
| test('rejects dangerous URL schemes nested in plugin node fields', () => { | ||
| for (const url of [ | ||
| 'javascript:alert(1)', | ||
| ' file:///etc/passwd', | ||
| 'data:text/html,<script>1</script>', | ||
| ]) { | ||
| const graph = buildGraph({ | ||
| [pluginTree().id]: pluginTree({ config: { textures: [{ src: url }] } }), | ||
| }) | ||
|
|
||
| const res = apiGraphSchema.safeParse(graph) | ||
|
|
||
| expect(res.success).toBe(false) | ||
| expect(res.error?.issues[0]?.message).toBe('URL scheme not allowed in plugin node fields') | ||
| } | ||
| }) | ||
|
|
||
| test('allows data:image URLs in plugin node fields', () => { | ||
| const graph = buildGraph({ | ||
| [pluginTree().id]: pluginTree({ thumbnail: 'data:image/png;base64,iVBORw0KGgo=' }), | ||
| }) | ||
|
|
||
| expect(apiGraphSchema.safeParse(graph).success).toBe(true) | ||
| }) | ||
|
|
||
| test('still rejects invalid builtin nodes', () => { | ||
| const graph = buildGraph({ | ||
| wall_bad: { object: 'node', id: 'wall_a1b2c3d4e5f6g7h8', type: 'wall' }, | ||
| }) | ||
|
|
||
| expect(apiGraphSchema.safeParse(graph).success).toBe(false) | ||
| }) | ||
|
|
||
| test('does not treat non-namespaced unknown types as plugin kinds', () => { | ||
| const graph = buildGraph({ | ||
| mystery_1: { object: 'node', id: 'mystery_1', type: 'mystery' }, | ||
| }) | ||
|
|
||
| expect(apiGraphSchema.safeParse(graph).success).toBe(false) | ||
| }) |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plugin URL scan misses SSRF
Medium Severity
DANGEROUS_STRINGonly denylistsjavascript/vbscript/file/ftpand non-imagedata:, so plugin nodes can persist non-loopbackhttp://(andws:) URLs thatAssetUrlrejects on builtin fields. Combined with.passthrough(), crafted fields likeconfig.textures[].srcreopen the Phase 3 client-side beacon/SSRF class the comments claim this path preserves.Additional Locations (1)
apps/editor/lib/graph-schema.ts#L87-L95Reviewed by Cursor Bugbot for commit dbbfb0d. Configure here.