@gjsify/fetch 0.64.40 → 0.64.41

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/README.md CHANGED
@@ -24,6 +24,18 @@ const text = await response.text();
24
24
  console.log(text);
25
25
  ```
26
26
 
27
+ ## TLS options (GJS)
28
+
29
+ - `rejectUnauthorized: false` accepts any peer certificate for that request (also `NODE_TLS_REJECT_UNAUTHORIZED=0`).
30
+ - `servername: 'host.example'` connects to the URL (e.g. `https://127.0.0.2:8443/` through an SSH tunnel)
31
+ but verifies the certificate against `host.example` with the system CA. Only a hostname mismatch is
32
+ forgiven, and only when the certificate names `servername`; an untrusted, expired or revoked chain
33
+ still fails. `rejectUnauthorized: false` takes precedence.
34
+
35
+ The check runs per TLS handshake. libsoup/GIO may reuse a pooled connection or resume the TLS session
36
+ for a later request to the same host:port without a handshake, so do not mix verification policies
37
+ for one host:port in a process (this holds for `rejectUnauthorized: false` too).
38
+
27
39
  ## Inspirations and credits
28
40
 
29
41
  - https://github.com/sonnyp/troll/blob/main/src/std/fetch.js
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{isAbortSignal as e}from"./utils/is.js";import t,{clone as n,extractContentType as r,getTotalBytes as i}from"./body.js";import a from"./headers.js";import{inputStreamToReadable as o,soupSendAsync as s}from"./utils/soup-helpers.js";import{loadSoup as c}from"./utils/soup-lazy.js";import{DEFAULT_REFERRER_POLICY as l,determineRequestsReferrer as u,validateReferrerPolicy as d}from"./utils/referrer.js";import{URL as f}from"@gjsify/url";import p from"@girs/glib-2.0";import m from"@girs/gio-2.0";const h=Symbol(`Request internals`);let g=null;function envPositiveInt(e,t){let n=p.getenv(e);if(!n)return t;let r=Number.parseInt(n,10);return Number.isFinite(r)&&r>0?r:t}function shouldAcceptAnyCert(e){return e===!1?!0:e===!0?!1:p.getenv(`NODE_TLS_REJECT_UNAUTHORIZED`)===`0`}function getSharedSession(e){if(g===null){let t=envPositiveInt(`GJSIFY_FETCH_MAX_CONNS_PER_HOST`,16),n=Math.max(envPositiveInt(`GJSIFY_FETCH_MAX_CONNS`,64),t);g=new e.Session({maxConns:n,maxConnsPerHost:t}),g.remove_feature_by_type(e.ContentDecoder.$gtype)}return g}const isRequest=e=>typeof e==`object`&&typeof e.url==`string`;var _=class Request extends t{cache;credentials;destination;get headers(){return this[h].headers}integrity;keepalive;get method(){return this[h].method}mode;get redirect(){return this[h].redirect}get referrer(){if(this[h].referrer===`no-referrer`)return``;if(this[h].referrer===`client`)return`about:client`;if(this[h].referrer)return this[h].referrer.toString()}get referrerPolicy(){return this[h].referrerPolicy}set referrerPolicy(e){this[h].referrerPolicy=d(e)}get signal(){return this[h].signal}get url(){return this[h].parsedURL.toString()}get _uri(){return p.Uri.parse(this.url,p.UriFlags.ENCODED)}get _session(){return this[h].session}get _message(){return this[h].message}get _inputStream(){return this[h].inputStream}get[Symbol.toStringTag](){return`Request`}[h];follow;compress=!1;counter=0;agent=``;highWaterMark=16384;insecureHTTPParser=!1;rejectUnauthorized;constructor(t,i){let o=t,s=i||{},c,l={};if(isRequest(t)?(c=new f(o.url),l=o):c=new f(t),c.username!==``||c.password!==``)throw TypeError(`${c} is an url with embedded credentials.`);let u=s.method||l.method||`GET`;if(/^(delete|get|head|options|post|put)$/i.test(u)&&(u=u.toUpperCase()),(i?.body!=null||isRequest(t)&&o.body!==null)&&(u===`GET`||u===`HEAD`))throw TypeError(`Request with GET/HEAD method cannot have body`);let d=i?.body?i.body:isRequest(t)&&o.body!==null?n(t):null;super(d,{size:s.size||0});let p=new a(i?.headers||o.headers||{});if(d!==null&&!p.has(`Content-Type`)){let e=r(d,this);e&&p.set(`Content-Type`,e)}let m=isRequest(t)?o.signal:null;if(i&&`signal`in i&&(m=i.signal),m!=null&&!e(m))throw TypeError(`Expected signal to be an instanceof AbortSignal or EventTarget`);let g=i?.referrer==null?o.referrer:i.referrer;if(g===``)g=`no-referrer`;else if(g){let e=new f(g);g=/^about:(\/\/)?client$/.test(e.toString())?`client`:e}else g=void 0;this[h]={method:u,redirect:i?.redirect||o.redirect||`follow`,headers:p,parsedURL:c,signal:m,referrer:g,referrerPolicy:``,session:null,message:null},this.follow=s.follow===void 0?o.follow===void 0?20:o.follow:s.follow,this.compress=s.compress===void 0?o.compress===void 0?!0:o.compress:s.compress,this.counter=s.counter||o.counter||0,this.agent=s.agent||o.agent,this.highWaterMark=s.highWaterMark||o.highWaterMark||16384,this.insecureHTTPParser=s.insecureHTTPParser||o.insecureHTTPParser||!1,this.rejectUnauthorized=s.rejectUnauthorized??o.rejectUnauthorized,this.referrerPolicy=i?.referrerPolicy||o.referrerPolicy||``}async _send(e){let{signal:t,parsedURL:n}=this[h],r=n.protocol;if(r!==`http:`&&r!==`https:`)throw Error(`Cannot send request: no Soup session (non-HTTP URL?)`);let i=await c(),a=getSharedSession(i),l=new i.Message({method:this[h].method,uri:p.Uri.parse(n.toString(),p.UriFlags.ENCODED)});this[h].session=a,this[h].message=l,e.headers._appendToSoupMessage(i,l);let u=this._rawBodyBuffer;if(u!==null&&u.byteLength>0){let t=e.headers.get(`content-type`)||null;l.set_request_body_from_bytes(t,new p.Bytes(u))}n.protocol===`https:`&&shouldAcceptAnyCert(this.rejectUnauthorized)&&l.connect(`accept-certificate`,(e,t,n)=>!0);let d=new m.Cancellable;return t&&(t.aborted?d.cancel():t.addEventListener(`abort`,()=>d.cancel(),{once:!0})),this[h].inputStream=await s(a,l,p.PRIORITY_DEFAULT,d),this[h].readable=o(this[h].inputStream),{inputStream:this[h].inputStream,readable:this[h].readable,cancellable:d}}clone(){return new Request(this)}async arrayBuffer(){return super.arrayBuffer()}async blob(){return super.blob()}async formData(){return super.formData()}async json(){return super.json()}async text(){return super.text()}};Object.defineProperties(_.prototype,{method:{enumerable:!0},url:{enumerable:!0},headers:{enumerable:!0},redirect:{enumerable:!0},clone:{enumerable:!0},signal:{enumerable:!0},referrer:{enumerable:!0},referrerPolicy:{enumerable:!0}});const getSoupRequestOptions=e=>{let{parsedURL:t}=e[h],n=new a(e[h].headers);n.has(`Accept`)||n.set(`Accept`,`*/*`);let r=null;if(e.body===null&&/^(post|put)$/i.test(e.method)&&(r=`0`),e.body!==null){let t=i(e);typeof t==`number`&&!Number.isNaN(t)&&(r=String(t))}r&&n.set(`Content-Length`,r),e.referrerPolicy===``&&(e.referrerPolicy=l),e.referrer&&e.referrer!==`no-referrer`?e[h].referrer=u(e):e[h].referrer=`no-referrer`,e[h].referrer instanceof f&&n.set(`Referer`,e.referrer),n.has(`User-Agent`)||n.set(`User-Agent`,`gjsify-fetch`),e.compress&&!n.has(`Accept-Encoding`)&&n.set(`Accept-Encoding`,`gzip, deflate`);let{agent:o}=e;return typeof o==`function`&&(o=o(t)),!n.has(`Connection`)&&!o&&n.set(`Connection`,`close`),{parsedURL:t,options:{headers:n}}};export{_ as Request,_ as default,getSoupRequestOptions};
1
+ import"./_virtual/_rolldown/runtime.js";import{isAbortSignal as e}from"./utils/is.js";import t,{clone as n,extractContentType as r,getTotalBytes as i}from"./body.js";import a from"./headers.js";import{inputStreamToReadable as o,soupSendAsync as s}from"./utils/soup-helpers.js";import{loadSoup as c}from"./utils/soup-lazy.js";import{acceptsForServername as l}from"./utils/tls-servername.js";import{DEFAULT_REFERRER_POLICY as u,determineRequestsReferrer as d,validateReferrerPolicy as f}from"./utils/referrer.js";import{URL as p}from"@gjsify/url";import m from"@girs/glib-2.0";import h from"@girs/gio-2.0";const g=Symbol(`Request internals`);let _=null;function envPositiveInt(e,t){let n=m.getenv(e);if(!n)return t;let r=Number.parseInt(n,10);return Number.isFinite(r)&&r>0?r:t}function shouldAcceptAnyCert(e){return e===!1?!0:e===!0?!1:m.getenv(`NODE_TLS_REJECT_UNAUTHORIZED`)===`0`}function getSharedSession(e){if(_===null){let t=envPositiveInt(`GJSIFY_FETCH_MAX_CONNS_PER_HOST`,16),n=Math.max(envPositiveInt(`GJSIFY_FETCH_MAX_CONNS`,64),t);_=new e.Session({maxConns:n,maxConnsPerHost:t}),_.remove_feature_by_type(e.ContentDecoder.$gtype)}return _}const isRequest=e=>typeof e==`object`&&typeof e.url==`string`;var v=class Request extends t{cache;credentials;destination;get headers(){return this[g].headers}integrity;keepalive;get method(){return this[g].method}mode;get redirect(){return this[g].redirect}get referrer(){if(this[g].referrer===`no-referrer`)return``;if(this[g].referrer===`client`)return`about:client`;if(this[g].referrer)return this[g].referrer.toString()}get referrerPolicy(){return this[g].referrerPolicy}set referrerPolicy(e){this[g].referrerPolicy=f(e)}get signal(){return this[g].signal}get url(){return this[g].parsedURL.toString()}get _uri(){return m.Uri.parse(this.url,m.UriFlags.ENCODED)}get _session(){return this[g].session}get _message(){return this[g].message}get _inputStream(){return this[g].inputStream}get[Symbol.toStringTag](){return`Request`}[g];follow;compress=!1;counter=0;agent=``;highWaterMark=16384;insecureHTTPParser=!1;rejectUnauthorized;servername;constructor(t,i){let o=t,s=i||{},c,l={};if(isRequest(t)?(c=new p(o.url),l=o):c=new p(t),c.username!==``||c.password!==``)throw TypeError(`${c} is an url with embedded credentials.`);let u=s.method||l.method||`GET`;if(/^(delete|get|head|options|post|put)$/i.test(u)&&(u=u.toUpperCase()),(i?.body!=null||isRequest(t)&&o.body!==null)&&(u===`GET`||u===`HEAD`))throw TypeError(`Request with GET/HEAD method cannot have body`);let d=i?.body?i.body:isRequest(t)&&o.body!==null?n(t):null;super(d,{size:s.size||0});let f=new a(i?.headers||o.headers||{});if(d!==null&&!f.has(`Content-Type`)){let e=r(d,this);e&&f.set(`Content-Type`,e)}let m=isRequest(t)?o.signal:null;if(i&&`signal`in i&&(m=i.signal),m!=null&&!e(m))throw TypeError(`Expected signal to be an instanceof AbortSignal or EventTarget`);let h=i?.referrer==null?o.referrer:i.referrer;if(h===``)h=`no-referrer`;else if(h){let e=new p(h);h=/^about:(\/\/)?client$/.test(e.toString())?`client`:e}else h=void 0;this[g]={method:u,redirect:i?.redirect||o.redirect||`follow`,headers:f,parsedURL:c,signal:m,referrer:h,referrerPolicy:``,session:null,message:null},this.follow=s.follow===void 0?o.follow===void 0?20:o.follow:s.follow,this.compress=s.compress===void 0?o.compress===void 0?!0:o.compress:s.compress,this.counter=s.counter||o.counter||0,this.agent=s.agent||o.agent,this.highWaterMark=s.highWaterMark||o.highWaterMark||16384,this.insecureHTTPParser=s.insecureHTTPParser||o.insecureHTTPParser||!1,this.rejectUnauthorized=s.rejectUnauthorized??o.rejectUnauthorized,this.servername=s.servername??o.servername,this.referrerPolicy=i?.referrerPolicy||o.referrerPolicy||``}async _send(e){let{signal:t,parsedURL:n}=this[g],r=n.protocol;if(r!==`http:`&&r!==`https:`)throw Error(`Cannot send request: no Soup session (non-HTTP URL?)`);let i=await c(),a=getSharedSession(i),u=new i.Message({method:this[g].method,uri:m.Uri.parse(n.toString(),m.UriFlags.ENCODED)});this[g].session=a,this[g].message=u,e.headers._appendToSoupMessage(i,u);let d=this._rawBodyBuffer;if(d!==null&&d.byteLength>0){let t=e.headers.get(`content-type`)||null;u.set_request_body_from_bytes(t,new m.Bytes(d))}if(n.protocol===`https:`&&shouldAcceptAnyCert(this.rejectUnauthorized)&&u.connect(`accept-certificate`,(e,t,n)=>!0),n.protocol===`https:`&&this.servername&&!shouldAcceptAnyCert(this.rejectUnauthorized)){let e=this.servername,t=Number(n.port)||443;u.connect(`accept-certificate`,(n,r,i)=>l(i,r.verify(h.NetworkAddress.new(e,t),null),h.TlsCertificateFlags.BAD_IDENTITY))}let f=new h.Cancellable;return t&&(t.aborted?f.cancel():t.addEventListener(`abort`,()=>f.cancel(),{once:!0})),this[g].inputStream=await s(a,u,m.PRIORITY_DEFAULT,f),this[g].readable=o(this[g].inputStream),{inputStream:this[g].inputStream,readable:this[g].readable,cancellable:f}}clone(){return new Request(this)}async arrayBuffer(){return super.arrayBuffer()}async blob(){return super.blob()}async formData(){return super.formData()}async json(){return super.json()}async text(){return super.text()}};Object.defineProperties(v.prototype,{method:{enumerable:!0},url:{enumerable:!0},headers:{enumerable:!0},redirect:{enumerable:!0},clone:{enumerable:!0},signal:{enumerable:!0},referrer:{enumerable:!0},referrerPolicy:{enumerable:!0}});const getSoupRequestOptions=e=>{let{parsedURL:t}=e[g],n=new a(e[g].headers);n.has(`Accept`)||n.set(`Accept`,`*/*`);let r=null;if(e.body===null&&/^(post|put)$/i.test(e.method)&&(r=`0`),e.body!==null){let t=i(e);typeof t==`number`&&!Number.isNaN(t)&&(r=String(t))}r&&n.set(`Content-Length`,r),e.referrerPolicy===``&&(e.referrerPolicy=u),e.referrer&&e.referrer!==`no-referrer`?e[g].referrer=d(e):e[g].referrer=`no-referrer`,e[g].referrer instanceof p&&n.set(`Referer`,e.referrer),n.has(`User-Agent`)||n.set(`User-Agent`,`gjsify-fetch`),e.compress&&!n.has(`Accept-Encoding`)&&n.set(`Accept-Encoding`,`gzip, deflate`);let{agent:o}=e;return typeof o==`function`&&(o=o(t)),!n.has(`Connection`)&&!o&&n.set(`Connection`,`close`),{parsedURL:t,options:{headers:n}}};export{v as Request,v as default,getSoupRequestOptions};
@@ -0,0 +1 @@
1
+ import"../_virtual/_rolldown/runtime.js";function acceptsForServername(e,t,n){return e===n&&(t&n)===0}export{acceptsForServername};
package/lib/request.d.ts CHANGED
@@ -70,6 +70,14 @@ export declare class Request extends Body {
70
70
  insecureHTTPParser: boolean;
71
71
  /** Per-request TLS opt-out (undefined ⇒ verify, honoring NODE_TLS_REJECT_UNAUTHORIZED). */
72
72
  rejectUnauthorized?: boolean;
73
+ /**
74
+ * Connect to the URL host but verify the peer certificate (system CA, chain and expiry
75
+ * included) against this name — Node's `tls.connect({ servername })`, curl's `--resolve`. For
76
+ * an SSH tunnel on loopback whose certificate names the real host. Only a hostname mismatch is
77
+ * forgiven, and only when the certificate names `servername`. `rejectUnauthorized: false`
78
+ * (or `NODE_TLS_REJECT_UNAUTHORIZED=0`) still accepts any certificate and takes precedence.
79
+ */
80
+ servername?: string;
73
81
  constructor(input: RequestInfo | URL | Request, init?: RequestInit);
74
82
  /**
75
83
  * Send the request using Soup.
package/lib/request.js CHANGED
@@ -6,6 +6,7 @@ import GLib from '@girs/glib-2.0';
6
6
  import Gio from '@girs/gio-2.0';
7
7
  import { soupSendAsync, inputStreamToReadable } from './utils/soup-helpers.js';
8
8
  import { loadSoup } from './utils/soup-lazy.js';
9
+ import { acceptsForServername } from './utils/tls-servername.js';
9
10
  import { URL } from '@gjsify/url';
10
11
  import Headers from './headers.js';
11
12
  import Body, { clone, extractContentType, getTotalBytes } from './body.js';
@@ -203,6 +204,14 @@ export class Request extends Body {
203
204
  insecureHTTPParser = false;
204
205
  /** Per-request TLS opt-out (undefined ⇒ verify, honoring NODE_TLS_REJECT_UNAUTHORIZED). */
205
206
  rejectUnauthorized;
207
+ /**
208
+ * Connect to the URL host but verify the peer certificate (system CA, chain and expiry
209
+ * included) against this name — Node's `tls.connect({ servername })`, curl's `--resolve`. For
210
+ * an SSH tunnel on loopback whose certificate names the real host. Only a hostname mismatch is
211
+ * forgiven, and only when the certificate names `servername`. `rejectUnauthorized: false`
212
+ * (or `NODE_TLS_REJECT_UNAUTHORIZED=0`) still accepts any certificate and takes precedence.
213
+ */
214
+ servername;
206
215
  constructor(input, init) {
207
216
  const inputRL = input;
208
217
  const initRL = (init || {});
@@ -293,6 +302,7 @@ export class Request extends Body {
293
302
  this.highWaterMark = initRL.highWaterMark || inputRL.highWaterMark || 16384;
294
303
  this.insecureHTTPParser = initRL.insecureHTTPParser || inputRL.insecureHTTPParser || false;
295
304
  this.rejectUnauthorized = initRL.rejectUnauthorized ?? inputRL.rejectUnauthorized;
305
+ this.servername = initRL.servername ?? inputRL.servername;
296
306
  // §5.4, Request constructor steps, step 16.
297
307
  // Default is empty string per https://fetch.spec.whatwg.org/#concept-request-referrer-policy
298
308
  this.referrerPolicy = init?.referrerPolicy || inputRL.referrerPolicy || '';
@@ -356,6 +366,13 @@ export class Request extends Body {
356
366
  if (parsedURL.protocol === 'https:' && shouldAcceptAnyCert(this.rejectUnauthorized)) {
357
367
  message.connect('accept-certificate', (_msg, _cert, _errors) => true);
358
368
  }
369
+ // `servername`: libsoup verifies the chain against the system CA and reports BAD_IDENTITY for
370
+ // the URL host; forgive exactly that when the cert names `servername` (see acceptsForServername).
371
+ if (parsedURL.protocol === 'https:' && this.servername && !shouldAcceptAnyCert(this.rejectUnauthorized)) {
372
+ const servername = this.servername;
373
+ const port = Number(parsedURL.port) || 443;
374
+ message.connect('accept-certificate', (_msg, cert, errors) => acceptsForServername(errors, cert.verify(Gio.NetworkAddress.new(servername, port), null), Gio.TlsCertificateFlags.BAD_IDENTITY));
375
+ }
359
376
  const cancellable = new Gio.Cancellable();
360
377
  // Close the connect/TTFB abort gap: wire abort → cancel BEFORE send_async. index.ts only wires
361
378
  // it AFTER _send resolves (i.e. after response headers arrive), so an abort fired during
@@ -105,6 +105,55 @@ export default async () => {
105
105
  expect(req.rejectUnauthorized).toBe(undefined);
106
106
  });
107
107
  });
108
+ await describe('@gjsify/fetch — servername (verify against another name than the URL host)', async () => {
109
+ await it('carries servername from init onto the request', () => {
110
+ expect(new RequestCtor('https://example.com/', { servername: 'a.example' }).servername).toBe('a.example');
111
+ expect(new RequestCtor('https://example.com/').servername).toBe(undefined);
112
+ });
113
+ // The system CA does not know the test cert, so the chain stays untrusted: servername only
114
+ // forgives a hostname mismatch, never UNKNOWN_CA — even though the name itself matches.
115
+ await it('still rejects an untrusted chain when the name matches servername', async () => {
116
+ const { server, base } = startHttpsServer();
117
+ let rejected = false;
118
+ try {
119
+ await fetchFn(base, { servername: 'localhost' });
120
+ }
121
+ catch {
122
+ rejected = true;
123
+ }
124
+ finally {
125
+ server.disconnect();
126
+ }
127
+ expect(rejected).toBe(true);
128
+ });
129
+ await it('rejects a servername the certificate does not name', async () => {
130
+ const { server, base } = startHttpsServer();
131
+ let rejected = false;
132
+ try {
133
+ await fetchFn(base, { servername: 'example.com' });
134
+ }
135
+ catch {
136
+ rejected = true;
137
+ }
138
+ finally {
139
+ server.disconnect();
140
+ }
141
+ expect(rejected).toBe(true);
142
+ });
143
+ await it('lets rejectUnauthorized:false win over servername', async () => {
144
+ const { server, base } = startHttpsServer();
145
+ let status = 0;
146
+ try {
147
+ const res = await fetchFn(base, { servername: 'example.com', rejectUnauthorized: false });
148
+ status = res.status;
149
+ await res.text();
150
+ }
151
+ finally {
152
+ server.disconnect();
153
+ }
154
+ expect(status).toBe(200);
155
+ });
156
+ });
108
157
  await describe('@gjsify/fetch — abort surfaces as AbortError', async () => {
109
158
  await it('rejects with an AbortError when the signal is already aborted', async () => {
110
159
  const ctrl = new AbortController();
@@ -0,0 +1,2 @@
1
+ declare const _default: () => Promise<void>;
2
+ export default _default;
@@ -0,0 +1,31 @@
1
+ // Decision function behind fetch's `servername` option — pure, so it runs on Node and GJS alike.
2
+ // The live handshake side (self-signed chain stays rejected, wrong name rejected) is in
3
+ // tls-abort.gjs.spec.ts.
4
+ import { describe, it, expect } from '@gjsify/unit';
5
+ import { acceptsForServername } from './utils/tls-servername.js';
6
+ // Gio.TlsCertificateFlags values (gio/gtlscertificate.h).
7
+ const UNKNOWN_CA = 1;
8
+ const BAD_IDENTITY = 2;
9
+ const EXPIRED = 8;
10
+ const REVOKED = 32;
11
+ export default async () => {
12
+ await describe('@gjsify/fetch — acceptsForServername', async () => {
13
+ await it('accepts when the URL host was the only problem and the cert names servername', async () => {
14
+ expect(acceptsForServername(BAD_IDENTITY, 0, BAD_IDENTITY)).toBe(true);
15
+ });
16
+ await it('rejects when the cert does not name servername', async () => {
17
+ expect(acceptsForServername(BAD_IDENTITY, BAD_IDENTITY, BAD_IDENTITY)).toBe(false);
18
+ });
19
+ await it('rejects an untrusted chain even when the name matches', async () => {
20
+ expect(acceptsForServername(UNKNOWN_CA | BAD_IDENTITY, 0, BAD_IDENTITY)).toBe(false);
21
+ expect(acceptsForServername(UNKNOWN_CA, 0, BAD_IDENTITY)).toBe(false);
22
+ });
23
+ await it('rejects an expired or revoked cert even when the name matches', async () => {
24
+ expect(acceptsForServername(EXPIRED | BAD_IDENTITY, 0, BAD_IDENTITY)).toBe(false);
25
+ expect(acceptsForServername(REVOKED | BAD_IDENTITY, 0, BAD_IDENTITY)).toBe(false);
26
+ });
27
+ await it('rejects when libsoup reported no error at all (nothing to forgive, not this handler’s case)', async () => {
28
+ expect(acceptsForServername(0, 0, BAD_IDENTITY)).toBe(false);
29
+ });
30
+ });
31
+ };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Verdict for a request that connects to one host but verifies the peer certificate against
3
+ * another name (`servername`, as Node's `tls.connect({ servername })` / curl `--resolve`).
4
+ *
5
+ * `errors` are the flags libsoup reports for the connection (it verifies the chain against the
6
+ * system CA and the URL host as identity); `nameErrors` are the flags from verifying the same
7
+ * certificate against `servername`. Accept ONLY when the URL host was the sole problem
8
+ * (`errors === badIdentity`: chain, expiry and revocation are fine) and the certificate does name
9
+ * `servername`. Any other flag, or a name mismatch, rejects — fail closed.
10
+ */
11
+ export declare function acceptsForServername(errors: number, nameErrors: number, badIdentity: number): boolean;
@@ -0,0 +1,14 @@
1
+ // SPDX-License-Identifier: MIT
2
+ /**
3
+ * Verdict for a request that connects to one host but verifies the peer certificate against
4
+ * another name (`servername`, as Node's `tls.connect({ servername })` / curl `--resolve`).
5
+ *
6
+ * `errors` are the flags libsoup reports for the connection (it verifies the chain against the
7
+ * system CA and the URL host as identity); `nameErrors` are the flags from verifying the same
8
+ * certificate against `servername`. Accept ONLY when the URL host was the sole problem
9
+ * (`errors === badIdentity`: chain, expiry and revocation are fine) and the certificate does name
10
+ * `servername`. Any other flag, or a name mismatch, rejects — fail closed.
11
+ */
12
+ export function acceptsForServername(errors, nameErrors, badIdentity) {
13
+ return errors === badIdentity && (nameErrors & badIdentity) === 0;
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/fetch",
3
- "version": "0.64.40",
3
+ "version": "0.64.41",
4
4
  "description": "Web and Node.js fetch module for Gjs",
5
5
  "module": "lib/esm/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -51,9 +51,9 @@
51
51
  "fetch"
52
52
  ],
53
53
  "devDependencies": {
54
- "@gjsify/abort-controller": "^0.64.40",
55
- "@gjsify/cli": "^0.64.40",
56
- "@gjsify/unit": "^0.64.40",
54
+ "@gjsify/abort-controller": "^0.64.41",
55
+ "@gjsify/cli": "^0.64.41",
56
+ "@gjsify/unit": "^0.64.41",
57
57
  "@types/node": "^25.9.2",
58
58
  "typescript": "^6.0.3"
59
59
  },
@@ -62,11 +62,11 @@
62
62
  "@girs/gjs": "5.4.0",
63
63
  "@girs/glib-2.0": "5.4.0",
64
64
  "@girs/soup-3.0": "5.4.0",
65
- "@gjsify/dom-events": "^0.64.40",
66
- "@gjsify/formdata": "^0.64.40",
67
- "@gjsify/http": "^0.64.40",
68
- "@gjsify/url": "^0.64.40",
69
- "@gjsify/utils": "^0.64.40"
65
+ "@gjsify/dom-events": "^0.64.41",
66
+ "@gjsify/formdata": "^0.64.41",
67
+ "@gjsify/http": "^0.64.41",
68
+ "@gjsify/url": "^0.64.41",
69
+ "@gjsify/utils": "^0.64.41"
70
70
  },
71
71
  "gjsify": {
72
72
  "runtimes": {