koa 2.16.1 → 2.16.2

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.
Files changed (2) hide show
  1. package/lib/response.js +20 -1
  2. package/package.json +5 -1
package/lib/response.js CHANGED
@@ -240,6 +240,22 @@ module.exports = {
240
240
  vary(this.res, field);
241
241
  },
242
242
 
243
+ _getBackReferrer() {
244
+ const referrer = this.ctx.get('Referrer');
245
+ if (referrer) {
246
+ // referrer is a relative path
247
+ if (referrer.startsWith('/')) {
248
+ return referrer;
249
+ }
250
+
251
+ // referrer is an absolute URL, check if it's the same origin
252
+ const url = new URL(referrer, this.ctx.href);
253
+ if (url.host === this.ctx.host) {
254
+ return referrer;
255
+ }
256
+ }
257
+ },
258
+
243
259
  /**
244
260
  * Perform a 302 redirect to `url`.
245
261
  *
@@ -261,7 +277,10 @@ module.exports = {
261
277
 
262
278
  redirect(url, alt) {
263
279
  // location
264
- if ('back' === url) url = this.ctx.get('Referrer') || alt || '/';
280
+ if ('back' === url) {
281
+ url = this._getBackReferrer() || alt || '/';
282
+ }
283
+
265
284
  if (/^https?:\/\//i.test(url)) {
266
285
  // formatting url again avoid security escapes
267
286
  url = new URL(url).toString();
package/package.json CHANGED
@@ -1,6 +1,10 @@
1
1
  {
2
2
  "name": "koa",
3
- "version": "2.16.1",
3
+ "version": "2.16.2",
4
+ "publishConfig": {
5
+ "access": "public",
6
+ "tag": "latest-2"
7
+ },
4
8
  "description": "Koa web app framework",
5
9
  "main": "lib/application.js",
6
10
  "exports": {