Skip to content

Commit

Permalink
fix(middleware/csrf): lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sixcolors committed Mar 9, 2024
1 parent d80cf53 commit 3934f1d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions middleware/csrf/csrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func New(config ...Config) fiber.Handler {
err := originMatchesHost(c, cfg.TrustedOrigins)

// If there's no origin, enforce a referer check for HTTPS connections.
if err == errNoOrigin {
if errors.Is(err, errNoOrigin) {
if c.Scheme() == "https" {
err = refererMatchesHost(c, cfg.TrustedOrigins)
} else {
Expand Down Expand Up @@ -260,7 +260,7 @@ func isFromCookie(extractor any) bool {
// originMatchesHost checks that the origin header matches the host header
// returns an error if the origin header is not present or is invalid
// returns nil if the origin header is valid
func originMatchesHost(c fiber.Ctx, TrustedOrigins []string) error {
func originMatchesHost(c fiber.Ctx, trustedOrigins []string) error {
origin := c.Get(fiber.HeaderOrigin)
if origin == "" {
return errNoOrigin
Expand All @@ -272,7 +272,7 @@ func originMatchesHost(c fiber.Ctx, TrustedOrigins []string) error {
}

if originURL.Host != c.Host() {
for _, trustedOrigin := range TrustedOrigins {
for _, trustedOrigin := range trustedOrigins {
if isSameSchemeAndDomain(trustedOrigin, origin) {
return nil
}
Expand All @@ -286,7 +286,7 @@ func originMatchesHost(c fiber.Ctx, TrustedOrigins []string) error {
// refererMatchesHost checks that the referer header matches the host header
// returns an error if the referer header is not present or is invalid
// returns nil if the referer header is valid
func refererMatchesHost(c fiber.Ctx, TrustedOrigins []string) error {
func refererMatchesHost(c fiber.Ctx, trustedOrigins []string) error {
referer := c.Get(fiber.HeaderReferer)
if referer == "" {
return ErrNoReferer
Expand All @@ -298,7 +298,7 @@ func refererMatchesHost(c fiber.Ctx, TrustedOrigins []string) error {
}

if refererURL.Host != c.Host() {
for _, trustedOrigin := range TrustedOrigins {
for _, trustedOrigin := range trustedOrigins {
if isSameSchemeAndDomain(trustedOrigin, referer) {
return nil
}
Expand Down

0 comments on commit 3934f1d

Please sign in to comment.