drone/app/router/secure.go

46 lines
1.7 KiB
Go

// Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package router
import (
"github.com/harness/gitness/types"
"github.com/unrolled/secure"
)
// NewSecure returns a new secure.Secure middleware to enforce security best practices
// for the user interface (not meant APIs).
func NewSecure(config *types.Config) *secure.Secure {
return secure.New(
secure.Options{
AllowedHosts: config.Secure.AllowedHosts,
HostsProxyHeaders: config.Secure.HostsProxyHeaders,
SSLRedirect: config.Secure.SSLRedirect,
SSLTemporaryRedirect: config.Secure.SSLTemporaryRedirect,
SSLHost: config.Secure.SSLHost,
SSLProxyHeaders: config.Secure.SSLProxyHeaders,
STSSeconds: config.Secure.STSSeconds,
STSIncludeSubdomains: config.Secure.STSIncludeSubdomains,
STSPreload: config.Secure.STSPreload,
ForceSTSHeader: config.Secure.ForceSTSHeader,
FrameDeny: config.Secure.FrameDeny,
ContentTypeNosniff: config.Secure.ContentTypeNosniff,
BrowserXssFilter: config.Secure.BrowserXSSFilter,
ContentSecurityPolicy: config.Secure.ContentSecurityPolicy,
ReferrerPolicy: config.Secure.ReferrerPolicy,
},
)
}