Skip to content

Commit d5e9b4b

Browse files
mmelkotadayosi
authored andcommitted
fix: add additional check for the redirect to prevent XSS
1 parent 3ba9b34 commit d5e9b4b

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

Diff for: packages/hawtio/src/plugins/shared/connect-service.ts

+25-2
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,32 @@ class ConnectService implements IConnectService {
243243
*/
244244
redirect() {
245245
const url = new URL(window.location.href)
246-
const redirect = url.searchParams.get(PARAM_KEY_REDIRECT) ?? hawtio.getBasePath() ?? '/'
246+
let redirect = url.searchParams.get(PARAM_KEY_REDIRECT) ?? '/'
247+
let safeRedirect: boolean = false
248+
249+
try {
250+
const { hostname, port, protocol, searchParams } = new URL(redirect)
251+
const connectionKey = searchParams.get(PARAM_KEY_CONNECTION) ?? ''
252+
safeRedirect =
253+
hostname === url.hostname &&
254+
port === url.port &&
255+
['http:', 'https:'].includes(protocol) &&
256+
connectionKey !== '' &&
257+
connectionKey === this.currentConnection
258+
} catch (_e) {
259+
log.error('Invalid URL')
260+
eventService.notify({
261+
type: 'danger',
262+
message: 'Redirect parameter was modified',
263+
})
264+
}
265+
266+
if (!safeRedirect) {
267+
redirect = hawtio.getBasePath() ?? '/'
268+
}
269+
247270
log.debug('Redirect to:', redirect)
248-
window.location.href = redirect
271+
window.location.href = encodeURI(redirect)
249272
}
250273

251274
/**

0 commit comments

Comments
 (0)