🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

Commit d547bea

Browse files
github-actions[bot]geokatBobbyHo
authored
fix(coderd): reject workspace proxy hostname prefixes (#27544) (#27616)
Backport of #27544 Original PR: #27544 — fix(coderd): reject workspace proxy hostname prefixes Merge commit: 8cc7f2b Requested by: @geokat Co-authored-by: George K <george@coder.com> Co-authored-by: Bobby Ho <bobbidinho@gmail.com>
1 parent b7d2742 commit d547bea

4 files changed

Lines changed: 63 additions & 2 deletions

File tree

coderd/database/querier_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,6 +1841,16 @@ func TestProxyByHostname(t *testing.T) {
18411841
accessURL: "https://two.coder.com",
18421842
wildcardHostname: "*--suffix.two.coder.com",
18431843
},
1844+
{
1845+
name: "three",
1846+
accessURL: "https://three.coder.com:8443",
1847+
wildcardHostname: "*.wildcard.three.coder.com",
1848+
},
1849+
{
1850+
name: "four",
1851+
accessURL: "https://four.coder.com/",
1852+
wildcardHostname: "*.wildcard.four.coder.com",
1853+
},
18441854
}
18451855
for _, p := range proxies {
18461856
dbgen.WorkspaceProxy(t, db, database.WorkspaceProxy{
@@ -1871,20 +1881,62 @@ func TestProxyByHostname(t *testing.T) {
18711881
allowWildcardHost: true,
18721882
matchProxyName: "one",
18731883
},
1884+
{
1885+
name: "MatchAccessURLWithPort",
1886+
testHostname: "three.coder.com",
1887+
allowAccessURL: true,
1888+
allowWildcardHost: false,
1889+
matchProxyName: "three",
1890+
},
1891+
{
1892+
name: "MatchAccessURLWithTrailingSlash",
1893+
testHostname: "four.coder.com",
1894+
allowAccessURL: true,
1895+
allowWildcardHost: false,
1896+
matchProxyName: "four",
1897+
},
1898+
{
1899+
name: "RejectAccessURLPrefix",
1900+
testHostname: "one.coder",
1901+
allowAccessURL: true,
1902+
allowWildcardHost: false,
1903+
matchProxyName: "",
1904+
},
1905+
{
1906+
name: "RejectAccessURLTLDPrefix",
1907+
testHostname: "one.coder.co",
1908+
allowAccessURL: true,
1909+
allowWildcardHost: false,
1910+
matchProxyName: "",
1911+
},
18741912
{
18751913
name: "MatchWildcard",
18761914
testHostname: "something.wildcard.one.coder.com",
18771915
allowAccessURL: true,
18781916
allowWildcardHost: true,
18791917
matchProxyName: "one",
18801918
},
1919+
{
1920+
name: "RejectWildcardHostnamePrefix",
1921+
testHostname: "something.wildcard.one.coder",
1922+
allowAccessURL: false,
1923+
allowWildcardHost: true,
1924+
matchProxyName: "",
1925+
},
18811926
{
18821927
name: "MatchSuffix",
18831928
testHostname: "something--suffix.two.coder.com",
18841929
allowAccessURL: true,
18851930
allowWildcardHost: true,
18861931
matchProxyName: "two",
18871932
},
1933+
{
1934+
name: "RejectSuffixHostnamePrefix",
1935+
testHostname: "something--suffix.two.coder",
1936+
allowAccessURL: false,
1937+
allowWildcardHost: true,
1938+
matchProxyName: "",
1939+
},
18881940
{
18891941
name: "ValidateHostname/1",
18901942
testHostname: ".*ne.coder.com",

coderd/database/queries.sql.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/proxies.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ WHERE
120120
(
121121
(
122122
@allow_access_url :: bool = true AND
123-
url SIMILAR TO '[^:]*://' || @hostname :: text || '([:/]?%)*'
123+
url SIMILAR TO '[^:]*://' || @hostname :: text || '([:/]%)*'
124124
) OR
125125
(
126126
@allow_wildcard_hostname :: bool = true AND

coderd/workspaceapps_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ func TestWorkspaceApplicationAuth(t *testing.T) {
115115
redirectURI: "https://proxy.test.coder.com/path",
116116
expectRedirect: "https://proxy.test.coder.com/path",
117117
},
118+
{
119+
name: "RejectProxyAccessURLPrefix",
120+
accessURL: "https://test.coder.com",
121+
appHostname: "*.test.coder.com",
122+
proxyURL: "https://proxy.test.coder.com",
123+
proxyAppHostname: "*.proxy.test.coder.com",
124+
redirectURI: "https://proxy.test.coder/path",
125+
expectRedirect: "",
126+
},
118127
{
119128
name: "ProxySubdomainOK",
120129
accessURL: "https://test.coder.com",

0 commit comments

Comments
 (0)