mirror of
https://github.com/allankoechke/pocketbase.git
synced 2026-11-30 10:58:44 +00:00
more strict cors quick subdomain checks to prevent misuse
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
- Updated `modernc.org/sqlite` to 1.59.0 _(minor performance improvement by switching to Go's `memmove` on Linux targets)_.
|
- Updated `modernc.org/sqlite` to 1.59.0 _(minor performance improvement by switching to Go's `memmove` on Linux targets)_.
|
||||||
|
|
||||||
- Other minor fixes (godoc typos, normalized negative jsvm pool size, etc.).
|
- Other minor fixes (godoc typos, normalized negative jsvm pool size, extra CORS wildcard subdomain checks to prevent misuse, etc.).
|
||||||
|
|
||||||
|
|
||||||
## v0.40.4
|
## v0.40.4
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ func CORS(config CORSConfig) *hook.Handler[*core.RequestEvent] {
|
|||||||
allowOrigin = o
|
allowOrigin = o
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if matchSubdomain(origin, o) {
|
if exactWildcardMatch(origin, o) {
|
||||||
allowOrigin = origin
|
allowOrigin = origin
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -283,8 +283,8 @@ func matchScheme(domain, pattern string) bool {
|
|||||||
return didx != -1 && pidx != -1 && domain[:didx] == pattern[:pidx]
|
return didx != -1 && pidx != -1 && domain[:didx] == pattern[:pidx]
|
||||||
}
|
}
|
||||||
|
|
||||||
// matchSubdomain compares authority with wildcard
|
// exactWildcardMatch compares domain with a * wildcard pattern
|
||||||
func matchSubdomain(domain, pattern string) bool {
|
func exactWildcardMatch(domain, pattern string) bool {
|
||||||
if !matchScheme(domain, pattern) {
|
if !matchScheme(domain, pattern) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -312,18 +312,21 @@ func matchSubdomain(domain, pattern string) bool {
|
|||||||
patComp[i], patComp[opp] = patComp[opp], patComp[i]
|
patComp[i], patComp[opp] = patComp[opp], patComp[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(patComp) != len(domComp) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
for i, v := range domComp {
|
for i, v := range domComp {
|
||||||
if len(patComp) <= i {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
p := patComp[i]
|
p := patComp[i]
|
||||||
|
|
||||||
if p == "*" {
|
if p == "*" {
|
||||||
return true
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if p != v {
|
if p != v {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
39
apis/middlewares_cors_test.go
Normal file
39
apis/middlewares_cors_test.go
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package apis
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestCorsExactWildcardMatch(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
scenarios := []struct {
|
||||||
|
domain string
|
||||||
|
pattern string
|
||||||
|
expected bool
|
||||||
|
}{
|
||||||
|
{"", "", false},
|
||||||
|
{"http://example.com", "", false},
|
||||||
|
{"", "http://example.com", false},
|
||||||
|
{"http://example.com", "https://example.com", false},
|
||||||
|
{"abc://example.com", "abc://example.com", true},
|
||||||
|
{"https://example.com", "https://example.com", true},
|
||||||
|
{"https://a.example.com", "https://example.com", false},
|
||||||
|
{"https://example.com", "https://a.example.com", false},
|
||||||
|
{"https://example.com", "https://*.example.com", false},
|
||||||
|
{"https://a.example.com", "https://*.example.com", true},
|
||||||
|
{"https://a.example.com", "https://a.*.example.com", false},
|
||||||
|
{"https://a.b.example.com", "https://a.*.example.com", true},
|
||||||
|
{"https://a.b.example.com", "https://a2.*.example.com", false},
|
||||||
|
{"https://a.b.example.com", "https://a.*", false},
|
||||||
|
{"https://a.b.example", "https://a.*", false},
|
||||||
|
{"https://a.b", "https://a.*", true},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, s := range scenarios {
|
||||||
|
t.Run(s.domain+":"+s.pattern, func(t *testing.T) {
|
||||||
|
result := exactWildcardMatch(s.domain, s.pattern)
|
||||||
|
if result != s.expected {
|
||||||
|
t.Fatalf("Expected %v, got %v", s.expected, result)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
11078
plugins/jsvm/internal/types/generated/types.d.ts
vendored
11078
plugins/jsvm/internal/types/generated/types.d.ts
vendored
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user