8000 [pull] main from miniflux:main by pull[bot] · Pull Request #366 · suhaoGe/miniflux · GitHub
[go: up one dir, main page]

Skip to content
8000
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/http/response/html_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ func TestHTMLRedirectRejectsUnsafeTargets(t *testing.T) {
"file:///etc/passwd",
"mailto:victim@example.org",
"//evil.example.org/path",
" //evil.example.org/path",
`/\evil.example.org/path`,
` /\evil.example.org/path`,
`\evil.example.org\path`,
`/foo\bar`,
"ftp://example.org/file",
Expand Down
8 changes: 8 additions & 0 deletions internal/urllib/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ func IsRelativePath(link string) bool {
return false
}

// Reject surrounding whitespace: browsers strip leading and trailing C0
// control characters and spaces before parsing a target, while Go's url.Parse
// treats spaces as path characters. Without this check, a target like
// " //evil.com" is accepted here and becomes //evil.com in the browser.
if link != strings.TrimSpace(link) {
return false
}

// Reject backslashes: Go's url.Parse treats them as ordinary path
// characters, but browsers normalize them to forward slashes, so a target
// like "/\evil.com" would parse as relative here yet redirect to
Expand Down
8 changes: 8 additions & 0 deletions internal/urllib/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,21 @@ func TestIsRelativePath(t *testing.T) {
"path?query=value": true,
"path#fragment": true,
"path?query#fragment": true,
"/bookmarklet?uri=https://example.org/rss": true,

// Not relative paths
"https://example.org/file.ext": false,
"http://example.org/file.ext": false,
"//example.org/file.ext": false,
"//example.org": false,
" //example.org": false,
" //example.org/path": false,
"\t//example.org": false,
"\n//example.org": false,
" /path": false,
"/path ": false,
`/\example.org`: false,
` /\example.org`: false,
`\example.org`: false,
`path\to\file.ext`: false,
"ftp://example.org/file.ext": false,
Expand Down
Loading
0