Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Allow website and local development origins

Manav Rathi6dd0c113a776
diff --git a/server/cmd/museum/main.go b/server/cmd/museum/main.go
index ac4665b40b..af3b3e00cf 100644
--- a/server/cmd/museum/main.go
+++ b/server/cmd/museum/main.go
@@ -5,6 +5,7 @@ import (
"database/sql"
b64 "encoding/base64"
"fmt"
+ "net"
"net/http"
"net/url"
"os"
@@ -1091,7 +1092,7 @@ func setAppDefaults() {
viper.SetDefault("apps.photos", "https://photos.ente.com")
viper.SetDefault("apps.public-albums", "https://albums.ente.com")
viper.SetDefault("apps.embed-albums", "https://embed.ente.com")
- viper.SetDefault("apps.extra-origins", []string{"https://embed.ente.io"})
+ viper.SetDefault("apps.extra-origins", []string{"https://ente.com", "https://embed.ente.io"})
viper.SetDefault("apps.auth", "https://auth.ente.com")
viper.SetDefault("apps.locker", "https://locker.ente.com")
viper.SetDefault("apps.public-locker", "https://share.ente.com")
@@ -1426,7 +1427,15 @@ func corsForOrigins(origins []string) gin.HandlerFunc {
}
}
isKnownOrigin := func(c *gin.Context, origin string) bool {
- if origin == "" || knownOrigins[normalizeOrigin(origin)] {
+ normalizedOrigin := normalizeOrigin(origin)
+ if origin == "" || knownOrigins[normalizedOrigin] {
+ return true
+ }
+ parsedOrigin, _ := url.Parse(normalizedOrigin)
+ host := strings.TrimSuffix(parsedOrigin.Hostname(), ".")
+ ip := net.ParseIP(host)
+ if (parsedOrigin.Scheme == "http" || parsedOrigin.Scheme == "https") &&
+ (host == "localhost" || strings.HasSuffix(host, ".localhost") || ip != nil && ip.IsLoopback()) {
return true
}
// CollectionLinkMiddleware validates custom album domains.
diff --git a/server/cmd/museum/main_cors_test.go b/server/cmd/museum/main_cors_test.go
index c1741ab01d..5a48043012 100644
--- a/server/cmd/museum/main_cors_test.go
+++ b/server/cmd/museum/main_cors_test.go
@@ -30,6 +30,14 @@ func TestCORS(t *testing.T) {
{"native client", http.MethodGet, "/users/details", "", "api.ente.com", http.StatusNoContent, true, false},
{"unconfigured same host", http.MethodPost, "/users/ott", "https://ente.example", "ente.example", http.StatusNoContent, true, true},
{"desktop app", http.MethodGet, "/users/details", "ente://app", "api.ente.com", http.StatusNoContent, true, false},
+ {"localhost", http.MethodGet, "/users/details", "http://localhost:3000", "api.ente.com", http.StatusNoContent, true, false},
+ {"localhost subdomain", http.MethodGet, "/users/details", "https://photos.localhost:3000", "api.ente.com", http.StatusNoContent, true, false},
+ {"IPv4 loopback", http.MethodGet, "/users/details", "http://127.1.2.3:3000", "api.ente.com", http.StatusNoContent, true, false},
+ {"IPv6 loopback", http.MethodGet, "/users/details", "http://[::1]:3000", "api.ente.com", http.StatusNoContent, true, false},
+ {"opaque origin", http.MethodGet, "/users/details", "null", "api.ente.com", http.StatusNoContent, true, true},
+ {"private address", http.MethodGet, "/users/details", "http://192.168.1.2:3000", "api.ente.com", http.StatusNoContent, true, true},
+ {"localhost lookalike", http.MethodGet, "/users/details", "http://localhost.example:3000", "api.ente.com", http.StatusNoContent, true, true},
+ {"non-HTTP loopback", http.MethodGet, "/users/details", "ftp://localhost", "api.ente.com", http.StatusNoContent, true, true},
{"custom album domain", http.MethodGet, "/public-collection/info", "https://gallery.example", "api.ente.com", http.StatusNoContent, true, false},
{"album prefix lookalike", http.MethodGet, "/public-collection-evil", "https://gallery.example", "api.ente.com", http.StatusNoContent, true, true},
{"unknown preflight", http.MethodOptions, "/users/details", "https://unknown.example", "api.ente.com", http.StatusOK, false, false},
@@ -97,6 +105,7 @@ func TestCORSProductionOriginsAreDefaults(t *testing.T) {
"https://photos.ente.com",
"https://albums.ente.com",
"https://embed.ente.com",
+ "https://ente.com",
"https://embed.ente.io",
"https://auth.ente.com",
"https://locker.ente.com",
diff --git a/server/configurations/local.yaml b/server/configurations/local.yaml
index 7a3762a706..69bd697a48 100644
--- a/server/configurations/local.yaml
+++ b/server/configurations/local.yaml
@@ -148,6 +148,7 @@ apps:
# Additional trusted browser origins not represented by an app above.
#
# Default is:
+ # - https://ente.com
# - https://embed.ente.io
extra-origins:
custom-domain: