Skip to content

Possible regression: /otp, /resend and /reauthenticate never return the SMS provider's message_id for a real provider #2901

Description

@QuintinWillison

While planning locally for auth-related integration tests for capabilities I'm adding to our new supabase-go SDK, Claude has identified a possible issue in this codebase...

🤖 Claude's Analysis

Since #1704, released in v2.158.1 in August 2024, a phone one-time code sent through a built-in SMS provider answers without the message_id the API documents. The identifier the provider returns is assigned to a shadowed variable inside sendPhoneConfirmation and discarded, so the response carries the empty outer one and omitempty drops the field. Only test OTP numbers still return an identifier, the fixed "test-otp".

What happens

In sendPhoneConfirmation at d7955e9:

  • Line 79 declares messageID in the function body: var otp, messageID string.
  • Line 83 assigns to it for a test number: messageID = "test-otp".
  • Line 120, inside the else block that opens at line 111, receives the provider's identifier with messageID, err := smsProvider.SendMessage(phone, message, channel, otp).
  • Line 160 returns messageID, the one from line 79, still empty.

Line 120 declares a new variable rather than assigning the existing one. A short variable declaration "may redeclare variables provided they were originally declared earlier in the same block" (Go spec, Short variable declarations). err was declared in that block at line 112, so it is reused, but messageID was declared in the enclosing function block, so := creates a second messageID whose scope "ends at the end of the innermost containing block" and which, while in scope, "denotes the entity declared by the inner declaration" (Go spec, Declarations and scope). Effective Go states the same case directly: "if v is already declared in an outer scope, the declaration will create a new variable" (Redeclaration and reassignment). The compiler accepts it because the inner variable is used on the error path at line 122.

The regression is in #1704, merged 2024-08-04 and released in v2.158.1 the next day: the parent commit had messageID, err = smsProvider.SendMessage(...), and the change to := came with moving the send into the new else block. The field had been delivered since #1145 added it in June 2023 (v2.73.0), so it worked for about fourteen months and has been missing for about twenty-seven. The send-SMS hook branch sets no identifier by design, so this affects every project on a built-in provider (Twilio, Twilio Verify, MessageBird, Textlocal, Vonage).

A standalone reproduction

The same lexical structure with the surrounding code removed. sendPhoneConfirmation is the function as it is at d7955e9, with the original line numbers in comments, and sendPhoneConfirmationFixed differs only at line 120. It has no dependencies, so it runs as is with go run or in the Go playground.

package main

import "fmt"

// providerMessageID is what SendMessage returns, standing in for the
// identifier a real provider reports.
const providerMessageID = "the id SendMessage returned"

// testNumberMessageID stands in for the fixed "test-otp" the real function
// assigns for a test number.
const testNumberMessageID = "test-otp, assigned at line 83 with ="

// smsProvider stands in for the built-in providers.
type smsProvider struct{}

func (smsProvider) SendMessage(phone, message, channel, otp string) (string, error) {
	return providerMessageID, nil
}

func getSmsProvider() (smsProvider, error)              { return smsProvider{}, nil }
func generateSMSFromTemplate(otp string) (string, error) { return "Your code is " + otp, nil }

const sendSMSHookEnabled = false

// sendPhoneConfirmation mirrors internal/api/phone.go at d7955e9, with the
// original line numbers in the comments.
func sendPhoneConfirmation(testNumber bool) (string, error) {
	var otp, messageID string // line 79

	if testNumber {
		otp = "123456"
		messageID = testNumberMessageID // line 83
	}

	if otp == "" { // line 87
		otp = "654321"
		if sendSMSHookEnabled { // line 96
			// the hook branch sets no identifier
		} else { // line 111
			smsProvider, err := getSmsProvider() // line 112: err is declared in this block
			if err != nil {
				return "", err
			}
			message, err := generateSMSFromTemplate(otp) // line 116
			if err != nil {
				return "", err
			}
			messageID, err := smsProvider.SendMessage("+15550000000", message, "sms", otp) // line 120: a new messageID, scoped to this block
			if err != nil {
				return messageID, err // line 122: the inner one, which is why the compiler is satisfied
			}
		}
	}

	return messageID, nil // line 160: the outer one
}

