@paywalls-net/filter 1.3.5 → 1.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Client SDK for integrating paywalls.net bot filtering and authorization services into your server or CDN.",
4
4
  "author": "paywalls.net",
5
5
  "license": "MIT",
6
- "version": "1.3.5",
6
+ "version": "1.3.7",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
package/src/index.js CHANGED
@@ -113,9 +113,17 @@ async function proxyVAIRequest(cfg, request) {
113
113
  forwardHeaders['X-Original-Host'] = headers['host'];
114
114
  }
115
115
 
116
+ // Forward browser Origin via custom header for CORS evaluation (§5).
117
+ // Using X-Forwarded-Origin because wrangler dev mangles the standard
118
+ // Origin header with port-stacking when proxying between local workers.
119
+ const browserOrigin = headers['origin'] || null;
120
+ if (browserOrigin) {
121
+ forwardHeaders['X-Forwarded-Origin'] = browserOrigin;
122
+ }
123
+
116
124
  // Forward request to cloud-api
117
125
  const response = await fetch(`${cfg.paywallsAPIHost}${cloudApiPath}`, {
118
- method: 'GET',
126
+ method: request.method || 'GET',
119
127
  headers: forwardHeaders
120
128
  });
121
129
 
@@ -123,7 +131,19 @@ async function proxyVAIRequest(cfg, request) {
123
131
  console.error(`VAI proxy error: ${response.status} ${response.statusText}`);
124
132
  }
125
133
 
126
- return response;
134
+ // Build response, fixing CORS headers that wrangler dev may mangle.
135
+ // The cloud-api sets Access-Control-Allow-Origin to the browser's origin
136
+ // (via X-Forwarded-Origin), but wrangler can corrupt the value on the
137
+ // return path too. Re-stamp it with the captured browser origin.
138
+ const responseHeaders = new Headers(response.headers);
139
+ if (browserOrigin && responseHeaders.has('Access-Control-Allow-Origin')) {
140
+ responseHeaders.set('Access-Control-Allow-Origin', browserOrigin);
141
+ }
142
+ return new Response(response.body, {
143
+ status: response.status,
144
+ statusText: response.statusText,
145
+ headers: responseHeaders
146
+ });
127
147
  } catch (err) {
128
148
  console.error(`Error proxying VAI request: ${err.message}`);
129
149
  return new Response('Internal Server Error', { status: 500 });
@@ -104,10 +104,10 @@ export async function classifyUserAgent(cfg, userAgent) {
104
104
  // Check classification cache first (single lookup is more efficient than has + get)
105
105
  const cached = classificationCache.get(userAgent);
106
106
  if (cached !== undefined) {
107
- console.log(`User agent classification cache hit for: ${userAgent}`);
107
+ // console.log(`User agent classification cache hit for: ${userAgent}`);
108
108
  return cached;
109
109
  }
110
- console.log(`User agent classification cache miss for: ${userAgent}`);
110
+ // console.log(`User agent classification cache miss for: ${userAgent}`);
111
111
 
112
112
  const parsedUA = new UAParser(userAgent).getResult();
113
113