ginsrv

package
v0.19.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 15, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package ginsrv holds the handful of Gin-server building blocks that are byte-for-byte identical between the api package (the framework-level server) and pkg/htpx (a parallel, independently-versioned fork retained for backward compatibility -- see pkg/htpx/VENDORED.md for the fork policy). Extracting exactly these pieces keeps the two call sites in lockstep without merging the packages: everything else the fork does differently is deliberate, and pkg/htpx/server_parity_test.go pins that the hardening options both packages DO share stay in sync going forward.

This package lives under internal/ (module root), not pkg/internal/, specifically so both api/ and pkg/htpx/ -- siblings outside pkg/'s own internal-visibility boundary -- can import it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildArgs

func BuildArgs(app string) cli.Args

BuildArgs returns the standard set of CLI flags a binary embedding one of these servers typically exposes (host, port, TLS cert/key/CA, OIDC issuer/audience, CORS origins, trusted proxies, rate limit/duration). app names the binary in the host flag's generated description text.

Callers are expected to memoize the result themselves (each of api.Args and htpx.Args wraps this in its own package-level sync.Once), since only the first caller's app value should ever be used within a given process for a given package.

func IsLoopbackBind

func IsLoopbackBind(bind string) bool

IsLoopbackBind reports whether bind, a host:port listen address, names a loopback host per IsLoopbackHost. A bind that does not parse as host:port, and one whose host is empty (":8080" binds every interface), is NOT loopback. IPv6 brackets ("[::1]:8080") are stripped before the check.

func IsLoopbackHost

func IsLoopbackHost(host string) bool

IsLoopbackHost reports whether host names the local machine: "localhost" (any case) or a literal IP address for which net.IP.IsLoopback is true (127.0.0.0/8, ::1). Surrounding whitespace is ignored. An empty host is NOT loopback -- it is the "every interface" wildcard -- and neither is a DNS name other than localhost, since resolving it would be a network round trip whose answer an attacker-controlled resolver could shape.

This is the security-gate predicate behind every "insecure only on loopback" check in the repo (the api server's dev-TLS opt-out, the pkg/htpx fork of it, `apic mcp --allow-insecure-network`, and the apimap proxy's bind guard); it lives here so those four call sites share one implementation instead of four byte-identical copies (QG-121).

func SecurityHeaders

func SecurityHeaders() gin.HandlerFunc

SecurityHeaders returns the always-on security-response-header middleware shared by api.New and htpx.New (N-11, appsec 2026-07-05; QG-095/#271 parity). default-src 'none' with same-origin isolation is the correct posture for a pure JSON/WebSocket API that serves no HTML -- defense in depth, meant to be installed first in the middleware chain so every response (CORS preflights, middleware aborts, 404s) carries the set.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL