Guard remote runtime PTY id decoding (#3626)

This commit is contained in:
Neil 2026-05-30 13:09:20 -07:00 committed by GitHub
parent ddbb6a1e7d
commit 7a8b10bd7d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 3 deletions

View File

@ -27,6 +27,13 @@ describe('remote runtime terminal ids', () => {
expect(getRemoteRuntimePtyEnvironmentId('remote:terminal-1')).toBeNull()
expect(getRemoteRuntimeTerminalHandle('remote:terminal-1')).toBe('terminal-1')
})
it('treats malformed encoded ids as invalid instead of throwing', () => {
const malformed = 'remote:%E0%A4%A@@terminal-1'
expect(getRemoteRuntimePtyEnvironmentId(malformed)).toBeNull()
expect(getRemoteRuntimeTerminalHandle(malformed)).toBeNull()
})
})
describe('remote runtime terminal data subscriptions', () => {

View File

@ -27,9 +27,13 @@ export function parseRemoteRuntimePtyId(ptyId: string): RemoteRuntimePtyIdParts
if (separatorIndex === -1) {
return { environmentId: null, handle: rest }
}
return {
environmentId: decodeURIComponent(rest.slice(0, separatorIndex)),
handle: decodeURIComponent(rest.slice(separatorIndex + REMOTE_PTY_OWNER_SEPARATOR.length))
try {
return {
environmentId: decodeURIComponent(rest.slice(0, separatorIndex)),
handle: decodeURIComponent(rest.slice(separatorIndex + REMOTE_PTY_OWNER_SEPARATOR.length))
}
} catch {
return null
}
}