Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds TrustedOriginPredicateFunc option, tests #1

Merged
merged 3 commits into from
Aug 14, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add TrustedOriginPredicateFunc method to options
  • Loading branch information
cody-dot-js committed Aug 14, 2024
commit 3e92a5ddfeee518f6a73076f6ec18001981a2dbb
15 changes: 15 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
@@ -131,6 +131,21 @@ func TrustedOrigins(origins []string) Option {
}
}

// TrustedOriginPredicateFunc configures a predicate function that can be used
// to determine if a given Referer is trusted.
// Like TrustedOrigins, this will allow cross-domain CSRF use-cases - e.g. where
// the front-end is served from a different domain than the API server - to
// correctly pass a CSRF check.
// However, this function allows for more complex logic to be applied to determine
// if a Referer is trusted than strict equality string matching.
//
// You should only pass origins you own or have full control over.
func TrustedOriginPredicateFunc(f func(referer string) bool) Option {
return func(cs *csrf) {
cs.opts.TrustedOriginPredicateFunc = f
}
}

// setStore sets the store used by the CSRF middleware.
// Note: this is private (for now) to allow for internal API changes.
func setStore(s store) Option {