@oxyhq/core 3.9.1 → 3.10.1

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.
Files changed (54) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/i18n/locales/en-US.json +9 -0
  3. package/dist/cjs/i18n/locales/es-ES.json +9 -0
  4. package/dist/cjs/i18n/locales/locales/en-US.json +9 -0
  5. package/dist/cjs/i18n/locales/locales/es-ES.json +9 -0
  6. package/dist/cjs/index.js +2 -3
  7. package/dist/cjs/mixins/OxyServices.assets.js +29 -6
  8. package/dist/cjs/mixins/OxyServices.utility.js +52 -23
  9. package/dist/cjs/server/cors.js +155 -0
  10. package/dist/cjs/server/index.js +21 -1
  11. package/dist/cjs/server/safeFetch.js +458 -0
  12. package/dist/cjs/server/verifySecret.js +50 -0
  13. package/dist/cjs/utils/fapiAutoDetect.js +12 -42
  14. package/dist/esm/.tsbuildinfo +1 -1
  15. package/dist/esm/i18n/locales/en-US.json +9 -0
  16. package/dist/esm/i18n/locales/es-ES.json +9 -0
  17. package/dist/esm/i18n/locales/locales/en-US.json +9 -0
  18. package/dist/esm/i18n/locales/locales/es-ES.json +9 -0
  19. package/dist/esm/index.js +1 -1
  20. package/dist/esm/mixins/OxyServices.assets.js +29 -6
  21. package/dist/esm/mixins/OxyServices.utility.js +52 -23
  22. package/dist/esm/server/cors.js +152 -0
  23. package/dist/esm/server/index.js +6 -0
  24. package/dist/esm/server/safeFetch.js +447 -0
  25. package/dist/esm/server/verifySecret.js +47 -0
  26. package/dist/esm/utils/fapiAutoDetect.js +12 -41
  27. package/dist/types/.tsbuildinfo +1 -1
  28. package/dist/types/index.d.ts +1 -1
  29. package/dist/types/mixins/OxyServices.assets.d.ts +6 -1
  30. package/dist/types/mixins/OxyServices.utility.d.ts +3 -3
  31. package/dist/types/server/cors.d.ts +57 -0
  32. package/dist/types/server/index.d.ts +5 -0
  33. package/dist/types/server/safeFetch.d.ts +135 -0
  34. package/dist/types/server/verifySecret.d.ts +29 -0
  35. package/dist/types/utils/fapiAutoDetect.d.ts +6 -23
  36. package/package.json +2 -1
  37. package/src/__tests__/authSocket.test.ts +96 -0
  38. package/src/i18n/locales/en-US.json +9 -0
  39. package/src/i18n/locales/es-ES.json +9 -0
  40. package/src/index.ts +1 -1
  41. package/src/mixins/OxyServices.assets.ts +40 -6
  42. package/src/mixins/OxyServices.utility.ts +57 -23
  43. package/src/mixins/__tests__/assetUpload.test.ts +191 -0
  44. package/src/mixins/__tests__/getFileDownloadUrl.test.ts +13 -0
  45. package/src/mixins/__tests__/serviceAuth.test.ts +30 -2
  46. package/src/server/__tests__/cors.test.ts +144 -0
  47. package/src/server/__tests__/safeFetch.test.ts +232 -0
  48. package/src/server/__tests__/verifySecret.test.ts +40 -0
  49. package/src/server/cors.ts +195 -0
  50. package/src/server/index.ts +30 -0
  51. package/src/server/safeFetch.ts +581 -0
  52. package/src/server/verifySecret.ts +52 -0
  53. package/src/utils/__tests__/fapiAutoDetect.test.ts +40 -11
  54. package/src/utils/fapiAutoDetect.ts +12 -39
@@ -6,8 +6,8 @@
6
6
  * one subdomain over.
7
7
  *
8
8
  * Ported verbatim from packages/auth-sdk/__tests__/utils/fapiAutoDetect.test.ts
9
- * plus multi-part-TLD bail-out cases that are unique to the core copy's
10
- * MULTIPART_TLDS guard.
9
+ * plus Public Suffix List regression cases that are unique to the core
10
+ * implementation's registrable-apex guard.
11
11
  */
12
12
 
13
13
  import { autoDetectAuthWebUrl, registrableApex } from '../fapiAutoDetect';
@@ -81,13 +81,28 @@ describe('autoDetectAuthWebUrl', () => {
81
81
  });
82
82
  });
83
83
 
