mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[bugfix] Convert IDNs to punycode before using as session name (#458)
* convert hostname to punycode for session name * test punycode
This commit is contained in:
@@ -31,6 +31,7 @@ import (
|
||||
"github.com/spf13/viper"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"golang.org/x/net/idna"
|
||||
)
|
||||
|
||||
// SessionOptions returns the standard set of options to use for each session.
|
||||
@@ -61,7 +62,14 @@ func SessionName() (string, error) {
|
||||
return "", fmt.Errorf("could not derive hostname without port from %s://%s", protocol, host)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("gotosocial-%s", strippedHostname), nil
|
||||
// make sure IDNs are converted to punycode or the cookie library breaks:
|
||||
// see https://en.wikipedia.org/wiki/Punycode
|
||||
punyHostname, err := idna.New().ToASCII(strippedHostname)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("could not convert %s to punycode: %s", strippedHostname, err)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("gotosocial-%s", punyHostname), nil
|
||||
}
|
||||
|
||||
func useSession(ctx context.Context, sessionDB db.Session, engine *gin.Engine) error {
|
||||
|
Reference in New Issue
Block a user