Skip to content

Commit ac1f634

Browse files
fix(client): Normalize allowlist to origins (#321)
1 parent 7d9b130 commit ac1f634

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

cli/package-lock.json

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/tdf3/src/client/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,10 @@ export class Client {
271271
this.kasEndpoint = clientConfig.keyRewrapEndpoint.replace(/\/rewrap$/, '');
272272
}
273273

274+
const kasOrigin = new URL(this.kasEndpoint).origin;
274275
if (clientConfig.allowedKases) {
275-
this.allowedKases = [...clientConfig.allowedKases];
276-
if (!validateSecureUrl(this.kasEndpoint) && !this.allowedKases.includes(this.kasEndpoint)) {
276+
this.allowedKases = clientConfig.allowedKases.map((a) => new URL(a).origin);
277+
if (!validateSecureUrl(this.kasEndpoint) && !this.allowedKases.includes(kasOrigin)) {
277278
throw new TdfError(`Invalid KAS endpoint [${this.kasEndpoint}]`);
278279
}
279280
this.allowedKases.forEach(validateSecureUrl);
@@ -283,7 +284,7 @@ export class Client {
283284
`Invalid KAS endpoint [${this.kasEndpoint}]; to force, please list it among allowedKases`
284285
);
285286
}
286-
this.allowedKases = [this.kasEndpoint];
287+
this.allowedKases = [kasOrigin];
287288
}
288289

289290
this.authProvider = config.authProvider;

lib/tdf3/src/tdf.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export type EncryptConfiguration = {
145145
};
146146

147147
export type DecryptConfiguration = {
148+
// Normalized KAS origins to connect to
148149
allowedKases: string[];
149150
authProvider: AuthProvider | AppIdAuthProvider;
150151
cryptoService: CryptoService;
@@ -824,7 +825,8 @@ async function unwrapKey({
824825
// Get key access information to know the KAS URLS
825826
const rewrappedKeys = await Promise.all(
826827
keyAccess.map(async (keySplitInfo) => {
827-
if (!allowedKases.includes(keySplitInfo.url)) {
828+
const kaoOrigin = new URL(keySplitInfo.url).origin;
829+
if (!allowedKases.includes(kaoOrigin)) {
828830
throw new UnsafeUrlError(
829831
`cannot decrypt TDF: [${keySplitInfo.url}] not on allowlist ${JSON.stringify(
830832
allowedKases

0 commit comments

Comments
 (0)