mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
chore: enable exhaustruct linter (#8403)
* chore: enable exhaustruct linter * add exlusion rules * move to allowlist instead * exhaustruct httpmw package * fixup! exhaustruct httpmw package * make lint * address PR comments
This commit is contained in:
@ -390,6 +390,7 @@ func New(options *Options) *API {
|
||||
RedirectToLogin: false,
|
||||
DisableSessionExpiryRefresh: options.DeploymentValues.DisableSessionExpiryRefresh.Value(),
|
||||
Optional: false,
|
||||
SessionTokenFunc: nil, // Default behavior
|
||||
})
|
||||
// Same as above but it redirects to the login page.
|
||||
apiKeyMiddlewareRedirect := httpmw.ExtractAPIKeyMW(httpmw.ExtractAPIKeyConfig{
|
||||
@ -398,6 +399,7 @@ func New(options *Options) *API {
|
||||
RedirectToLogin: true,
|
||||
DisableSessionExpiryRefresh: options.DeploymentValues.DisableSessionExpiryRefresh.Value(),
|
||||
Optional: false,
|
||||
SessionTokenFunc: nil, // Default behavior
|
||||
})
|
||||
// Same as the first but it's optional.
|
||||
apiKeyMiddlewareOptional := httpmw.ExtractAPIKeyMW(httpmw.ExtractAPIKeyConfig{
|
||||
@ -406,6 +408,7 @@ func New(options *Options) *API {
|
||||
RedirectToLogin: false,
|
||||
DisableSessionExpiryRefresh: options.DeploymentValues.DisableSessionExpiryRefresh.Value(),
|
||||
Optional: true,
|
||||
SessionTokenFunc: nil, // Default behavior
|
||||
})
|
||||
|
||||
// API rate limit middleware. The counter is local and not shared between
|
||||
|
@ -20,7 +20,7 @@ type HSTSConfig struct {
|
||||
func HSTSConfigOptions(maxAge int, options []string) (HSTSConfig, error) {
|
||||
if maxAge <= 0 {
|
||||
// No header, so no need to build the header string.
|
||||
return HSTSConfig{}, nil
|
||||
return HSTSConfig{HeaderValue: ""}, nil
|
||||
}
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security
|
||||
|
@ -56,7 +56,10 @@ func ExtractRealIP(config *RealIPConfig) func(next http.Handler) http.Handler {
|
||||
// configuration and headers. It does not mutate the original request.
|
||||
func ExtractRealIPAddress(config *RealIPConfig, req *http.Request) (net.IP, error) {
|
||||
if config == nil {
|
||||
config = &RealIPConfig{}
|
||||
config = &RealIPConfig{
|
||||
TrustedOrigins: nil,
|
||||
TrustedHeaders: nil,
|
||||
}
|
||||
}
|
||||
|
||||
cf := isContainedIn(config.TrustedOrigins, getRemoteAddress(req.RemoteAddr))
|
||||
@ -81,7 +84,10 @@ func ExtractRealIPAddress(config *RealIPConfig, req *http.Request) (net.IP, erro
|
||||
// of each proxy header is set.
|
||||
func FilterUntrustedOriginHeaders(config *RealIPConfig, req *http.Request) {
|
||||
if config == nil {
|
||||
config = &RealIPConfig{}
|
||||
config = &RealIPConfig{
|
||||
TrustedOrigins: nil,
|
||||
TrustedHeaders: nil,
|
||||
}
|
||||
}
|
||||
|
||||
cf := isContainedIn(config.TrustedOrigins, getRemoteAddress(req.RemoteAddr))
|
||||
@ -208,7 +214,10 @@ func RealIP(ctx context.Context) *RealIPState {
|
||||
// ParseRealIPConfig takes a raw string array of headers and origins
|
||||
// to produce a config.
|
||||
func ParseRealIPConfig(headers, origins []string) (*RealIPConfig, error) {
|
||||
config := &RealIPConfig{}
|
||||
config := &RealIPConfig{
|
||||
TrustedOrigins: []*net.IPNet{},
|
||||
TrustedHeaders: []string{},
|
||||
}
|
||||
for _, origin := range origins {
|
||||
_, network, err := net.ParseCIDR(origin)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user