fix cookie -- not working

This commit is contained in:
2026-05-12 11:25:32 +02:00
parent 669d24c6a3
commit 8c4e664ca8
23 changed files with 836 additions and 166 deletions
+15 -4
View File
@@ -140,15 +140,15 @@ func (c Config) DeriveCookieName(host string) string {
return c.PrestaShopCookieName
}
domain := normalizedCookieDomain(host)
domain := fallbackCookieHashDomain(host)
if domain == "" {
domain = normalizedCookieDomain(c.PrestaShopBaseURL)
domain = fallbackCookieHashDomain(c.PrestaShopBaseURL)
}
if domain == "" {
domain = normalizedCookieDomain(c.PrestaShopProxyTarget)
domain = fallbackCookieHashDomain(c.PrestaShopProxyTarget)
}
sum := md5.Sum([]byte(c.PrestaShopVersion + "PrestaShop" + domain))
sum := md5.Sum([]byte(c.PrestaShopVersion + "ps-s1" + domain))
return fmt.Sprintf("PrestaShop-%x", sum)
}
@@ -256,6 +256,17 @@ func normalizedCookieDomain(input string) string {
return value
}
func fallbackCookieHashDomain(input string) string {
value := normalizedCookieDomain(input)
if value == "" {
return ""
}
if net.ParseIP(value) != nil || !strings.Contains(value, ".") {
return ""
}
return value
}
func dbDSNFromEnv() string {
return mysqlDSN(
firstNonEmpty(os.Getenv("PRESTASHOP_DB_HOST"), os.Getenv("DB_HOST")),
+19
View File
@@ -0,0 +1,19 @@
package config
import (
"crypto/md5"
"fmt"
"testing"
)
func TestDeriveCookieNameMatchesFallbackPrestashopRule(t *testing.T) {
cfg := Config{PrestaShopVersion: "1.7.3"}
got := cfg.DeriveCookieName("localhost")
sum := md5.Sum([]byte("1.7.3" + "ps-s1"))
want := fmt.Sprintf("PrestaShop-%x", sum)
if got != want {
t.Fatalf("DeriveCookieName() = %q, want %q", got, want)
}
}