How to Apply the Principle of Least Privilege in Go API Design
Apply the Principle of Least Privilege in Go API design by restricting runtime behavior to the minimum necessary scope using GODEBUG settings and //go:debug directives. Define specific constraints in your go.mod file or source code to disable unnecessary features like HTTP/2 or legacy behaviors that could introduce security risks.
//go:build go1.23
//go:debug http2client=0
//go:debug http2server=0
//go:debug panicnil=0
package main
import "fmt"
func main() {
fmt.Println("API running with restricted privileges")
}
Alternatively, set the environment variable before execution:
export GODEBUG=http2client=0,http2server=0,panicnil=0
go run main.go