jackc/pgx · error
bad auth type
Error message
bad auth type
What it means
Returned by AuthenticationOk.Decode in pgproto3/authentication_ok.go:30 when the leading 4 bytes are not AuthTypeOk (0). Defensive check redundant with frontend dispatch; firing means corruption after dispatch or Decode called on bytes whose code is not 0.
Source
Thrown at pgproto3/authentication_ok.go:30
type AuthenticationOk struct{}
// Backend identifies this message as sendable by the PostgreSQL backend.
func (*AuthenticationOk) Backend() {}
// Backend identifies this message as an authentication response.
func (*AuthenticationOk) AuthenticationResponse() {}
// Decode decodes src into dst. src must contain the complete message with the exception of the initial 1 byte message
// type identifier and 4 byte message length.
func (dst *AuthenticationOk) Decode(src []byte) error {
if len(src) != 4 {
return errors.New("bad authentication message size")
}
authType := binary.BigEndian.Uint32(src)
if authType != AuthTypeOk {
return errors.New("bad auth type")
}
return nil
}
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
func (src *AuthenticationOk) Encode(dst []byte) ([]byte, error) {
dst, sp := beginMessage(dst, 'R')
dst = pgio.AppendUint32(dst, AuthTypeOk)
return finishMessage(dst, sp)
}
// MarshalJSON implements encoding/json.Marshaler.
func (src AuthenticationOk) MarshalJSON() ([]byte, error) {
return json.Marshal(struct {
Type string
}{
Type: "AuthenticationOK",View on GitHub (pinned to ec1a0befd2)
Solutions
- Use findAuthenticationMessageType for dispatch instead of a fixed struct.
- Switch on the auth code (0 => Ok) when decoding manually.
- Do not alias the message buffer across decodes.
Defensive patterns
Strategy: validation
Validate before calling
if len(body) >= 4 && binary.BigEndian.Uint32(body) == pgproto3.AuthTypeOk {
var m pgproto3.AuthenticationOk
return m.Decode(body)
} Type guard
func isAuthOkFrame(body []byte) bool {
return len(body) >= 4 && binary.BigEndian.Uint32(body) == pgproto3.AuthTypeOk
} Prevention
- Use findAuthenticationMessageType for dispatch instead of a fixed struct.
- Switch on the auth code (0 => Ok) before Decode.
- Do not alias the message buffer across decodes.
When it happens
Trigger: Manual/proxy code decoding a non-Ok frame with the AuthenticationOk struct; buffer mutation; fuzz input.
Common situations: Test/proxy hard-coding the wrong struct; corrupted reused buffer.
Related errors
AI-assisted analysis of jackc/pgx@ec1a0befd2 (2026-08-04).
Data as JSON: /data/errors/6b968bb9486cb56c.json.
Report an issue: GitHub.