@@ -274,7 +274,7 @@ export function getB64Flag(uint16Arr, flagVersion) {
274
274
export function msgkeyFromUrl ( u ) {
275
275
const ans = extractStamps ( u ) ;
276
276
// accesskey is at index 3
277
- return ans [ 3 ] ;
277
+ return ans [ 3 ] || "" ;
278
278
}
279
279
280
280
/**
@@ -286,8 +286,8 @@ export function msgkeyFromUrl(u) {
286
286
export function blockstampFromUrl ( u ) {
287
287
const ans = extractStamps ( u ) ;
288
288
const delim = ans [ 0 ] ;
289
- const ver = ans [ 1 ] ;
290
- const blockstamp = ans [ 2 ] ;
289
+ const ver = ans [ 1 ] || "" ; // may be undefined
290
+ const blockstamp = ans [ 2 ] || "" ; // may be undefined
291
291
292
292
// delim at index 0, version at index 1, blockstamp at index 2
293
293
if ( util . emptyString ( ver ) || util . emptyString ( blockstamp ) ) return "" ;
@@ -328,19 +328,26 @@ export function extractStamps(u) {
328
328
const recStamp = recBlockstampFrom ( url ) ;
329
329
const useRecStamp = ! util . emptyString ( recStamp ) ;
330
330
331
- const paths = url . pathname . split ( "/" ) ;
332
-
333
- if ( ! useRecStamp && paths . length <= 1 ) {
334
- return emptystamp ;
335
- }
336
-
337
331
let s = emptystr ;
338
332
// note: the legacy free.bravedns endpoint need not support
339
333
// gateway queries or auth
340
334
if ( useRecStamp ) {
341
335
s = recStamp ;
342
336
}
343
337
338
+ const paths = url . pathname . split ( "/" ) ;
339
+ const domains = url . hostname . split ( "." ) ;
340
+ // could be a b32 flag in the hostname,
341
+ // even if its a http-req (possible for a cc request)
342
+ for ( const d of domains ) {
343
+ if ( d . length === 0 ) continue ;
344
+ // capture the first occurence of a b32 delimiter "-"
345
+ if ( isStampQuery ( d ) ) {
346
+ s = d ;
347
+ break ;
348
+ }
349
+ }
350
+ // overwrite if there exists a b64 flag in path
344
351
for ( const p of paths ) {
345
352
if ( p . length === 0 ) continue ;
346
353
// skip to next if path has `/dns-query` or `/gateway` or '/l:'
@@ -350,8 +357,9 @@ export function extractStamps(u) {
350
357
}
351
358
}
352
359
353
- // get blockstamp with access-key from paths[1|2]
360
+ // get blockstamp with access-key from paths[1|2] or from hostname[0|1]
354
361
try {
362
+ // FIXME: the array returned here may not always be of length 4
355
363
return splitBlockstamp ( s ) ;
356
364
} catch ( e ) {
357
365
log . d ( "Rdns:blockstampFromUrl" , e ) ;
@@ -379,17 +387,16 @@ export function base32ToUintV1(flag) {
379
387
return bufutil . decodeFromBinaryArray ( rbase32 ( b32 ) ) ;
380
388
}
381
389
382
- export function splitBlockstamp ( s ) {
390
+ function splitBlockstamp ( s ) {
383
391
// delim, version, blockstamp, accesskey
384
- let out = [ "" , "" , "" , "" ] ;
385
392
386
- if ( util . emptyString ( s ) ) return out ;
387
- if ( ! isStampQuery ( s ) ) return out ;
393
+ if ( util . emptyString ( s ) ) return emptystamp ;
394
+ if ( ! isStampQuery ( s ) ) return emptystamp ;
388
395
389
396
if ( isB32Stamp ( s ) ) {
390
- out = [ _b32delim , ...s . split ( _b32delim ) ] ;
397
+ return [ _b32delim , ...s . split ( _b32delim ) ] ;
391
398
} else {
392
- out = [ _b64delim , ...s . split ( _b64delim ) ] ;
399
+ return [ _b64delim , ...s . split ( _b64delim ) ] ;
393
400
}
394
401
395
402
return out ;
0 commit comments