mirror of
https://github.com/coder/code-server.git
synced 2026-04-13 11:38:50 -05:00
Add skip-auth-preflight flag to allow OPTIONS requests through proxy (#7284)
This commit is contained in:
@@ -84,6 +84,7 @@ export interface UserProvidedArgs extends UserProvidedCodeArgs {
|
||||
"trusted-origins"?: string[]
|
||||
version?: boolean
|
||||
"proxy-domain"?: string[]
|
||||
"skip-auth-preflight"?: boolean
|
||||
"reuse-window"?: boolean
|
||||
"new-window"?: boolean
|
||||
"ignore-last-opened"?: boolean
|
||||
@@ -252,6 +253,10 @@ export const options: Options<Required<UserProvidedArgs>> = {
|
||||
description: "GitHub authentication token (can only be passed in via $GITHUB_TOKEN or the config file).",
|
||||
},
|
||||
"proxy-domain": { type: "string[]", description: "Domain used for proxying ports." },
|
||||
"skip-auth-preflight": {
|
||||
type: "boolean",
|
||||
description: "Allows preflight requests through proxy without authentication.",
|
||||
},
|
||||
"ignore-last-opened": {
|
||||
type: "boolean",
|
||||
short: "e",
|
||||
|
||||
@@ -163,6 +163,9 @@ export const runCodeServer = async (
|
||||
logger.info(` - ${plural(args["proxy-domain"].length, "Proxying the following domain")}:`)
|
||||
args["proxy-domain"].forEach((domain) => logger.info(` - ${domain}`))
|
||||
}
|
||||
if (args["skip-auth-preflight"]) {
|
||||
logger.info(" - Skipping authentication for preflight requests")
|
||||
}
|
||||
if (process.env.VSCODE_PROXY_URI) {
|
||||
logger.info(`Using proxy URI in PORTS tab: ${process.env.VSCODE_PROXY_URI}`)
|
||||
}
|
||||
|
||||
@@ -61,6 +61,11 @@ router.all(/.*/, async (req, res, next) => {
|
||||
|
||||
ensureProxyEnabled(req)
|
||||
|
||||
if (req.method === "OPTIONS" && req.args["skip-auth-preflight"]) {
|
||||
// Allow preflight requests with `skip-auth-preflight` flag
|
||||
return next()
|
||||
}
|
||||
|
||||
// Must be authenticated to use the proxy.
|
||||
const isAuthenticated = await authenticated(req)
|
||||
if (!isAuthenticated) {
|
||||
|
||||
@@ -26,7 +26,9 @@ export async function proxy(
|
||||
): Promise<void> {
|
||||
ensureProxyEnabled(req)
|
||||
|
||||
if (!(await authenticated(req))) {
|
||||
if (req.method === "OPTIONS" && req.args["skip-auth-preflight"]) {
|
||||
// Allow preflight requests with `skip-auth-preflight` flag
|
||||
} else if (!(await authenticated(req))) {
|
||||
// If visiting the root (/:port only) redirect to the login page.
|
||||
if (!req.params.path || req.params.path === "/") {
|
||||
const to = self(req)
|
||||
|
||||
Reference in New Issue
Block a user