Skip to content

Commit

Permalink
Only select valid characters from the authenticate header (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwvb-zoosh authored May 9, 2024
1 parent fd23fd4 commit 2c0d348
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/client/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ export function setupL402Interceptor(instance: AxiosInstance, wallet: Wallet, st
*/
function parseHeader(header: string): { header_key: string; invoice: string; macaroon: string } | null {
const headerKeyMatch = /^(LSAT|L402)/.exec(header);
const invoiceMatch = /invoice="([^"]+)"/.exec(header);
const macaroonMatch = /macaroon="([^"]+)"/.exec(header);
const invoiceMatch = /invoice="([\w|\d]+)"/.exec(header); // Lightning invoice only use alphanumeric characters, see: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
const macaroonMatch = /macaroon="([\w|\d\+\/=_-]+)"/.exec(header); // Base64 URL-safe characters

if (invoiceMatch && macaroonMatch) {
return {
Expand Down
2 changes: 1 addition & 1 deletion test/client/axios.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class MockWallet extends Wallet {
const url = 'https://example.com/resource';
nock('https://example.com')
.get('/resource')
.reply(402, '', { 'www-authenticate': 'L402 invoice="mock-invoice" macaroon="mock-macaroon"' });
.reply(402, '', { 'www-authenticate': 'L402 invoice="mockinvoice" macaroon="mock-macaroon"' });

// Mock the successful retry response
nock('https://example.com')
Expand Down

0 comments on commit 2c0d348

Please sign in to comment.