Files
gotosocial/vendor/github.com/go-openapi/runtime/middleware/context_skipauth_enabled.go
T
kim 06c10bba83 [chore] update dependencies (#4848)
- ~~github.com/go-swagger/go-swagger: v0.33.2 -> v0.34.0~~ ignoring for now
- github.com/jackc/pgx/v5: v5.9.2 -> v5.10.0
- github.com/minio/minio-go/v7: v7.1.0 -> v7.2.0
- github.com/mitchellh/mapstructure: v1.5.0 -> v1.5.0
- github.com/ncruces/go-sqlite3: v0.34.2 -> v0.34.4
- github.com/tetratelabs/wazero: v1.11.0 -> v1.12.0
- go.opentelemetry.io/contrib/exporters/autoexport: v0.68.0 -> v0.69.0
- go.opentelemetry.io/contrib/instrumentation/runtime: v0.68.0 -> v0.69.0
- golang.org/x/image: v0.40.0 -> v0.41.0
- codeberg.org/gruf/go-ffmpreg: v0.6.19 -> v0.6.20

Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4848
2026-06-05 00:31:09 +02:00

62 lines
2.3 KiB
Go

// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
// SPDX-License-Identifier: Apache-2.0
//go:build openapi_unsafe_skipauth
package middleware
import (
"log"
"net/http"
"sync/atomic"
)
// skipAuthEnabled holds the process-wide skip-auth flag. It only
// exists in binaries built with the `openapi_unsafe_skipauth` tag —
// production binaries (built without the tag) have no field, no
// setter, no storage, and no skip-checking branch in [Context.Authorize].
// Reflection, unsafe-pointer arithmetic, or a debugger cannot flip
// what is not in the binary.
var skipAuthEnabled atomic.Bool
// SetSkipAuth toggles a PROCESS-WIDE bypass of authentication AND
// authorization for every operation served by every Context in the
// running program.
//
// DANGER: this disables ALL authentication and ALL authorization.
// Every request to every secured endpoint runs as if it had been
// authorized with a nil principal. Use ONLY on developer
// workstations during early prototyping (e.g. while
// authentication is not yet wired up).
//
// This function exists only when the build tag
// `openapi_unsafe_skipauth` is set:
//
// go build -tags openapi_unsafe_skipauth ./...
//
// Production CI MUST NOT pass this tag. Calls compile to a symbol
// that does not exist in production binaries.
//
// Calling with true emits a one-line WARNING via the stdlib `log`
// package (stderr by default) so the bypass is visible at startup.
// Calling with false silently disables it.
func SetSkipAuth(skip bool) {
skipAuthEnabled.Store(skip)
if skip {
log.Println("WARNING: go-openapi/runtime: SetSkipAuth(true) — authentication and authorization are bypassed for ALL operations. This MUST NOT run in production.")
}
}
// Authorize is the dev-build variant of the production
// [Context.Authorize] (see context_skipauth_disabled.go for the
// production path). When [SetSkipAuth] has enabled the bypass, this
// returns a nil principal with the original request and no error —
// handlers downstream receive a nil-value principal. Otherwise it
// delegates to the standard authentication+authorization body.
func (c *Context) Authorize(request *http.Request, route *MatchedRoute) (any, *http.Request, error) {
if skipAuthEnabled.Load() {
return nil, request, nil
}
return c.authorizeImpl(request, route)
}