Skip to content

armgit / ente

Public Imported from GitHub
0

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

Keep loopback origin checks consistent

Manav Rathifa7b4abb1443
diff --git a/docs/docs/self-hosting/installation/config.md b/docs/docs/self-hosting/installation/config.md
index 59efa0fa82..86c6947507 100644
--- a/docs/docs/self-hosting/installation/config.md
+++ b/docs/docs/self-hosting/installation/config.md
@@ -70,7 +70,7 @@ The `apps` section tells Museum where each Ente web app is hosted. Configure the
| `apps.family` | Family web app base endpoint | `https://family.ente.io` |
| `apps.space` | Space web app base endpoint | `https://ente.space` |
| `apps.legacy` | Legacy recovery web app base endpoint | `https://legacy.ente.com` |
-| `apps.extra-origins` | Additional trusted browser origins | `["https://embed.ente.io"]` |
+| `apps.extra-origins` | Additional trusted browser origins | `["https://ente.com", "https://embed.ente.io"]` |
### Database
diff --git a/server/cmd/museum/main.go b/server/cmd/museum/main.go
index af3b3e00cf..fe349f9ddb 100644
--- a/server/cmd/museum/main.go
+++ b/server/cmd/museum/main.go
@@ -5,7 +5,6 @@ import (
"database/sql"
b64 "encoding/base64"
"fmt"
- "net"
"net/http"
"net/url"
"os"
@@ -74,6 +73,7 @@ import (
userEntityRepo "github.com/ente/museum/pkg/repo/userentity"
"github.com/ente/museum/pkg/utils/billing"
"github.com/ente/museum/pkg/utils/config"
+ "github.com/ente/museum/pkg/utils/network"
"github.com/ente/museum/pkg/utils/s3config"
timeUtil "github.com/ente/museum/pkg/utils/time"
spaceapi "github.com/ente/museum/space/api"
@@ -1427,15 +1427,7 @@ func corsForOrigins(origins []string) gin.HandlerFunc {
}
}
isKnownOrigin := func(c *gin.Context, origin string) bool {
- 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()) {
+ if origin == "" || knownOrigins[normalizeOrigin(origin)] || network.IsLoopbackOrigin(origin) {
return true
}
// CollectionLinkMiddleware validates custom album domains.
diff --git a/server/pkg/middleware/collection_link.go b/server/pkg/middleware/collection_link.go
index eb4e177be8..5ec2621350 100644
--- a/server/pkg/middleware/collection_link.go
+++ b/server/pkg/middleware/collection_link.go
@@ -299,7 +299,7 @@ func (m *CollectionLinkMiddleware) validateOrigin(c *gin.Context, ownerID int64)
// origin to embed.ente.com. Custom embed origins should not inherit this.
(embedAlbumsOrigin == "https://embed.ente.com" && origin == "https://embed.ente.io") ||
origin == viper.GetString("apps.public-locker") ||
- strings.HasPrefix(strings.ToLower(origin), "http://localhost:") {
+ network.IsLoopbackOrigin(origin) {
return nil
}
reqId := requestid.Get(c)
diff --git a/server/pkg/utils/network/origin.go b/server/pkg/utils/network/origin.go
new file mode 100644
index 0000000000..1afcd036c2
--- /dev/null
+++ b/server/pkg/utils/network/origin.go
@@ -0,0 +1,17 @@
+package network
+
+import (
+ "net"
+ "net/url"
+ "strings"
+)
+
+func IsLoopbackOrigin(origin string) bool {
+ parsed, err := url.Parse(strings.TrimSpace(origin))
+ if err != nil || !strings.EqualFold(parsed.Scheme, "http") && !strings.EqualFold(parsed.Scheme, "https") {
+ return false
+ }
+ host := strings.ToLower(strings.TrimSuffix(parsed.Hostname(), "."))
+ ip := net.ParseIP(host)
+ return host == "localhost" || strings.HasSuffix(host, ".localhost") || ip != nil && ip.IsLoopback()
+}