mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
92d328926d
* refactor(handlers): lower case error messages also refactor verifyAuth function to detect malicious activity both with session cookie and authorization header. * refacto(handlers): simplify error construction * fix(handlers): check prefix in authorization header to determine auth method * fix(handlers): determining the method should be done with headers instead of query arg * refacto(handlers): rollback changes of verifyAuth * don't lowercase log messages * Apply suggestions from code review Make sure logger errors are not lowercased. * fix: uppercase logger errors and remove unused param * Do not lowercase logger errors * Remove unused param targetURL * Rename url variable to not conflict with imported package Co-authored-by: Amir Zarrinkafsh <nightah@me.com>
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package handlers
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
|
|
"github.com/authelia/authelia/v4/internal/middlewares"
|
|
"github.com/authelia/authelia/v4/internal/utils"
|
|
)
|
|
|
|
type logoutBody struct {
|
|
TargetURL string `json:"targetURL"`
|
|
}
|
|
|
|
type logoutResponseBody struct {
|
|
SafeTargetURL bool `json:"safeTargetURL"`
|
|
}
|
|
|
|
// LogoutPost is the handler logging out the user attached to the given cookie.
|
|
func LogoutPost(ctx *middlewares.AutheliaCtx) {
|
|
body := logoutBody{}
|
|
responseBody := logoutResponseBody{SafeTargetURL: false}
|
|
|
|
err := ctx.ParseBody(&body)
|
|
if err != nil {
|
|
ctx.Error(fmt.Errorf("unable to parse body during logout: %s", err), messageOperationFailed)
|
|
}
|
|
|
|
err = ctx.Providers.SessionProvider.DestroySession(ctx.RequestCtx)
|
|
if err != nil {
|
|
ctx.Error(fmt.Errorf("unable to destroy session during logout: %s", err), messageOperationFailed)
|
|
}
|
|
|
|
redirectionURL, err := url.Parse(body.TargetURL)
|
|
if err == nil {
|
|
responseBody.SafeTargetURL = utils.IsRedirectionSafe(*redirectionURL, ctx.Configuration.Session.Domain)
|
|
}
|
|
|
|
if body.TargetURL != "" {
|
|
ctx.Logger.Debugf("Logout target url is %s, safe %t", body.TargetURL, responseBody.SafeTargetURL)
|
|
}
|
|
|
|
err = ctx.SetJSONBody(responseBody)
|
|
if err != nil {
|
|
ctx.Error(fmt.Errorf("unable to set body during logout: %s", err), messageOperationFailed)
|
|
}
|
|
}
|