Files
LocalAI/core/http/auth/csrf.go
T
Ettore Di Giacinto db929f4a08 test(config): assert every usecase flag is a distinct bit
FLAG_MOTION and FLAG_UPSCALE were both declared as 1 << 26 on separate
branches, and a merge combined the two const blocks without a conflict.
Add a spec that checks every flag from GetAllModelConfigUsecases() is a
single bit that no other flag uses, so a collision fails the tests.

FLAG_MOTION itself moves to 1 << 27.

Assisted-by: Claude Code:claude-sonnet-5-5
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
2026-10-13 08:27:24 +00:00

26 lines
816 B
Go

// SPDX-License-Identifier: MIT
package auth
import (
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
// CSRFMiddleware must run after Middleware so only validated header credentials
// grant an exemption. Cookie authentication must still pass the browser checks.
func CSRFMiddleware() echo.MiddlewareFunc {
return middleware.CSRFWithConfig(middleware.CSRFConfig{
Skipper: func(c echo.Context) bool {
if authenticated, _ := c.Get(contextKeyHeaderAuthenticated).(bool); authenticated {
return true
}
// Preserve support for clients that do not send fetch metadata.
return c.Request().Header.Get("Sec-Fetch-Site") == ""
},
AllowSecFetchSiteFunc: func(c echo.Context) (bool, error) {
return c.Request().Header.Get("Sec-Fetch-Site") == "same-site", nil
},
})
}