@magda/authentication-plugin-sdk 1.2.1-rc.0 → 1.3.0-rc.0

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/README.md CHANGED
@@ -81,12 +81,13 @@ export declare function createOrGetUserToken(
81
81
  ): Promise<UserToken>;
82
82
 
83
83
  /**
84
- * Join `url` with `baseUrl` if `url` is not an absolute url
84
+ * Join `url` with `baseUrl` if `url` is not an absolute (full) url string
85
85
  *
86
86
  * @export
87
- * @param {string} url
88
- * @param {string} baseUrl
87
+ * @param {string} url A full url string or a url path string (/a/b/c).
88
+ * @param {string} baseUrl A baseUrl used to generate a full url when a url path string is supplied via the `url` parameter.
89
89
  * @param {{ [key: string]: string }} [optionalQueries]
90
+ * @param {string[]} [allowedUrlHosts] Optional; when specify, the host of `url` parameter will only be used if it is included by this list.
90
91
  * @returns
91
92
  */
92
93
  export declare function getAbsoluteUrl(
@@ -94,7 +95,8 @@ export declare function getAbsoluteUrl(
94
95
  baseUrl: string,
95
96
  optionalQueries?: {
96
97
  [key: string]: string;
97
- }
98
+ },
99
+ allowedUrlHosts?: string[]
98
100
  ): string;
99
101
 
100
102
  export declare function redirectOnSuccess(
package/dist/index.d.ts CHANGED
@@ -129,17 +129,18 @@ export declare const destroySession: typeof destroySession_2;
129
129
  declare function destroySession_2(req: express.Request): Promise<void>;
130
130
 
131
131
  /**
132
- * Join `url` with `baseUrl` if `url` is not an absolute url
132
+ * Join `url` with `baseUrl` if `url` is not an absolute (full) url string
133
133
  *
134
134
  * @export
135
- * @param {string} url
136
- * @param {string} baseUrl
135
+ * @param {string} url A full url string or a url path string (/a/b/c).
136
+ * @param {string} baseUrl A baseUrl used to generate a full url when a url path string is supplied via the `url` parameter.
137
137
  * @param {{ [key: string]: string }} [optionalQueries]
138
+ * @param {string[]} [allowedUrlHosts] Optional; when specify, the host of `url` parameter will only be used if it is included by this list.
138
139
  * @returns
139
140
  */
140
141
  export declare function getAbsoluteUrl(url: string, baseUrl: string, optionalQueries?: {
141
142
  [key: string]: string;
142
- }): string;
143
+ }, allowedUrlHosts?: string[]): string;
143
144
 
144
145
  export declare function getSessionId(req: express.Request, secret?: string): string;
145
146
 
package/dist/index.js CHANGED
@@ -10091,7 +10091,7 @@ function defineMethod(obj, name, fn) {
10091
10091
  var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*!
10092
10092
  * URI.js - Mutating URLs
10093
10093
  *
10094
- * Version: 1.19.5
10094
+ * Version: 1.19.11
10095
10095
  *
10096
10096
  * Author: Rodney Rehm
10097
10097
  * Web: http://medialize.github.io/URI.js/
@@ -10171,7 +10171,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
10171
10171
  return /^[0-9]+$/.test(value);
10172
10172
  }
10173
10173
 
10174
- URI.version = '1.19.5';
10174
+ URI.version = '1.19.11';
10175
10175
 
10176
10176
  var p = URI.prototype;
10177
10177
  var hasOwn = Object.prototype.hasOwnProperty;
@@ -10329,6 +10329,9 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
10329
10329
  // balanced parens inclusion (), [], {}, <>
10330
10330
  parens: /(\([^\)]*\)|\[[^\]]*\]|\{[^}]*\}|<[^>]*>)/g,
10331
10331
  };
10332
+ URI.leading_whitespace_expression = /^[\x00-\x20\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/
10333
+ // https://infra.spec.whatwg.org/#ascii-tab-or-newline
10334
+ URI.ascii_tab_whitespace = /[\u0009\u000A\u000D]+/g
10332
10335
  // http://www.iana.org/assignments/uri-schemes.html
10333
10336
  // http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Well-known_ports
10334
10337
  URI.defaultPorts = {
@@ -10584,6 +10587,11 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
10584
10587
  preventInvalidHostname: URI.preventInvalidHostname
10585
10588
  };
10586
10589
  }
10590
+
10591
+ string = string.replace(URI.leading_whitespace_expression, '')
10592
+ // https://infra.spec.whatwg.org/#ascii-tab-or-newline
10593
+ string = string.replace(URI.ascii_tab_whitespace, '')
10594
+
10587
10595
  // [protocol"://"[username[":"password]"@"]hostname[":"port]"/"?][path]["?"querystring]["#"fragment]
10588
10596
 
10589
10597
  // extract fragment
@@ -10602,6 +10610,11 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
10602
10610
  string = string.substring(0, pos);
10603
10611
  }
10604
10612
 
10613
+ // slashes and backslashes have lost all meaning for the web protocols (https, http, wss, ws)
10614
+ string = string.replace(/^(https?|ftp|wss?)?:+[/\\]*/i, '$1://');
10615
+ // slashes and backslashes have lost all meaning for scheme relative URLs
10616
+ string = string.replace(/^[/\\]{2,}/i, '//');
10617
+
10605
10618
  // extract protocol
10606
10619
  if (string.substring(0, 2) === '//') {
10607
10620
  // relative-scheme
@@ -10616,7 +10629,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
10616
10629
  if (parts.protocol && !parts.protocol.match(URI.protocol_expression)) {
10617
10630
  // : may be within the path
10618
10631
  parts.protocol = undefined;
10619
- } else if (string.substring(pos + 1, pos + 3) === '//') {
10632
+ } else if (string.substring(pos + 1, pos + 3).replace(/\\/g, '/') === '//') {
10620
10633
  string = string.substring(pos + 3);
10621
10634
 
10622
10635
  // extract "user:pass@host:port"
@@ -10748,7 +10761,10 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
10748
10761
  // no "=" is null according to http://dvcs.w3.org/hg/url/raw-file/tip/Overview.html#collect-url-parameters
10749
10762
  value = v.length ? URI.decodeQuery(v.join('='), escapeQuerySpace) : null;
10750
10763
 
10751
- if (hasOwn.call(items, name)) {
10764
+ if (name === '__proto__') {
10765
+ // ignore attempt at exploiting JavaScript internals
10766
+ continue;
10767
+ } else if (hasOwn.call(items, name)) {
10752
10768
  if (typeof items[name] === 'string' || items[name] === null) {
10753
10769
  items[name] = [items[name]];
10754
10770
  }
@@ -10841,7 +10857,10 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
10841
10857
  var t = '';
10842
10858
  var unique, key, i, length;
10843
10859
  for (key in data) {
10844
- if (hasOwn.call(data, key)) {
10860
+ if (key === '__proto__') {
10861
+ // ignore attempt at exploiting JavaScript internals
10862
+ continue;
10863
+ } else if (hasOwn.call(data, key)) {
10845
10864
  if (isArray(data[key])) {
10846
10865
  unique = {};
10847
10866
  for (i = 0, length = data[key].length; i < length; i++) {
@@ -12969,7 +12988,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;/*!
12969
12988
  * URI.js - Mutating URLs
12970
12989
  * IPv6 Support
12971
12990
  *
12972
- * Version: 1.19.5
12991
+ * Version: 1.19.11
12973
12992
  *
12974
12993
  * Author: Rodney Rehm
12975
12994
  * Web: http://medialize.github.io/URI.js/
@@ -13161,7 +13180,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;/*!
13161
13180
  * URI.js - Mutating URLs
13162
13181
  * Second Level Domain (SLD) Support
13163
13182
  *
13164
- * Version: 1.19.5
13183
+ * Version: 1.19.11
13165
13184
  *
13166
13185
  * Author: Rodney Rehm
13167
13186
  * Web: http://medialize.github.io/URI.js/
@@ -29936,31 +29955,35 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
29936
29955
  Object.defineProperty(exports, "__esModule", { value: true });
29937
29956
  const urijs_1 = __importDefault(__webpack_require__(67));
29938
29957
  /**
29939
- * Join `url` with `baseUrl` if `url` is not an absolute url
29958
+ * Join `url` with `baseUrl` if `url` is not an absolute (full) url string
29940
29959
  *
29941
29960
  * @export
29942
- * @param {string} url
29943
- * @param {string} baseUrl
29961
+ * @param {string} url A full url string or a url path string (/a/b/c).
29962
+ * @param {string} baseUrl A baseUrl used to generate a full url when a url path string is supplied via the `url` parameter.
29944
29963
  * @param {{ [key: string]: string }} [optionalQueries]
29964
+ * @param {string[]} [allowedUrlHosts] Optional; when specify, the host of `url` parameter will only be used if it is included by this list.
29945
29965
  * @returns
29946
29966
  */
29947
- function getAbsoluteUrl(url, baseUrl, optionalQueries) {
29967
+ function getAbsoluteUrl(url, baseUrl, optionalQueries, allowedUrlHosts) {
29948
29968
  const uri = urijs_1.default(url);
29949
- if (uri.hostname()) {
29950
- // --- absolute url, return directly
29951
- return url;
29952
- }
29953
- else {
29954
- if (typeof baseUrl !== "string") {
29955
- baseUrl = "";
29956
- }
29957
- const baseUri = urijs_1.default(baseUrl);
29958
- const query = uri.search(true);
29959
- const mergedUri = baseUri.segmentCoded(baseUri.segmentCoded().concat(uri.segmentCoded()));
29960
- return mergedUri
29961
- .search(Object.assign(Object.assign({}, (query ? query : {})), (optionalQueries ? optionalQueries : {})))
29962
- .toString();
29963
- }
29969
+ const urlHost = uri.host();
29970
+ if (urlHost) {
29971
+ // --- absolute url, return directly only if the urlHost is included by `allowedUrlHosts` (unless `allowedUrlHosts` is not supplied)
29972
+ if (!allowedUrlHosts ||
29973
+ allowedUrlHosts.findIndex((item) => item === urlHost) !== -1) {
29974
+ return url;
29975
+ }
29976
+ }
29977
+ // ignore url host of `host` if any and use `baseUrl` to create the final full url string
29978
+ if (typeof baseUrl !== "string") {
29979
+ baseUrl = "";
29980
+ }
29981
+ const baseUri = urijs_1.default(baseUrl);
29982
+ const query = uri.search(true);
29983
+ const mergedUri = baseUri.segmentCoded(baseUri.segmentCoded().concat(uri.segmentCoded()));
29984
+ return mergedUri
29985
+ .search(Object.assign(Object.assign({}, (query ? query : {})), (optionalQueries ? optionalQueries : {})))
29986
+ .toString();
29964
29987
  }
29965
29988
  exports.default = getAbsoluteUrl;
29966
29989
  //# sourceMappingURL=getAbsoluteUrl.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@magda/authentication-plugin-sdk",
3
3
  "description": "MAGDA Authentication Plugin SDK",
4
- "version": "1.2.1-rc.0",
4
+ "version": "1.3.0-rc.0",
5
5
  "scripts": {
6
6
  "prebuild": "rimraf dist tsconfig.tsbuildinfo",
7
7
  "build": "webpack && api-extractor run -l",
@@ -12,14 +12,14 @@
12
12
  "main": "dist/index.js",
13
13
  "types": "dist/index.d.ts",
14
14
  "devDependencies": {
15
- "@magda/auth-api-client": "^1.2.1-rc.0",
16
- "@magda/typescript-common": "^1.2.1-rc.0",
15
+ "@magda/auth-api-client": "^1.3.0-rc.0",
16
+ "@magda/typescript-common": "^1.3.0-rc.0",
17
17
  "@types/express": "^4.17.6",
18
18
  "@types/express-session": "^1.15.15",
19
19
  "@types/lodash": "^4.14.74",
20
20
  "@types/passport": "^1.0.3",
21
21
  "@types/pg": "^6.1.41",
22
- "@types/urijs": "1.19.13",
22
+ "@types/urijs": "^1.19.19",
23
23
  "ts-loader": "^6.2.1",
24
24
  "typescript": "^3.7.2",
25
25
  "webpack": "^4.41.2",
@@ -32,7 +32,7 @@
32
32
  "express-session": "^1.17.1",
33
33
  "lodash": "^4.17.4",
34
34
  "pg": "^6.4.0",
35
- "urijs": "^1.19.4"
35
+ "urijs": "^1.19.11"
36
36
  },
37
37
  "magda": {
38
38
  "language": "typescript",