@oxyhq/core 3.10.0 → 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.
- package/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/i18n/locales/en-US.json +9 -0
- package/dist/cjs/i18n/locales/es-ES.json +9 -0
- package/dist/cjs/i18n/locales/locales/en-US.json +9 -0
- package/dist/cjs/i18n/locales/locales/es-ES.json +9 -0
- package/dist/cjs/index.js +2 -3
- package/dist/cjs/mixins/OxyServices.assets.js +29 -6
- package/dist/cjs/mixins/OxyServices.utility.js +52 -23
- package/dist/cjs/utils/fapiAutoDetect.js +12 -42
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/i18n/locales/en-US.json +9 -0
- package/dist/esm/i18n/locales/es-ES.json +9 -0
- package/dist/esm/i18n/locales/locales/en-US.json +9 -0
- package/dist/esm/i18n/locales/locales/es-ES.json +9 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/mixins/OxyServices.assets.js +29 -6
- package/dist/esm/mixins/OxyServices.utility.js +52 -23
- package/dist/esm/utils/fapiAutoDetect.js +12 -41
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/mixins/OxyServices.assets.d.ts +6 -1
- package/dist/types/mixins/OxyServices.utility.d.ts +3 -3
- package/dist/types/utils/fapiAutoDetect.d.ts +6 -23
- package/package.json +2 -1
- package/src/__tests__/authSocket.test.ts +96 -0
- package/src/i18n/locales/en-US.json +9 -0
- package/src/i18n/locales/es-ES.json +9 -0
- package/src/index.ts +1 -1
- package/src/mixins/OxyServices.assets.ts +40 -6
- package/src/mixins/OxyServices.utility.ts +57 -23
- package/src/mixins/__tests__/assetUpload.test.ts +191 -0
- package/src/mixins/__tests__/getFileDownloadUrl.test.ts +13 -0
- package/src/mixins/__tests__/serviceAuth.test.ts +30 -2
- package/src/utils/__tests__/fapiAutoDetect.test.ts +40 -11
- package/src/utils/fapiAutoDetect.ts +12 -39
|
@@ -672,9 +672,9 @@ describe('requireScope() middleware', () => {
|
|
|
672
672
|
expect(res.headersSent).toBe(false);
|
|
673
673
|
});
|
|
674
674
|
|
|
675
|
-
it('allows requests
|
|
675
|
+
it('allows delegated requests only when both app and delegation carry the required scope', () => {
|
|
676
676
|
const req = makeReq();
|
|
677
|
-
req.serviceApp = { appId: 'a', appName: 'svc', credentialId: 'cred-1', scopes: [] };
|
|
677
|
+
req.serviceApp = { appId: 'a', appName: 'svc', credentialId: 'cred-1', scopes: ['user:read'] };
|
|
678
678
|
req.serviceActingAs = { userId: 'u-1', scopes: ['user:read'] };
|
|
679
679
|
const res = makeRes();
|
|
680
680
|
const next = jest.fn();
|
|
@@ -684,6 +684,34 @@ describe('requireScope() middleware', () => {
|
|
|
684
684
|
expect(next).toHaveBeenCalledTimes(1);
|
|
685
685
|
});
|
|
686
686
|
|
|
687
|
+
it('rejects delegated requests when only the app carries the required scope', () => {
|
|
688
|
+
const req = makeReq();
|
|
689
|
+
req.serviceApp = { appId: 'a', appName: 'svc', credentialId: 'cred-1', scopes: ['files:write'] };
|
|
690
|
+
req.serviceActingAs = { userId: 'u-1', scopes: ['profile:read'] };
|
|
691
|
+
const res = makeRes();
|
|
692
|
+
const next = jest.fn();
|
|
693
|
+
|
|
694
|
+
oxy.requireScope('files:write')(req as unknown as never, res as unknown as never, next as unknown as never);
|
|
695
|
+
|
|
696
|
+
expect(next).not.toHaveBeenCalled();
|
|
697
|
+
expect(res.statusCode).toBe(403);
|
|
698
|
+
expect(res.body).toMatchObject({ code: 'INSUFFICIENT_SCOPE' });
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
it('rejects delegated requests when only the delegation carries the required scope', () => {
|
|
702
|
+
const req = makeReq();
|
|
703
|
+
req.serviceApp = { appId: 'a', appName: 'svc', credentialId: 'cred-1', scopes: ['profile:read'] };
|
|
704
|
+
req.serviceActingAs = { userId: 'u-1', scopes: ['files:write'] };
|
|
705
|
+
const res = makeRes();
|
|
706
|
+
const next = jest.fn();
|
|
707
|
+
|
|
708
|
+
oxy.requireScope('files:write')(req as unknown as never, res as unknown as never, next as unknown as never);
|
|
709
|
+
|
|
710
|
+
expect(next).not.toHaveBeenCalled();
|
|
711
|
+
expect(res.statusCode).toBe(403);
|
|
712
|
+
expect(res.body).toMatchObject({ code: 'INSUFFICIENT_SCOPE' });
|
|
713
|
+
});
|
|
714
|
+
|
|
687
715
|
it('rejects requests missing the required scope with 403', () => {
|
|
688
716
|
const req = makeReq();
|
|
689
717
|
req.serviceApp = { appId: 'a', appName: 'svc', credentialId: 'cred-1', scopes: ['user:read'] };
|
|
@@ -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
|
|
10
|
-
*
|
|
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('
|
|
85
|
-
it('
|
|
86
|
-
expect(autoDetectAuthWebUrl(loc('foo.co.uk'))).
|
|
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('
|
|
90
|
-
expect(autoDetectAuthWebUrl(loc('
|
|
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',
|
|
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
|
|
132
|
-
expect(registrableApex('foo.co.uk')).
|
|
133
|
-
expect(registrableApex('
|
|
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
|
|
24
|
-
*
|
|
25
|
-
*
|
|
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
|
|
65
|
-
*
|
|
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
|
-
* -
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return
|
|
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(
|