Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf1da2f1

Browse files
committed
Add url validation
1 parent8613b13 commitf1da2f1

File tree

7 files changed

+67
-11
lines changed

7 files changed

+67
-11
lines changed

‎coderd/database/dump.sql

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/migrations/000111_workspace_proxy.up.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ CREATE TABLE workspace_proxies (
33
id uuidNOT NULL,
44
organization_id uuidNOT NULL,
55
nametextNOT NULL,
6+
display_nametextNOT NULL,
67
icontextNOT NULL,
78
urltextNOT NULL,
89
wildcard_urltextNOT NULL,

‎coderd/database/models.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries.sql.go

Lines changed: 20 additions & 9 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries/proxies.sql

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@ INSERT INTO
44
id,
55
organization_id,
66
name,
7+
display_name,
78
icon,
89
url,
910
wildcard_url,
1011
created_at,
11-
updated_at
12+
updated_at,
13+
deleted
1214
)
1315
VALUES
14-
($1, $2, $3, $4, $5, $6, $7, $8) RETURNING*;
16+
($1, $2, $3, $4, $5, $6, $7, $8, $9, false) RETURNING*;
1517

1618
-- name: UpdateWorkspaceProxy :one
1719
UPDATE
1820
workspace_proxies
1921
SET
2022
name= @name,
23+
display_name= @display_name,
2124
url= @url,
2225
wildcard_url= @wildcard_url,
2326
icon= @icon,

‎codersdk/workspaceproxy.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
typeCreateWorkspaceProxyRequeststruct {
1616
Namestring`json:"name"`
17+
DisplayNamestring`json:"display_name"`
1718
Iconstring`json:"icon"`
1819
URLstring`json:"url"`
1920
WildcardURLstring`json:"wildcard_url"`

‎enterprise/coderd/workspaceproxy.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"database/sql"
55
"fmt"
66
"net/http"
7+
"net/url"
8+
"strings"
79

810
"golang.org/x/xerrors"
911

@@ -44,10 +46,27 @@ func (api *API) postWorkspaceProxyByOrganization(rw http.ResponseWriter, r *http
4446
return
4547
}
4648

49+
iferr:=validateProxyURL(req.URL,false);err!=nil {
50+
httpapi.Write(ctx,rw,http.StatusBadRequest, codersdk.Response{
51+
Message:"URL is invalid.",
52+
Detail:err.Error(),
53+
})
54+
return
55+
}
56+
57+
iferr:=validateProxyURL(req.WildcardURL,true);err!=nil {
58+
httpapi.Write(ctx,rw,http.StatusBadRequest, codersdk.Response{
59+
Message:"Wildcard URL is invalid.",
60+
Detail:err.Error(),
61+
})
62+
return
63+
}
64+
4765
proxy,err:=api.Database.InsertWorkspaceProxy(ctx, database.InsertWorkspaceProxyParams{
4866
ID:uuid.New(),
4967
OrganizationID:org.ID,
5068
Name:req.Name,
69+
DisplayName:req.DisplayName,
5170
Icon:req.Icon,
5271
// TODO: validate URLs
5372
Url:req.URL,
@@ -70,6 +89,25 @@ func (api *API) postWorkspaceProxyByOrganization(rw http.ResponseWriter, r *http
7089
httpapi.Write(ctx,rw,http.StatusCreated,convertProxy(proxy))
7190
}
7291

92+
funcvalidateProxyURL(ustring,wildcardbool)error {
93+
p,err:=url.Parse(u)
94+
iferr!=nil {
95+
returnerr
96+
}
97+
ifp.Scheme!="http"&&p.Scheme!="https" {
98+
returnxerrors.New("scheme must be http or https")
99+
}
100+
if!(p.Path=="/"||p.Path=="") {
101+
returnxerrors.New("path must be empty or /")
102+
}
103+
ifwildcard {
104+
if!strings.HasPrefix(p.Host,"*.") {
105+
returnxerrors.Errorf("wildcard URL must have a wildcard subdomain (e.g. *.example.com)")
106+
}
107+
}
108+
returnnil
109+
}
110+
73111
// @Summary Get workspace proxies
74112
// @ID get-workspace-proxies
75113
// @Security CoderSessionToken

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp