-
Notifications
You must be signed in to change notification settings - Fork 9
Fix terminal plugin bugs #238
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,7 +48,7 @@ export async function terminalPlugin(fastify, options = {}) { | |
| }); | ||
|
|
||
| fastify.get(wsPath, { websocket: true }, async (connection, request) => { | ||
| const socket = connection.socket; | ||
| const socket = connection.socket || connection; | ||
|
|
||
| // Authenticate — query param token support for browser WebSocket | ||
| const queryToken = request.query?.token; | ||
|
|
@@ -57,14 +57,15 @@ export async function terminalPlugin(fastify, options = {}) { | |
| } | ||
| const { webId } = await getWebIdFromRequestAsync(request); | ||
|
|
||
| if (!webId) { | ||
| if (!webId && !options.public) { | ||
| socket.send(JSON.stringify({ type: 'error', message: 'Authentication required' })); | ||
| socket.close(); | ||
| return; | ||
| } | ||
|
Comment on lines
+60
to
64
|
||
|
|
||
| // Spawn shell | ||
| const shell = spawn('/bin/sh', [], { | ||
| const shellCommand = process.env.SHELL || 'bash'; | ||
| const shell = spawn(shellCommand, ['-i'], { | ||
| stdio: ['pipe', 'pipe', 'pipe'], | ||
| env: { ...process.env, TERM: 'xterm-256color' }, | ||
| }); | ||
|
Comment on lines
+67
to
71
|
||
|
|
@@ -74,14 +75,14 @@ export async function terminalPlugin(fastify, options = {}) { | |
| // Pipe shell stdout to WebSocket | ||
| shell.stdout.on('data', (data) => { | ||
| if (socket.readyState === 1) { | ||
| try { socket.send(data); } catch { /* socket closed */ } | ||
| try { socket.send(data.toString().replace(/\r?\n/g, '\r\n')); } catch { /* socket closed */ } | ||
| } | ||
|
Comment on lines
76
to
79
|
||
| }); | ||
|
|
||
| // Pipe shell stderr to WebSocket | ||
| shell.stderr.on('data', (data) => { | ||
| if (socket.readyState === 1) { | ||
| try { socket.send(data); } catch { /* socket closed */ } | ||
| try { socket.send(data.toString().replace(/\r?\n/g, '\r\n')); } catch { /* socket closed */ } | ||
| } | ||
|
Comment on lines
83
to
86
|
||
| }); | ||
|
|
||
|
|
||
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.
Passing
public: options.publicinto the terminal plugin means starting the server in public mode will expose an unauthenticated WebSocket shell. This is likely too dangerous for a flag that is meant for public resource access; consider a separate CLI/server option to explicitly enable unauthenticated terminal access (or omit this option entirely).