// sendPhoneConfirmationFixed is the same function with `=` at line 120.
func sendPhoneConfirmationFixed(testNumber bool) (string, error) {
	var otp, messageID string

	if testNumber {
		otp = "123456"
		messageID = testNumberMessageID
	}

	if otp == "" {
		otp = "654321"
		if sendSMSHookEnabled {
		} else {
			smsProvider, err := getSmsProvider()
			if err != nil {
				return "", err
			}
			message, err := generateSMSFromTemplate(otp)
			if err != nil {
				return "", err
			}
			messageID, err = smsProvider.SendMessage("+15550000000", message, "sms", otp) // assigns the outer one
			if err != nil {
				return messageID, err
			}
		}
	}

	return messageID, nil
}

func main() {
	id, _ := sendPhoneConfirmation(false)
	fmt.Printf("as written, real provider: got %q, expected %q\n", id, providerMessageID)
	id, _ = sendPhoneConfirmation(true)
	fmt.Printf("as written, test number:   got %q, expected %q\n", id, testNumberMessageID)
	id, _ = sendPhoneConfirmationFixed(false)
	fmt.Printf("with `=` at line 120:      got %q, expected %q\n", id, providerMessageID)
}

Output:

as written, real provider: got "", expected "the id SendMessage returned"
as written, test number:   got "test-otp, assigned at line 83 with =", expected "test-otp, assigned at line 83 with ="
with `=` at line 120:      got "the id SendMessage returned", expected "the id SendMessage returned"

go vet reports nothing on this file. The shadow analyzer does, on the := line of the first function: declaration of "messageID" shadows declaration at line 28.

Who it affects and what it breaks

The field is documented on POST /otp and POST /resend as "Unique ID of the message as reported by the SMS sending provider. Useful for tracking deliverability problems", and all three phone-send handlers forward what sendPhoneConfirmation returns (otp.go:194-207, resend.go:141-169, reauthenticate.go:47-62).

This is customer-facing surface: every official client library exposes the field (supabase-js AuthOtpResponse.messageId, supabase-py AuthOtpResponse.message_id, supabase-swift ResendMobileResponse.messageId and supabase-flutter ResendResponse.messageId), and a developer on a built-in provider who reads it has received nothing since August 2024. What they lose is the one identifier that ties a send to the provider's record of it, the documented purpose. No authentication flow is affected: the code is still sent, verified and signed in exactly as before, and the response is otherwise unchanged.

To be clear about the size of this: it is a documented field that is silently absent, not a broken flow, and no customer has reported it in twenty-seven months, which suggests few read it. Not affected at all: projects on the send-SMS hook, which never had an identifier, test numbers, which still answer "test-otp", and anyone who does not read the field. The reason to fix it now rather than leave it is that the cross-SDK capability specs being written in supabase/sdk (supabase/sdk#314) promise the field for the OTP, resend and reauthenticate flows, so new SDKs will build and document a field the server does not deliver unless either the server is fixed or the specs stop promising it.

What should change

  • Line 120 assigns instead of declaring: messageID, err = smsProvider.SendMessage(phone, message, channel, otp). Both variables exist at that point, so nothing else moves.
  • A test that asserts the provider's identifier comes back. The existing TestSmsProvider returns an empty identifier and doTestSendPhoneConfirmation discards the function's first return value (phone_test.go:35-38, :119), so no test could catch this. Returning a fixed identifier from the double and asserting it on the result, and on the /otp body, would.
  • Optionally, the shadow analyzer (golang.org/x/tools/go/analysis/passes/shadow) in the lint run. It is not part of go vet's default set, which is why nothing flagged the change.

Activity

  1. thelastbackspace commented on Nov 5, 2026

    @thelastbackspace

    I'd like to pick this up. Plan is the one-line := → = change in sendPhoneConfirmation, plus making TestSmsProvider return a fixed ID and asserting it comes back from doTestSendPhoneConfirmation (and that test numbers still get test-otp). Will open a PR shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions