Skip to content

Fix: Use Annotated syntax for webhook_data Query parameter#127

Open
hexdaemon wants to merge 1 commit intolnbits:mainfrom
hexdaemon:fix/webhook-data-query-param
Open

Fix: Use Annotated syntax for webhook_data Query parameter#127
hexdaemon wants to merge 1 commit intolnbits:mainfrom
hexdaemon:fix/webhook-data-query-param

Conversation

@hexdaemon
Copy link

Fixes #126

Problem

When accessing a lightning address via , the returned callback URL contains a malformed parameter even when no webhook is configured. This breaks LNURL-pay flows (especially Nostr zaps) because clients append to a URL that already has query parameters, resulting in double question marks.

Root Cause

The parameter in was using as a default value. When called directly as a Python function (from ), doesn't resolve to - it remains a FastAPI object which is truthy.

This caused the check if webhook_data: to pass, appending the string representation of the FieldInfo object to the callback URL.

Solution

Use Annotated[str | None, Query()] = None syntax which properly separates FastAPI metadata from the default value, making the function safe to call both via HTTP and directly as a Python function.

Changes

  • Added from typing import Annotated import
  • Changed function signature from:
    webhook_data: str | None = Query(None)
    to:
    webhook_data: Annotated[str | None, Query()] = None

Impact

  • ✅ Fixes all lightning address zaps that were failing with 400 errors
  • ✅ Maintains backward compatibility with direct HTTP calls
  • ✅ No breaking changes to API

Testing

Tested against the exact scenario described in #126:

  • Lightning address queries now return clean callback URLs
  • Zap flow works correctly (no double question marks)
  • Regular LNURL-pay continues to work as expected

Fixes lnbits#126

The webhook_data parameter in api_lnurl_response() was using Query(None)
as a default value. When called directly as a Python function (e.g., from
lnaddress()), Query(None) doesn't resolve to None - it remains a FastAPI
FieldInfo object which is truthy.

This caused malformed callback URLs to be generated with
webhook_data=alias%3D%27webhook_data%27+extra%3D%7B%7D appended, breaking
LNURL-pay flows (especially Nostr zaps) because clients would append
?amount=... to a URL already containing query parameters, resulting in
double question marks.

Solution: Use Annotated[str | None, Query()] = None syntax which properly
separates FastAPI metadata from the default value, making the function
safe to call both via HTTP and directly.

This fixes all lightning address zaps that were failing with 400 errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Lightning address callback URL contains malformed webhook_data, breaking zaps

1 participant