···2222 );
2323 const targetUrl = new TextDecoder().decode(urlBytes);
24242525- // check if we have an entry in the cache with the target url
2626- let cacheKey = new Request(targetUrl);
2727- let response = await cache.match(cacheKey);
2828- if (response) {
2929- return response;
3030- }
3131-3232- // else compute the signature
2525+ // check signature before we lookup cache, if we do the other way
2626+ // then any random signature for the same url will be let through after
2727+ // a single successful request
3328 const key = await crypto.subtle.importKey(
3429 "raw",
3530 new TextEncoder().encode(env.CAMO_SHARED_SECRET),
···58535954 if (!valid) {
6055 return new Response("Invalid signature", { status: 403 });
5656+ }
5757+5858+ // check if we have an entry in the cache with the target url
5959+ let cacheKey = new Request(targetUrl);
6060+ let response = await cache.match(cacheKey);
6161+ if (response) {
6262+ return response;
6163 }
62646365 let parsedUrl;