@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
|
@@ -129,6 +129,15 @@
|
|
|
129
129
|
"title": "Reputation = Trust & Growth",
|
|
130
130
|
"body": "Oxy Trust is a reputation system that reacts to what you do. Helpful, respectful, constructive actions earn it. Harmful or low‑effort stuff chips it away. More reputation can unlock benefits; low reputation can limit features. It keeps things fair and rewards real contribution."
|
|
131
131
|
},
|
|
132
|
+
"name": {
|
|
133
|
+
"title": "What's your name?",
|
|
134
|
+
"body": "Add your name so people know who you are.",
|
|
135
|
+
"firstLabel": "First name",
|
|
136
|
+
"firstPlaceholder": "Your first name",
|
|
137
|
+
"lastLabel": "Last name",
|
|
138
|
+
"lastPlaceholder": "Your last name",
|
|
139
|
+
"saveFailed": "Could not save your name"
|
|
140
|
+
},
|
|
132
141
|
"avatar": {
|
|
133
142
|
"title": "Make It Yours",
|
|
134
143
|
"body": "Add an avatar so people recognize you. It will show anywhere you show up here. Skip if you want — you can add it later.",
|
|
@@ -849,6 +849,15 @@
|
|
|
849
849
|
"title": "Reputación = Confianza y crecimiento",
|
|
850
850
|
"body": "Oxy Trust es un sistema de reputación que reacciona a lo que haces. Las acciones útiles, respetuosas y constructivas la aumentan. Las acciones dañinas o de poco esfuerzo la reducen. Más reputación puede desbloquear beneficios; poca reputación puede limitar funciones. Mantiene la justicia y recompensa la contribución real."
|
|
851
851
|
},
|
|
852
|
+
"name": {
|
|
853
|
+
"title": "¿Cuál es tu nombre?",
|
|
854
|
+
"body": "Añade tu nombre para que la gente sepa quién eres.",
|
|
855
|
+
"firstLabel": "Nombre",
|
|
856
|
+
"firstPlaceholder": "Tu nombre",
|
|
857
|
+
"lastLabel": "Apellidos",
|
|
858
|
+
"lastPlaceholder": "Tus apellidos",
|
|
859
|
+
"saveFailed": "No se pudo guardar tu nombre"
|
|
860
|
+
},
|
|
852
861
|
"avatar": {
|
|
853
862
|
"title": "Hazlo tuyo",
|
|
854
863
|
"body": "Añade un avatar para que te reconozcan. Se mostrará donde aparezcas aquí. Puedes omitirlo — puedes añadirlo más tarde.",
|
|
@@ -129,6 +129,15 @@
|
|
|
129
129
|
"title": "Reputation = Trust & Growth",
|
|
130
130
|
"body": "Oxy Trust is a reputation system that reacts to what you do. Helpful, respectful, constructive actions earn it. Harmful or low‑effort stuff chips it away. More reputation can unlock benefits; low reputation can limit features. It keeps things fair and rewards real contribution."
|
|
131
131
|
},
|
|
132
|
+
"name": {
|
|
133
|
+
"title": "What's your name?",
|
|
134
|
+
"body": "Add your name so people know who you are.",
|
|
135
|
+
"firstLabel": "First name",
|
|
136
|
+
"firstPlaceholder": "Your first name",
|
|
137
|
+
"lastLabel": "Last name",
|
|
138
|
+
"lastPlaceholder": "Your last name",
|
|
139
|
+
"saveFailed": "Could not save your name"
|
|
140
|
+
},
|
|
132
141
|
"avatar": {
|
|
133
142
|
"title": "Make It Yours",
|
|
134
143
|
"body": "Add an avatar so people recognize you. It will show anywhere you show up here. Skip if you want — you can add it later.",
|
|
@@ -849,6 +849,15 @@
|
|
|
849
849
|
"title": "Reputación = Confianza y crecimiento",
|
|
850
850
|
"body": "Oxy Trust es un sistema de reputación que reacciona a lo que haces. Las acciones útiles, respetuosas y constructivas la aumentan. Las acciones dañinas o de poco esfuerzo la reducen. Más reputación puede desbloquear beneficios; poca reputación puede limitar funciones. Mantiene la justicia y recompensa la contribución real."
|
|
851
851
|
},
|
|
852
|
+
"name": {
|
|
853
|
+
"title": "¿Cuál es tu nombre?",
|
|
854
|
+
"body": "Añade tu nombre para que la gente sepa quién eres.",
|
|
855
|
+
"firstLabel": "Nombre",
|
|
856
|
+
"firstPlaceholder": "Tu nombre",
|
|
857
|
+
"lastLabel": "Apellidos",
|
|
858
|
+
"lastPlaceholder": "Tus apellidos",
|
|
859
|
+
"saveFailed": "No se pudo guardar tu nombre"
|
|
860
|
+
},
|
|
852
861
|
"avatar": {
|
|
853
862
|
"title": "Hazlo tuyo",
|
|
854
863
|
"body": "Añade un avatar para que te reconozcan. Se mostrará donde aparezcas aquí. Puedes omitirlo — puedes añadirlo más tarde.",
|
package/dist/cjs/index.js
CHANGED
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
21
|
exports.rgbToHex = exports.hexToRgb = exports.lightenColor = exports.darkenColor = exports.isAndroid = exports.isIOS = exports.isNative = exports.isWeb = exports.setPlatformOS = exports.getPlatformOS = exports.isRTLLocale = exports.normalizeLanguageCode = exports.getNativeLanguageName = exports.getLanguageName = exports.getLanguageMetadata = exports.SUPPORTED_LANGUAGES = exports.TopicSource = exports.TopicType = exports.SECURITY_EVENT_SEVERITY_MAP = exports.DeviceManager = exports.RecoveryPhraseService = exports.SignatureService = exports.IdentityPersistError = exports.IdentityAlreadyExistsError = exports.KeyManager = exports.sessionsArraysEqual = exports.normalizeAndSortSessions = exports.mergeSessions = exports.authenticatedApiCall = exports.withAuthErrorHandling = exports.isAuthenticationError = exports.ensureValidToken = exports.AuthenticationFailedError = exports.SessionSyncRequiredError = exports.getNormalizedUserHandle = exports.getCanonicalUserHandle = exports.normalizeUserIdentityOrNull = exports.normalizeUserIdentity = exports.getNormalizedUserId = exports.OxyAppDataIdentifierError = exports.ServiceCredentialMismatchError = exports.createCrossDomainAuth = exports.CrossDomainAuth = exports.createAuthManager = exports.AuthManager = exports.oxyClient = exports.OXY_CLOUD_URL = exports.OxyAuthenticationTimeoutError = exports.OxyAuthenticationError = exports.OxyServices = void 0;
|
|
22
22
|
exports.isRequiredNumber = exports.isRequiredString = exports.isValidPassword = exports.isValidUsername = exports.isValidEmail = exports.PASSWORD_REGEX = exports.USERNAME_REGEX = exports.EMAIL_REGEX = exports.retryAsync = exports.validateRequiredFields = exports.handleHttpError = exports.createApiError = exports.ErrorCodes = exports.safeJsonParse = exports.buildPaginationParams = exports.buildUrl = exports.buildSearchParams = exports.translate = exports.createDebugLogger = exports.debugError = exports.debugWarn = exports.debugLog = exports.isDev = exports.withRetry = exports.delay = exports.shouldAllowRequest = exports.recordSuccess = exports.recordFailure = exports.calculateBackoffInterval = exports.createCircuitBreakerState = exports.DEFAULT_CIRCUIT_BREAKER_CONFIG = exports.isRetryableError = exports.isNetworkError = exports.isServerError = exports.isRateLimitError = exports.isNotFoundError = exports.isForbiddenError = exports.isUnauthorizedError = exports.isAlreadyRegisteredError = exports.getErrorMessage = exports.getErrorStatus = exports.HttpStatus = exports.getSystemColorScheme = exports.systemPrefersDarkMode = exports.getOppositeTheme = exports.normalizeColorScheme = exports.normalizeTheme = exports.getContrastTextColor = exports.isLightColor = exports.withOpacity = void 0;
|
|
23
|
-
exports.isCentralIdPOrigin = exports.buildSsoBounceUrl = exports.getSsoCallbackBootstrapScript = exports.ssoNavigate = exports.ssoCallbackBootstrapKey = exports.ssoAttemptedKey = exports.ssoNoSessionKey = exports.ssoDestKey = exports.ssoGuardKey = exports.ssoStateKey = exports.SSO_GUARD_TTL_MS = exports.SSO_CALLBACK_PATH = exports.generateSsoState = exports.consumeSsoReturn = exports.parseSsoReturnFragment = exports.resolveCentralAuthUrl = exports.CENTRAL_IDP_APEX = exports.CENTRAL_AUTH_URL = exports.
|
|
24
|
-
exports.packageInfo = exports.runColdBoot =
|
|
23
|
+
exports.guardActive = exports.isCentralIdPOrigin = exports.buildSsoBounceUrl = exports.getSsoCallbackBootstrapScript = exports.ssoNavigate = exports.ssoCallbackBootstrapKey = exports.ssoAttemptedKey = exports.ssoNoSessionKey = exports.ssoDestKey = exports.ssoGuardKey = exports.ssoStateKey = exports.SSO_GUARD_TTL_MS = exports.SSO_CALLBACK_PATH = exports.generateSsoState = exports.consumeSsoReturn = exports.parseSsoReturnFragment = exports.resolveCentralAuthUrl = exports.CENTRAL_IDP_APEX = exports.CENTRAL_AUTH_URL = exports.registrableApex = exports.autoDetectAuthWebUrl = exports.getAccountColor = exports.mergeAccountsFromRefreshAll = exports.formatPublicKeyHandle = exports.getAccountFallbackHandle = exports.getAccountDisplayName = exports.createQuickAccount = exports.buildAccountsArray = exports.updateAvatarVisibility = exports.logPerformance = exports.logPayment = exports.logDevice = exports.logUser = exports.logSession = exports.logApi = exports.logAuth = exports.LogLevel = exports.logger = exports.validateAndSanitizeUserInput = exports.isValidObjectId = exports.sanitizeHTML = exports.sanitizeString = exports.isValidFileType = exports.isValidFileSize = exports.isValidDate = exports.isValidURL = exports.isValidUUID = exports.isValidObject = exports.isValidArray = exports.isRequiredBoolean = void 0;
|
|
24
|
+
exports.packageInfo = exports.runColdBoot = void 0;
|
|
25
25
|
// Ensure crypto polyfills are loaded before anything else
|
|
26
26
|
require("./crypto/polyfill");
|
|
27
27
|
// ---------------------------------------------------------------------------
|
|
@@ -242,7 +242,6 @@ Object.defineProperty(exports, "getAccountColor", { enumerable: true, get: funct
|
|
|
242
242
|
var fapiAutoDetect_1 = require("./utils/fapiAutoDetect");
|
|
243
243
|
Object.defineProperty(exports, "autoDetectAuthWebUrl", { enumerable: true, get: function () { return fapiAutoDetect_1.autoDetectAuthWebUrl; } });
|
|
244
244
|
Object.defineProperty(exports, "registrableApex", { enumerable: true, get: function () { return fapiAutoDetect_1.registrableApex; } });
|
|
245
|
-
Object.defineProperty(exports, "MULTIPART_TLDS", { enumerable: true, get: function () { return fapiAutoDetect_1.MULTIPART_TLDS; } });
|
|
246
245
|
// Central cross-domain SSO (opaque single-use code bounce via auth.oxy.so)
|
|
247
246
|
var authWebUrl_1 = require("./utils/authWebUrl");
|
|
248
247
|
Object.defineProperty(exports, "CENTRAL_AUTH_URL", { enumerable: true, get: function () { return authWebUrl_1.CENTRAL_AUTH_URL; } });
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OxyServicesAssetsMixin = OxyServicesAssetsMixin;
|
|
4
|
+
const platform_1 = require("../utils/platform");
|
|
4
5
|
function OxyServicesAssetsMixin(Base) {
|
|
5
6
|
return class extends Base {
|
|
6
7
|
constructor(...args) {
|
|
@@ -43,8 +44,8 @@ function OxyServicesAssetsMixin(Base) {
|
|
|
43
44
|
*
|
|
44
45
|
* For a CDN-signed URL fetched from the API, use {@link getFileDownloadUrlAsync}.
|
|
45
46
|
*/
|
|
46
|
-
getFileDownloadUrl(fileId, variant, expiresIn) {
|
|
47
|
-
const token = this.getClient().getAccessToken();
|
|
47
|
+
getFileDownloadUrl(fileId, variant, expiresIn, options = {}) {
|
|
48
|
+
const token = options.omitToken ? undefined : this.getClient().getAccessToken();
|
|
48
49
|
// Public case: no auth token and no expiry requested → clean CDN URL.
|
|
49
50
|
// CloudFront serves the public media origin under `${cloudURL}/<id>`.
|
|
50
51
|
if (!token && !expiresIn) {
|
|
@@ -192,10 +193,32 @@ function OxyServicesAssetsMixin(Base) {
|
|
|
192
193
|
formData.append('file', file, fileName);
|
|
193
194
|
}
|
|
194
195
|
else if ('uri' in file && typeof file.uri === 'string') {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
196
|
+
const descriptor = file;
|
|
197
|
+
if ((0, platform_1.isReactNative)()) {
|
|
198
|
+
// React Native file descriptor — RN's FormData handles {uri, type, name} natively.
|
|
199
|
+
// It reads the file from disk during the multipart request — no in-JS Blob
|
|
200
|
+
// conversion (which would fail on Hermes for ArrayBuffer-backed Blobs).
|
|
201
|
+
formData.append('file', descriptor, fileName);
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
// Web (browser/Node): the browser's FormData cannot read bytes from a plain
|
|
205
|
+
// { uri } object — it would serialize "[object Object]" and the server would
|
|
206
|
+
// store a 0-byte asset. Materialize the uri into a real Blob first. `fetch`
|
|
207
|
+
// resolves blob:, data:, and http(s): uris on web, so all picker outputs work.
|
|
208
|
+
const res = await fetch(descriptor.uri);
|
|
209
|
+
if (!res.ok) {
|
|
210
|
+
throw new Error(`Failed to read file from uri (status ${res.status})`);
|
|
211
|
+
}
|
|
212
|
+
const fetched = await res.blob();
|
|
213
|
+
// Preserve the descriptor's declared MIME type when the fetched blob has none.
|
|
214
|
+
const blob = fetched.type === '' && descriptor.type
|
|
215
|
+
? new Blob([fetched], { type: descriptor.type })
|
|
216
|
+
: fetched;
|
|
217
|
+
if (blob.size === 0) {
|
|
218
|
+
throw new Error('Cannot upload an empty file');
|
|
219
|
+
}
|
|
220
|
+
formData.append('file', blob, fileName);
|
|
221
|
+
}
|
|
199
222
|
}
|
|
200
223
|
else {
|
|
201
224
|
throw new Error('Unsupported file input: expected File, Blob, or { uri, type?, name?, size? } descriptor');
|
|
@@ -691,33 +691,45 @@ function OxyServicesUtilityMixin(Base) {
|
|
|
691
691
|
}
|
|
692
692
|
return next(new Error('Invalid token'));
|
|
693
693
|
}
|
|
694
|
-
const
|
|
695
|
-
if (!
|
|
694
|
+
const claimedUserId = decoded.userId || decoded.id;
|
|
695
|
+
if (!claimedUserId) {
|
|
696
696
|
return next(new Error('Invalid token payload'));
|
|
697
697
|
}
|
|
698
698
|
// Check expiration — reject tokens at exact expiry second (use <=)
|
|
699
699
|
if (decoded.exp && decoded.exp <= Math.floor(Date.now() / 1000)) {
|
|
700
700
|
return next(new Error('Token expired'));
|
|
701
701
|
}
|
|
702
|
-
//
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
702
|
+
// A server-validated session is mandatory. A bare decoded JWT proves
|
|
703
|
+
// nothing — the signature is not verified here, so without a session
|
|
704
|
+
// round-trip a forged token could claim any user id.
|
|
705
|
+
if (!decoded.sessionId) {
|
|
706
|
+
return next(new Error('Session required'));
|
|
707
|
+
}
|
|
708
|
+
let userId = claimedUserId;
|
|
709
|
+
try {
|
|
710
|
+
const result = await oxyInstance.validateSession(decoded.sessionId, {
|
|
711
|
+
useHeaderValidation: true,
|
|
712
|
+
});
|
|
713
|
+
if (!result || !result.valid || !result.user) {
|
|
714
|
+
return next(new Error('Session invalid'));
|
|
711
715
|
}
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
}
|
|
719
|
-
return next(new Error('Session validation failed'));
|
|
716
|
+
// The session is the source of truth. The client-claimed user id
|
|
717
|
+
// must match the server-validated identity, otherwise a valid
|
|
718
|
+
// session could be paired with a forged user id.
|
|
719
|
+
const validatedUserId = getUserIdentityId(result.user);
|
|
720
|
+
if (!validatedUserId || validatedUserId !== claimedUserId) {
|
|
721
|
+
return next(new Error('Session user mismatch'));
|
|
720
722
|
}
|
|
723
|
+
userId = validatedUserId;
|
|
724
|
+
}
|
|
725
|
+
catch (validateErr) {
|
|
726
|
+
if (debug) {
|
|
727
|
+
loggerUtils_1.logger.debug('[oxy.authSocket] Session validation failed', {
|
|
728
|
+
component: 'auth',
|
|
729
|
+
method: 'authSocket',
|
|
730
|
+
}, validateErr);
|
|
731
|
+
}
|
|
732
|
+
return next(new Error('Session validation failed'));
|
|
721
733
|
}
|
|
722
734
|
// Attach user data to socket. We expose BOTH `socket.data.userId`
|
|
723
735
|
// (the official Socket.IO data slot) and `socket.user` because
|
|
@@ -782,9 +794,9 @@ function OxyServicesUtilityMixin(Base) {
|
|
|
782
794
|
* Express.js middleware that enforces a specific service-token scope.
|
|
783
795
|
*
|
|
784
796
|
* Mount AFTER `auth()` / `serviceAuth()` — relies on `req.serviceApp` and
|
|
785
|
-
* (when delegation is in effect) `req.serviceActingAs.scopes`.
|
|
786
|
-
*
|
|
787
|
-
* the app
|
|
797
|
+
* (when delegation is in effect) `req.serviceActingAs.scopes`. App-only
|
|
798
|
+
* service requests require the app scope. Delegated user requests require
|
|
799
|
+
* BOTH the app scope and the per-user delegation scope.
|
|
788
800
|
*
|
|
789
801
|
* Requests authenticated as a regular user (no service token) are rejected
|
|
790
802
|
* with 403 — scope-protected endpoints are service-to-service by design.
|
|
@@ -814,7 +826,12 @@ function OxyServicesUtilityMixin(Base) {
|
|
|
814
826
|
});
|
|
815
827
|
return;
|
|
816
828
|
}
|
|
817
|
-
|
|
829
|
+
const appHasScope = appScopes.includes(scope);
|
|
830
|
+
const delegationHasScope = delegatedScopes.includes(scope);
|
|
831
|
+
const hasRequiredScope = req.serviceActingAs
|
|
832
|
+
? appHasScope && delegationHasScope
|
|
833
|
+
: appHasScope;
|
|
834
|
+
if (hasRequiredScope) {
|
|
818
835
|
next();
|
|
819
836
|
return;
|
|
820
837
|
}
|
|
@@ -872,6 +889,18 @@ async function verifyServiceTokenSignature(token, secret) {
|
|
|
872
889
|
* access token signed by the same shared secret could be replayed as a
|
|
873
890
|
* service token because no claim binding existed.
|
|
874
891
|
*/
|
|
892
|
+
/**
|
|
893
|
+
* Resolve the canonical user id from a validated session's user object.
|
|
894
|
+
*
|
|
895
|
+
* The API serializer emits `id`, but some upstream shapes carry the raw Mongo
|
|
896
|
+
* `_id` instead. We accept either, but only a non-empty string — anything else
|
|
897
|
+
* means the validated identity is unusable and the caller must reject.
|
|
898
|
+
*/
|
|
899
|
+
function getUserIdentityId(user) {
|
|
900
|
+
const candidate = user.id
|
|
901
|
+
?? user._id;
|
|
902
|
+
return typeof candidate === 'string' && candidate.length > 0 ? candidate : null;
|
|
903
|
+
}
|
|
875
904
|
function verifyServiceTokenClaims(decoded, expected) {
|
|
876
905
|
if (decoded.type !== 'service') {
|
|
877
906
|
throw new ServiceTokenClaimError(`Service token has unexpected type '${String(decoded.type)}'`);
|
|
@@ -21,10 +21,9 @@
|
|
|
21
21
|
* - SSR / non-browser (no `window`).
|
|
22
22
|
* - `localhost`, `127.0.0.1`, IPv4/IPv6 literals.
|
|
23
23
|
* - Hostnames with fewer than two labels.
|
|
24
|
-
* - Hostnames
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* registrable domain.
|
|
24
|
+
* - Hostnames where a registrable domain cannot be determined from the
|
|
25
|
+
* Public Suffix List, including private hosted suffixes such as
|
|
26
|
+
* `github.io`, `pages.dev`, and `netlify.app`.
|
|
28
27
|
*
|
|
29
28
|
* When the page is already loaded ON the IdP itself (`auth.<anything>`),
|
|
30
29
|
* the helper returns the current origin so the SDK keeps everything
|
|
@@ -36,36 +35,12 @@
|
|
|
36
35
|
* is required for end-to-end FedCM correctness — no per-RP config.
|
|
37
36
|
*/
|
|
38
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.MULTIPART_TLDS = void 0;
|
|
40
38
|
exports.registrableApex = registrableApex;
|
|
41
39
|
exports.autoDetectAuthWebUrl = autoDetectAuthWebUrl;
|
|
40
|
+
const tldts_1 = require("tldts");
|
|
42
41
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* of these would yield an attacker-registrable suffix (e.g. `auth.co.uk`),
|
|
46
|
-
* so we bail out instead.
|
|
47
|
-
*
|
|
48
|
-
* This is intentionally a small, explicit allow-list rather than the full
|
|
49
|
-
* Public Suffix List — it covers the suffixes the Oxy ecosystem's RPs use.
|
|
50
|
-
* Any multi-part-TLD RP MUST extend this set (or wire in a proper PSL check)
|
|
51
|
-
* before relying on this helper, otherwise auto-detection silently bails to
|
|
52
|
-
* `undefined` and the consumer must pass `authWebUrl` explicitly.
|
|
53
|
-
*/
|
|
54
|
-
exports.MULTIPART_TLDS = new Set([
|
|
55
|
-
'co.uk',
|
|
56
|
-
'com.au',
|
|
57
|
-
'co.jp',
|
|
58
|
-
'co.nz',
|
|
59
|
-
'com.br',
|
|
60
|
-
'co.za',
|
|
61
|
-
'com.mx',
|
|
62
|
-
'co.in',
|
|
63
|
-
'co.kr',
|
|
64
|
-
'com.sg',
|
|
65
|
-
]);
|
|
66
|
-
/**
|
|
67
|
-
* Compute the bare registrable apex (eTLD+1) of a hostname, guarding against
|
|
68
|
-
* multi-part public suffixes.
|
|
42
|
+
* Compute the bare registrable apex (eTLD+1) of a hostname using the Public
|
|
43
|
+
* Suffix List, including private hosted suffixes.
|
|
69
44
|
*
|
|
70
45
|
* This is the pure host-handling kernel shared by {@link autoDetectAuthWebUrl}
|
|
71
46
|
* and the IdP worker — it performs NO protocol handling, NO `auth.` prefixing,
|
|
@@ -77,10 +52,7 @@ exports.MULTIPART_TLDS = new Set([
|
|
|
77
52
|
* - IPv4 literals (`192.168.1.10`);
|
|
78
53
|
* - IPv6 literals or any host carrying a port (`[::1]`, anything with `:`);
|
|
79
54
|
* - single-label hosts (`intranet`, `localhost`);
|
|
80
|
-
* -
|
|
81
|
-
* (e.g. `foo.co.uk`), where `labels.slice(-2)` would yield an
|
|
82
|
-
* attacker-registrable suffix (`co.uk`) rather than a real registrable
|
|
83
|
-
* domain. Such hosts MUST configure `authWebUrl` explicitly.
|
|
55
|
+
* - public suffixes without a registrable label (e.g. `co.uk`, `github.io`).
|
|
84
56
|
*
|
|
85
57
|
* @param hostname - A bare hostname (no scheme), e.g. `www.mention.earth`.
|
|
86
58
|
* @returns The eTLD+1 (`mention.earth`), or `null` when undefinable.
|
|
@@ -95,13 +67,11 @@ function registrableApex(hostname) {
|
|
|
95
67
|
// yields a registrable apex.
|
|
96
68
|
if (host.startsWith('[') || host.includes(':'))
|
|
97
69
|
return null;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return null;
|
|
104
|
-
return lastTwo;
|
|
70
|
+
// The Public Suffix List (private suffixes included) is the source of truth
|
|
71
|
+
// for what an attacker can register. A multi-part public suffix like `co.uk`
|
|
72
|
+
// or a hosted suffix like `github.io` returns no registrable domain, so
|
|
73
|
+
// deriving `auth.<apex>` against it is impossible — `getDomain` returns null.
|
|
74
|
+
return (0, tldts_1.getDomain)(host, { allowPrivateDomains: true });
|
|
105
75
|
}
|
|
106
76
|
function autoDetectAuthWebUrl(location = typeof window !== 'undefined' ? window.location : undefined) {
|
|
107
77
|
if (!location)
|