-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: 修复 OPTIONS.js 在 OPTIONS 请求伪造成功后,实际请求却不含跨域响应头 `Access-Control-…
…Allow-Origin`,导致跨域请求失败的问题。
- Loading branch information
1 parent
120279c
commit 667cd25
Showing
3 changed files
with
33 additions
and
3 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
packages/mitmproxy/src/lib/interceptor/impl/res/AfterOPTIONSHeaders.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const responseReplaceApi = require('./responseReplace') | ||
|
||
module.exports = { | ||
name: 'OPTIONSHeaders', | ||
desc: '开启了options.js功能时,正常请求时,会需要增加响应头 `Access-Control-Allow-Origin: xxx`', | ||
priority: 201, | ||
responseIntercept (context, interceptOpt, req, res, proxyReq, proxyRes, ssl, next) { | ||
const { rOptions, log } = context | ||
|
||
if (rOptions.method === 'OPTIONS') { | ||
return | ||
} | ||
|
||
const headers = { | ||
'Access-Control-Allow-Origin': rOptions.headers.origin | ||
} | ||
|
||
// 替换响应头 | ||
responseReplaceApi.replaceResponseHeaders(headers, res, proxyRes) | ||
|
||
res.setHeader('DS-AfterOPTIONSHeaders-Interceptor', true) | ||
log.info('AfterOPTIONSHeaders intercept:', JSON.stringify(headers)) | ||
}, | ||
is (interceptOpt) { | ||
return !!interceptOpt.options | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters