@inrupt/solid-client-authn-browser 1.13.0 → 1.13.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inrupt/solid-client-authn-browser",
3
- "version": "1.13.0",
3
+ "version": "1.13.1",
4
4
  "license": "MIT",
5
5
  "types": "dist/index",
6
6
  "browser": "dist/index.js",
@@ -25,8 +25,8 @@
25
25
  "cross-fetch": "^3.1.5"
26
26
  },
27
27
  "dependencies": {
28
- "@inrupt/oidc-client-ext": "^1.13.0",
29
- "@inrupt/solid-client-authn-core": "^1.13.0",
28
+ "@inrupt/oidc-client-ext": "^1.13.1",
29
+ "@inrupt/solid-client-authn-core": "^1.13.1",
30
30
  "@types/lodash.clonedeep": "^4.5.6",
31
31
  "@types/node": "^18.0.3",
32
32
  "@types/uuid": "^8.3.0",
@@ -41,5 +41,5 @@
41
41
  "engines": {
42
42
  "node": "^14.0.0 || ^16.0.0"
43
43
  },
44
- "gitHead": "72cd3486efd627d01c8f272a502639075cf16c7c"
44
+ "gitHead": "db1b8613648e96ef536374640421b318058551a3"
45
45
  }
@@ -228,6 +228,58 @@ describe("ClientAuthentication", () => {
228
228
  nonEmptyStorage.get("clientKey", { secure: false })
229
229
  ).resolves.toBeUndefined();
230
230
  });
231
+
232
+ it("throws if the redirect IRI is a malformed URL", async () => {
233
+ const clientAuthn = getClientAuthentication();
234
+ await expect(() =>
235
+ clientAuthn.login(
236
+ {
237
+ sessionId: "someUser",
238
+ tokenType: "DPoP",
239
+ clientId: "coolApp",
240
+ redirectUrl: "not a valid URL",
241
+ oidcIssuer: "https://idp.com",
242
+ },
243
+ mockEmitter
244
+ )
245
+ ).rejects.toThrow();
246
+ });
247
+
248
+ it("throws if the redirect IRI contains a hash fragment, with a helpful message", async () => {
249
+ const clientAuthn = getClientAuthentication();
250
+ await expect(() =>
251
+ clientAuthn.login(
252
+ {
253
+ sessionId: "someUser",
254
+ tokenType: "DPoP",
255
+ clientId: "coolApp",
256
+ redirectUrl: "https://example.org/redirect#some-fragment",
257
+ oidcIssuer: "https://idp.com",
258
+ },
259
+ mockEmitter
260
+ )
261
+ ).rejects.toThrow("hash fragment");
262
+ });
263
+
264
+ it("does not normalize the redirect URL if provided by the user", async () => {
265
+ const clientAuthn = getClientAuthentication();
266
+ await clientAuthn.login(
267
+ {
268
+ sessionId: "mySession",
269
+ clientId: "coolApp",
270
+ // Note that the redirect IRI does not include a trailing slash.
271
+ redirectUrl: "https://example.org",
272
+ oidcIssuer: "https://idp.com",
273
+ tokenType: "Bearer",
274
+ },
275
+ mockEmitter
276
+ );
277
+ expect(defaultMocks.loginHandler.handle).toHaveBeenCalledWith(
278
+ expect.objectContaining({
279
+ redirectUrl: "https://example.org",
280
+ })
281
+ );
282
+ });
231
283
  });
232
284
 
233
285
  describe("fetch", () => {
@@ -34,6 +34,7 @@ import {
34
34
  ISessionInternalInfo,
35
35
  ILoginOptions,
36
36
  EVENTS,
37
+ isValidRedirectUrl,
37
38
  } from "@inrupt/solid-client-authn-core";
38
39
  import { removeOidcQueryParam } from "@inrupt/oidc-client-ext";
39
40
  import { EventEmitter } from "events";
@@ -72,11 +73,17 @@ export default class ClientAuthentication {
72
73
 
73
74
  // In the case of the user hitting the 'back' button in their browser, they
74
75
  // could return to a previous redirect URL that contains OIDC params that
75
- // are now longer valid - so just to be safe, strip relevant params now.
76
- const redirectUrl = removeOidcQueryParam(
77
- options.redirectUrl ?? window.location.href
78
- );
79
-
76
+ // are now longer valid. To be safe, strip relevant params now.
77
+ // If the user is providing a redirect IRI, it should not be modified, so
78
+ // normalization only applies if we default to the current location (which is
79
+ // a bad practice and should be discouraged).
80
+ const redirectUrl =
81
+ options.redirectUrl ?? removeOidcQueryParam(window.location.href);
82
+ if (!isValidRedirectUrl(redirectUrl)) {
83
+ throw new Error(
84
+ `${redirectUrl} is not a valid redirect URL, it is either a malformed IRI or it includes a hash fragment.`
85
+ );
86
+ }
80
87
  await this.loginHandler.handle({
81
88
  ...options,
82
89
  redirectUrl,
@@ -33,7 +33,6 @@ import {
33
33
  IStorageUtility,
34
34
  ConfigurationError,
35
35
  } from "@inrupt/solid-client-authn-core";
36
- import { appendToUrlPathname } from "../../util/urlPath";
37
36
 
38
37
  export const WELL_KNOWN_OPENID_CONFIG = ".well-known/openid-configuration";
39
38
 
@@ -160,10 +159,7 @@ export default class IssuerConfigFetcher implements IIssuerConfigFetcher {
160
159
  async fetchConfig(issuer: string): Promise<IIssuerConfig> {
161
160
  let issuerConfig: IIssuerConfig;
162
161
 
163
- const openIdConfigUrl = appendToUrlPathname(
164
- issuer,
165
- WELL_KNOWN_OPENID_CONFIG
166
- );
162
+ const openIdConfigUrl = new URL(WELL_KNOWN_OPENID_CONFIG, issuer).href;
167
163
  const issuerConfigRequestBody = await window.fetch(openIdConfigUrl);
168
164
  // Check the validity of the fetched config
169
165
  try {
@@ -1 +0,0 @@
1
- export declare function appendToUrlPathname(url: string, append: string): string;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.appendToUrlPathname = void 0;
4
- function appendToUrlPathname(url, append) {
5
- const parsedUrl = new URL(url);
6
- const path = parsedUrl.pathname;
7
- parsedUrl.pathname = `${path}${path.endsWith("/") ? "" : "/"}${append.startsWith("/") ? append.substring(1) : append}`;
8
- return parsedUrl.toString();
9
- }
10
- exports.appendToUrlPathname = appendToUrlPathname;
11
- //# sourceMappingURL=urlPath.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"urlPath.js","sourceRoot":"","sources":["../../src/util/urlPath.ts"],"names":[],"mappings":";;;AAgCA,SAAgB,mBAAmB,CAAC,GAAW,EAAE,MAAc;IAC7D,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAC/B,MAAM,IAAI,GAAG,SAAS,CAAC,QAAQ,CAAC;IAChC,SAAS,CAAC,QAAQ,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAC1D,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MACjD,EAAE,CAAC;IAEH,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;AAC9B,CAAC;AARD,kDAQC"}
@@ -1,55 +0,0 @@
1
- //
2
- // Copyright 2022 Inrupt Inc.
3
- //
4
- // Permission is hereby granted, free of charge, to any person obtaining a copy
5
- // of this software and associated documentation files (the "Software"), to deal in
6
- // the Software without restriction, including without limitation the rights to use,
7
- // copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8
- // Software, and to permit persons to whom the Software is furnished to do so,
9
- // subject to the following conditions:
10
- //
11
- // The above copyright notice and this permission notice shall be included in
12
- // all copies or substantial portions of the Software.
13
- //
14
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15
- // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16
- // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17
- // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19
- // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
- //
21
-
22
- import { describe, it, expect } from "@jest/globals";
23
- import { appendToUrlPathname } from "./urlPath";
24
-
25
- describe("urlPath", () => {
26
- it("should remove one slash if empty path", () => {
27
- expect(appendToUrlPathname("https://ex.com/", "/test")).toBe(
28
- "https://ex.com/test"
29
- );
30
-
31
- expect(
32
- appendToUrlPathname("https://ex.com/", "////only-remove-one-slash")
33
- ).toBe("https://ex.com////only-remove-one-slash");
34
- });
35
-
36
- it("should remove one slash if non-empty path", () => {
37
- expect(appendToUrlPathname("https://ex.com/a/", "/test")).toBe(
38
- "https://ex.com/a/test"
39
- );
40
-
41
- expect(
42
- appendToUrlPathname("https://ex.com/a/", "////only-remove-one-slash")
43
- ).toBe("https://ex.com/a////only-remove-one-slash");
44
- });
45
-
46
- it("should add a slash before appending slash", () => {
47
- expect(appendToUrlPathname("https://ex.com", "test")).toBe(
48
- "https://ex.com/test"
49
- );
50
-
51
- expect(appendToUrlPathname("https://ex.com/a", "test")).toBe(
52
- "https://ex.com/a/test"
53
- );
54
- });
55
- });
@@ -1,41 +0,0 @@
1
- //
2
- // Copyright 2022 Inrupt Inc.
3
- //
4
- // Permission is hereby granted, free of charge, to any person obtaining a copy
5
- // of this software and associated documentation files (the "Software"), to deal in
6
- // the Software without restriction, including without limitation the rights to use,
7
- // copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8
- // Software, and to permit persons to whom the Software is furnished to do so,
9
- // subject to the following conditions:
10
- //
11
- // The above copyright notice and this permission notice shall be included in
12
- // all copies or substantial portions of the Software.
13
- //
14
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15
- // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16
- // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17
- // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19
- // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
- //
21
-
22
- /**
23
- * @hidden
24
- * @packageDocumentation
25
- */
26
-
27
- /**
28
- * Utility that appends the specified value to end of the specified URL's path.
29
- *
30
- * @param url the URL to whose path we append the specified value
31
- * @param append the value to append to the URL's path
32
- */
33
- export function appendToUrlPathname(url: string, append: string): string {
34
- const parsedUrl = new URL(url);
35
- const path = parsedUrl.pathname;
36
- parsedUrl.pathname = `${path}${path.endsWith("/") ? "" : "/"}${
37
- append.startsWith("/") ? append.substring(1) : append
38
- }`;
39
-
40
- return parsedUrl.toString();
41
- }