{"record":{"id":"73b4abede099bd24","repo":"wavetermdev/waveterm","slug":"no-auth-key-found-in-environment-variables","errorCode":null,"errorMessage":"no auth key found in environment variables","messagePattern":"no auth key found in environment variables","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/authkey/authkey.go","lineNumber":31,"sourceCode":"\nconst WaveAuthKeyEnv = \"WAVETERM_AUTH_KEY\"\nconst AuthKeyHeader = \"X-AuthKey\"\n\nfunc ValidateIncomingRequest(r *http.Request) error {\n\treqAuthKey := r.Header.Get(AuthKeyHeader)\n\tif reqAuthKey == \"\" {\n\t\treturn fmt.Errorf(\"no x-authkey header\")\n\t}\n\tif reqAuthKey != GetAuthKey() {\n\t\treturn fmt.Errorf(\"x-authkey header is invalid\")\n\t}\n\treturn nil\n}\n\nfunc SetAuthKeyFromEnv() error {\n\tauthkey = os.Getenv(WaveAuthKeyEnv)\n\tif authkey == \"\" {\n\t\treturn fmt.Errorf(\"no auth key found in environment variables\")\n\t}\n\tos.Unsetenv(WaveAuthKeyEnv)\n\treturn nil\n}\n\nfunc GetAuthKey() string {\n\treturn authkey\n}\n","sourceCodeStart":13,"sourceCodeEnd":40,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/authkey/authkey.go#L13-L40","documentation":"SetAuthKeyFromEnv reads the WAVE_AUTHKEY environment variable and stores it as the server's auth key. If the variable is unset or empty, the server cannot establish an authentication key and returns this error instead of silently running unauthenticated.","triggerScenarios":"Calling SetAuthKeyFromEnv (via grabAndRemoveEnvVars) when os.Getenv(WaveAuthKeyEnv) returns an empty string — i.e. WAVE_AUTHKEY was never exported into the server process environment.","commonSituations":"Starting the Wave server from a shell or service manager that does not pass WAVE_AUTHKEY; a .env file not loaded into the process environment; a typo like WAVEAUTHKEY or WAVE_AUTH_KEY in launch scripts or systemd unit files.","solutions":["Export WAVE_AUTHKEY before launching the server: export WAVE_AUTHKEY=$(openssl rand -hex 32)","Check that the service manager / launch script actually forwards the variable (e.g. systemd Environment= or EnvironmentFile=)","Fix typos in the variable name in your shell profile or wrapper scripts","If keys are generated by a launcher, confirm the launcher ran before the server start"],"exampleFix":"// before\nwave-server   # WAVE_AUTHKEY unset\n// after\nexport WAVE_AUTHKEY=$(openssl rand -hex 32)\nwave-server","handlingStrategy":"validation","validationCode":"if os.Getenv(\"WAVE_AUTHKEY\") == \"\" {\n    return fmt.Errorf(\"WAVE_AUTHKEY must be set before starting the server\")\n}","typeGuard":null,"tryCatchPattern":"if err := authkey.SetAuthKeyFromEnv(); err != nil {\n    log.Fatalf(\"authkey setup failed: %v\", err)\n}","preventionTips":["Set WAVE_AUTHKEY in shell profiles or service unit files before launch","Use a launcher that generates and exports the key atomically","Validate env in CI/startup scripts with a preflight check"],"tags":["auth","environment","config"],"backgroundTag":"missing-env-var","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}