mirror of
https://github.com/coder/coder.git
synced 2026-10-24 01:26:25 +08:00
feat: allow bypassing current CORS magic based on template config (#18706)
Solves https://github.com/coder/coder/issues/15096 This is a slight rework/refactor of the earlier PRs from @dannykopping and @Emyrk: - https://github.com/coder/coder/pull/15669 - https://github.com/coder/coder/pull/15684 - https://github.com/coder/coder/pull/17596 Rather than having a per-app CORS behaviour setting and additionally a template level setting for ports, this PR adds a single template level CORS behaviour setting that is then used by all apps/ports for workspaces created from that template. The main changes are in `proxy.go` and `request.go` to: a) get the CORS behaviour setting from the template b) have `HandleSubdomain` bypass the CORS middleware handler if the selected behaviour is `passthru` c) in `proxyWorkspaceApp`, do not modify the response if the selected behaviour is `passthru` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added support for configuring CORS behavior ("simple" or "passthru") at the template level for all shared ports. * Introduced a new "CORS Behavior" setting in the template creation and settings forms. * API endpoints and responses now include the optional `cors_behavior` property for templates. * Workspace apps and proxy now honor the specified CORS behavior, enabling conditional CORS middleware application. * Enhanced workspace app tests with comprehensive scenarios covering CORS behaviors and authentication states. * **Bug Fixes** * None. * **Documentation** * Updated API and admin documentation to describe the new `cors_behavior` property and its usage. * Added examples and schema references for CORS behavior in relevant API docs. * **Tests** * Extended automated tests to cover different CORS behavior scenarios for templates and workspace apps. * **Chores** * Updated audit logging to track changes to the `cors_behavior` field on templates. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Callum Styan <callumstyan@gmail.com>
This commit is contained in:
Generated
+8
@@ -307,6 +307,11 @@ export const BypassRatelimitHeader = "X-Coder-Bypass-Ratelimit";
|
||||
// From codersdk/client.go
|
||||
export const CLITelemetryHeader = "Coder-CLI-Telemetry";
|
||||
|
||||
// From codersdk/cors_behavior.go
|
||||
export type CORSBehavior = "passthru" | "simple";
|
||||
|
||||
export const CORSBehaviors: CORSBehavior[] = ["passthru", "simple"];
|
||||
|
||||
// From codersdk/workspacebuilds.go
|
||||
export interface CancelWorkspaceBuildParams {
|
||||
readonly expect_status?: CancelWorkspaceBuildStatus;
|
||||
@@ -492,6 +497,7 @@ export interface CreateTemplateRequest {
|
||||
readonly require_active_version: boolean;
|
||||
readonly max_port_share_level: WorkspaceAgentPortShareLevel | null;
|
||||
readonly template_use_classic_parameter_flow?: boolean;
|
||||
readonly cors_behavior: CORSBehavior | null;
|
||||
}
|
||||
|
||||
// From codersdk/templateversions.go
|
||||
@@ -2816,6 +2822,7 @@ export interface Template {
|
||||
readonly time_til_dormant_autodelete_ms: number;
|
||||
readonly require_active_version: boolean;
|
||||
readonly max_port_share_level: WorkspaceAgentPortShareLevel;
|
||||
readonly cors_behavior: CORSBehavior;
|
||||
readonly use_classic_parameter_flow: boolean;
|
||||
}
|
||||
|
||||
@@ -3188,6 +3195,7 @@ export interface UpdateTemplateMeta {
|
||||
readonly deprecation_message?: string;
|
||||
readonly disable_everyone_group_access: boolean;
|
||||
readonly max_port_share_level?: WorkspaceAgentPortShareLevel;
|
||||
readonly cors_behavior?: CORSBehavior;
|
||||
readonly use_classic_parameter_flow?: boolean;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user