Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 62cef36

Browse files
committed
security: Allow hostnames starting with digits in default http.urls
Domains like 1password.com and 37signals.com were blocked by the default allow rule '^https?://[a-z]'. Allow [a-z0-9] for the first hostname char and add an explicit deny for hosts whose first label is all-digit (IP literals like 127.0.0.1) to retain the prior SSRF protections. Fixes #14837
1 parent ff22c62 commit 62cef36

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

config/security/securityConfig.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ var DefaultConfig = Config{
5757
// foil the obvious SSRF bypass. Public IP literals are collateral
5858
// blocks; users who need them can override security.http.urls.
5959
URLs: MustNewWhitelist(
60-
`(?i)^https?://[a-z]`,
60+
`(?i)^https?://[a-z0-9]`,
61+
`! ^https?://\d+\.`,
6162
`! (?i)localhost`,
6263
`! (?i)^https?://[^/?#]*@`,
6364
),

config/security/securityConfig_test.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func TestToTOML(t *testing.T) {
135135
got := DefaultConfig.ToTOML()
136136

137137
c.Assert(got, qt.Equals,
138-
"[security]\n enableInlineShortcodes = false\n\n [security.exec]\n allow = ['^(dart-)?sass(-embedded)?$', '^go$', '^git$', '^node$', '^postcss$', '^tailwindcss$']\n osEnv = ['(?i)^((HTTPS?|NO)_PROXY|PATH(EXT)?|APPDATA|TE?MP|TERM|GO\\w+|(XDG_CONFIG_)?HOME|USERPROFILE|SSH_AUTH_SOCK|DISPLAY|LANG|SYSTEMDRIVE|PROGRAMDATA)$']\n\n [security.funcs]\n getenv = ['^HUGO_', '^CI$']\n\n [security.http]\n methods = ['(?i)GET|POST']\n urls = ['(?i)^https?://[a-z]', '! (?i)localhost', '! (?i)^https?://[^/?#]*@']\n\n [security.node]\n [security.node.permissions]\n allowAddons = ['tailwindcss']\n allowChildProcess = ['tailwindcss']\n allowRead = ['.']\n allowWorker = ['tailwindcss']\n allowWrite = []\n disable = false",
138+
"[security]\n enableInlineShortcodes = false\n\n [security.exec]\n allow = ['^(dart-)?sass(-embedded)?$', '^go$', '^git$', '^node$', '^postcss$', '^tailwindcss$']\n osEnv = ['(?i)^((HTTPS?|NO)_PROXY|PATH(EXT)?|APPDATA|TE?MP|TERM|GO\\w+|(XDG_CONFIG_)?HOME|USERPROFILE|SSH_AUTH_SOCK|DISPLAY|LANG|SYSTEMDRIVE|PROGRAMDATA)$']\n\n [security.funcs]\n getenv = ['^HUGO_', '^CI$']\n\n [security.http]\n methods = ['(?i)GET|POST']\n urls = ['(?i)^https?://[a-z0-9]', '! ^https?://\\d+\\.', '! (?i)localhost', '! (?i)^https?://[^/?#]*@']\n\n [security.node]\n [security.node.permissions]\n allowAddons = ['tailwindcss']\n allowChildProcess = ['tailwindcss']\n allowRead = ['.']\n allowWorker = ['tailwindcss']\n allowWrite = []\n disable = false",
139139
)
140140
}
141141

@@ -273,6 +273,31 @@ func TestCheckAllowedHTTPURLAtInPathIssue14825(t *testing.T) {
273273
}
274274
}
275275

276+
func TestCheckAllowedHTTPURLDigitHostnameIssue14837(t *testing.T) {
277+
t.Parallel()
278+
c := qt.New(t)
279+
280+
pc, err := DecodeConfig(config.New())
281+
c.Assert(err, qt.IsNil)
282+
283+
for _, u := range []string{
284+
"https://1password.com/",
285+
"https://37signals.com/foo",
286+
} {
287+
c.Assert(pc.CheckAllowedHTTPURL(u), qt.IsNil, qt.Commentf(u))
288+
}
289+
290+
for _, u := range []string{
291+
"http://127.0.0.1/",
292+
"http://10.0.0.1/",
293+
"http://192.168.1.1/",
294+
"http://0.0.0.0/",
295+
} {
296+
err := pc.CheckAllowedHTTPURL(u)
297+
c.Assert(err, qt.IsNotNil, qt.Commentf(u))
298+
}
299+
}
300+
276301
func TestDecodeConfigNodePermissions(t *testing.T) {
277302
c := qt.New(t)
278303

0 commit comments

Comments
 (0)