-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Improve hostname validation #4118
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 |
---|---|---|
|
@@ -9,7 +9,7 @@ import { log } from '@gitpod/gitpod-protocol/lib/util/logging'; | |
import { URL } from 'url'; | ||
import * as express from 'express'; | ||
import * as crypto from 'crypto'; | ||
import { GitpodHostUrl, workspaceIDRegex } from '@gitpod/gitpod-protocol/lib/util/gitpod-host-url'; | ||
import { GitpodHostUrl } from '@gitpod/gitpod-protocol/lib/util/gitpod-host-url'; | ||
|
||
export const pingPong: WsRequestHandler = (ws, req, next) => { | ||
let pingSentTimer: any; | ||
|
@@ -91,7 +91,14 @@ const looksLikeWorkspaceHostname = (originHostname: URL, gitpodHostName: string) | |
return false; | ||
} | ||
const url = new GitpodHostUrl(originHostname); | ||
return workspaceIDRegex.test(url.workspaceId || '') | ||
const workspaceId = url.workspaceId; | ||
if (workspaceId) { | ||
const hostname = url.url.hostname as string; | ||
if (hostname.startsWith(workspaceId)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice if we had one place for the workspace URL parsing. But might be out of scope for this PR, as it was here before, too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
|
||
export function saveSession(reqOrSession: express.Request | Express.Session): Promise<void> { | ||
|
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.
💯