koa 2.16.2 → 2.16.4
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/lib/request.js +11 -1
- package/lib/response.js +0 -5
- package/package.json +1 -1
package/lib/request.js
CHANGED
|
@@ -257,7 +257,17 @@ module.exports = {
|
|
|
257
257
|
if (!host) host = this.get('Host');
|
|
258
258
|
}
|
|
259
259
|
if (!host) return '';
|
|
260
|
-
|
|
260
|
+
host = splitCommaSeparatedValues(host, 1)[0];
|
|
261
|
+
// Host header may contain userinfo (e.g., "user@host") which is invalid per RFC 7230.
|
|
262
|
+
// Use URL parser to correctly extract the host portion.
|
|
263
|
+
if (host.includes('@')) {
|
|
264
|
+
try {
|
|
265
|
+
host = new URL(`http://${host}`).host;
|
|
266
|
+
} catch (e) {
|
|
267
|
+
return '';
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return host;
|
|
261
271
|
},
|
|
262
272
|
|
|
263
273
|
/**
|
package/lib/response.js
CHANGED
|
@@ -243,11 +243,6 @@ module.exports = {
|
|
|
243
243
|
_getBackReferrer() {
|
|
244
244
|
const referrer = this.ctx.get('Referrer');
|
|
245
245
|
if (referrer) {
|
|
246
|
-
// referrer is a relative path
|
|
247
|
-
if (referrer.startsWith('/')) {
|
|
248
|
-
return referrer;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
246
|
// referrer is an absolute URL, check if it's the same origin
|
|
252
247
|
const url = new URL(referrer, this.ctx.href);
|
|
253
248
|
if (url.host === this.ctx.host) {
|