84
- describe('bails out on multi-part public suffixes (would derive an attacker-registrable apex)', () => {
85
- it('does not derive auth.co.uk from a two-label co.uk host', () => {
86
- expect(autoDetectAuthWebUrl(loc('foo.co.uk'))).toBeUndefined();
84
+ describe('uses the Public Suffix List for registrable apex detection', () => {
85
+ it('derives from the registrable domain under multi-part public suffixes', () => {
86
+ expect(autoDetectAuthWebUrl(loc('foo.co.uk'))).toBe('https://auth.foo.co.uk');
87
+ expect(autoDetectAuthWebUrl(loc('shop.com.au'))).toBe('https://auth.shop.com.au');
88
+ expect(autoDetectAuthWebUrl(loc('shop.victim.com.tr'))).toBe('https://auth.victim.com.tr');
87
89
  });
88
90
 
89
- it('does not derive auth.com.au from a two-label com.au host', () => {
90
- expect(autoDetectAuthWebUrl(loc('shop.com.au'))).toBeUndefined();
91
+ it('derives from the registrable domain under private hosted suffixes', () => {
92
+ expect(autoDetectAuthWebUrl(loc('honest.github.io'))).toBe('https://auth.honest.github.io');
93
+ expect(autoDetectAuthWebUrl(loc('app.victim.pages.dev'))).toBe(
94
+ 'https://auth.victim.pages.dev'
95
+ );
96
+ expect(autoDetectAuthWebUrl(loc('site.victim.netlify.app'))).toBe(
97
+ 'https://auth.victim.netlify.app'
98
+ );
99
+ });
100
+
101
+ it('returns undefined for bare public and private suffixes', () => {
102
+ expect(autoDetectAuthWebUrl(loc('co.uk'))).toBeUndefined();
103
+ expect(autoDetectAuthWebUrl(loc('github.io'))).toBeUndefined();
104
+ expect(autoDetectAuthWebUrl(loc('pages.dev'))).toBeUndefined();
105
+ expect(autoDetectAuthWebUrl(loc('netlify.app'))).toBeUndefined();
91
106
  });
92
107
  });
93
108
 
@@ -105,7 +120,7 @@ describe('autoDetectAuthWebUrl', () => {
105
120
  ['[::1]', undefined],
106
121
  ['intranet', undefined],
107
122
  ['', undefined],
108
- ['foo.co.uk', undefined],
123
+ ['foo.co.uk', 'https://auth.foo.co.uk'],
109
124
  ];
110
125
  it.each(cases)('autoDetectAuthWebUrl(%s) === %s', (hostname, expected) => {
111
126
  const protocol = hostname === 'localhost' || hostname === '[::1]' ? 'http:' : 'https:';
@@ -128,9 +143,23 @@ describe('registrableApex', () => {
128
143
  expect(registrableApex('WWW.Mention.EARTH')).toBe('mention.earth');
129
144
  });
130
145
 
131
- it('returns null for a multi-part public suffix (foo.co.uk -> null)', () => {
132
- expect(registrableApex('foo.co.uk')).toBeNull();
133
- expect(registrableApex('shop.com.au')).toBeNull();
146
+ it('returns the eTLD+1 for hosts under multi-part public suffixes', () => {
147
+ expect(registrableApex('foo.co.uk')).toBe('foo.co.uk');
148
+ expect(registrableApex('www.foo.co.uk')).toBe('foo.co.uk');
149
+ expect(registrableApex('shop.victim.com.tr')).toBe('victim.com.tr');
150
+ });
151
+
152
+ it('returns the eTLD+1 for hosts under private hosted suffixes', () => {
153
+ expect(registrableApex('honest.github.io')).toBe('honest.github.io');
154
+ expect(registrableApex('app.victim.pages.dev')).toBe('victim.pages.dev');
155
+ expect(registrableApex('site.victim.netlify.app')).toBe('victim.netlify.app');
156
+ });
157
+
158
+ it('returns null for bare public and private suffixes', () => {
159
+ expect(registrableApex('co.uk')).toBeNull();
160
+ expect(registrableApex('github.io')).toBeNull();
161
+ expect(registrableApex('pages.dev')).toBeNull();
162
+ expect(registrableApex('netlify.app')).toBeNull();
134
163
  });
135
164
 
136
165
  it('returns null for IPv4 literals', () => {
@@ -20,10 +20,9 @@
20
20
  * - SSR / non-browser (no `window`).
21
21
  * - `localhost`, `127.0.0.1`, IPv4/IPv6 literals.
22
22
  * - Hostnames with fewer than two labels.
23
- * - Hostnames whose trailing two labels form a known multi-part public
24
- * suffix (e.g. `co.uk`), where the naive `labels.slice(-2)` apex would be
25
- * an attacker-registrable suffix like `auth.co.uk` rather than the real
26
- * registrable domain.
23
+ * - Hostnames where a registrable domain cannot be determined from the
24
+ * Public Suffix List, including private hosted suffixes such as
25
+ * `github.io`, `pages.dev`, and `netlify.app`.
27
26
  *
28
27
  * When the page is already loaded ON the IdP itself (`auth.<anything>`),
29
28
  * the helper returns the current origin so the SDK keeps everything
@@ -35,34 +34,11 @@
35
34
  * is required for end-to-end FedCM correctness — no per-RP config.
36
35
  */
37
36
 
38
- /**
39
- * Known multi-part public suffixes where the registrable domain is the LAST
40
- * THREE labels, not two. Deriving an apex from `labels.slice(-2)` against any
41
- * of these would yield an attacker-registrable suffix (e.g. `auth.co.uk`),
42
- * so we bail out instead.
43
- *
44
- * This is intentionally a small, explicit allow-list rather than the full
45
- * Public Suffix List — it covers the suffixes the Oxy ecosystem's RPs use.
46
- * Any multi-part-TLD RP MUST extend this set (or wire in a proper PSL check)
47
- * before relying on this helper, otherwise auto-detection silently bails to
48
- * `undefined` and the consumer must pass `authWebUrl` explicitly.
49
- */
50
- export const MULTIPART_TLDS: ReadonlySet<string> = new Set([
51
- 'co.uk',
52
- 'com.au',
53
- 'co.jp',
54
- 'co.nz',
55
- 'com.br',
56
- 'co.za',
57
- 'com.mx',
58
- 'co.in',
59
- 'co.kr',
60
- 'com.sg',
61
- ]);
37
+ import { getDomain } from 'tldts';
62
38
 
63
39
  /**
64
- * Compute the bare registrable apex (eTLD+1) of a hostname, guarding against
65
- * multi-part public suffixes.
40
+ * Compute the bare registrable apex (eTLD+1) of a hostname using the Public
41
+ * Suffix List, including private hosted suffixes.
66
42
  *
67
43
  * This is the pure host-handling kernel shared by {@link autoDetectAuthWebUrl}
68
44
  * and the IdP worker — it performs NO protocol handling, NO `auth.` prefixing,
@@ -74,10 +50,7 @@ export const MULTIPART_TLDS: ReadonlySet<string> = new Set([
74
50
  * - IPv4 literals (`192.168.1.10`);
75
51
  * - IPv6 literals or any host carrying a port (`[::1]`, anything with `:`);
76
52
  * - single-label hosts (`intranet`, `localhost`);
77
- * - hosts whose trailing two labels form a known multi-part public suffix
78
- * (e.g. `foo.co.uk`), where `labels.slice(-2)` would yield an
79
- * attacker-registrable suffix (`co.uk`) rather than a real registrable
80
- * domain. Such hosts MUST configure `authWebUrl` explicitly.
53
+ * - public suffixes without a registrable label (e.g. `co.uk`, `github.io`).
81
54
  *
82
55
  * @param hostname - A bare hostname (no scheme), e.g. `www.mention.earth`.
83
56
  * @returns The eTLD+1 (`mention.earth`), or `null` when undefinable.
@@ -89,11 +62,11 @@ export function registrableApex(hostname: string): string | null {
89
62
  // IPv6 literals are bracketed; any remaining ':' implies a port — neither
90
63
  // yields a registrable apex.
91
64
  if (host.startsWith('[') || host.includes(':')) return null;
92
- const labels = host.split('.');
93
- if (labels.length < 2) return null;
94
- const lastTwo = labels.slice(-2).join('.');
95
- if (MULTIPART_TLDS.has(lastTwo)) return null;
96
- return lastTwo;
65
+ // The Public Suffix List (private suffixes included) is the source of truth
66
+ // for what an attacker can register. A multi-part public suffix like `co.uk`
67
+ // or a hosted suffix like `github.io` returns no registrable domain, so
68
+ // deriving `auth.<apex>` against it is impossible — `getDomain` returns null.
69
+ return getDomain(host, { allowPrivateDomains: true });
97
70
  }
98
71
 
99
72
  export function autoDetectAuthWebUrl(