form: allow relative redirect_url

EvaluateRelativePath will un-relative-ize a path if it is relative (has
a preceding /) in the same way as app.ExternalURI() roughly. Should fix #414.
This commit is contained in:
Harvey Tindall
2025-07-16 18:47:32 +01:00
parent 7cb66e26e5
commit bcb6346f81
2 changed files with 23 additions and 4 deletions
+19
View File
@@ -47,6 +47,10 @@ func (app *appContext) MustSetURLPath(section, key, val string) {
}
func FixFullURL(v string) string {
// Keep relative paths relative
if strings.HasPrefix(v, "/") {
return v
}
if !strings.HasPrefix(v, "http://") && !strings.HasPrefix(v, "https://") {
v = "http://" + v
}
@@ -98,6 +102,21 @@ func (app *appContext) ExternalURI(gc *gin.Context) string {
return app.externalURI
}
func (app *appContext) EvaluateRelativePath(gc *gin.Context, path string) string {
if !strings.HasPrefix(path, "/") {
return path
}
var proto string
if gc.Request.TLS != nil || gc.Request.Header.Get("X-Forwarded-Proto") == "https" || gc.Request.Header.Get("X-Forwarded-Protocol") == "https" {
proto = "https://"
} else {
proto = "http://"
}
return proto + app.ExternalDomain(gc) + path
}
func (app *appContext) loadConfig() error {
var err error
app.config, err = ini.ShadowLoad(app.configPath)