Skip to content

Commit 59bade3

Browse files
ariesly15ariesly
andauthored
Bugfix 2022 11 01 (#2628)
* fix: 修复【Mongo 注入获取 token】的问题 * chore: up version * chore: 关闭 Pre-request Script 和 Pre-response Script v1.11.0 之后 如下脚本功能关闭,如需打开,请联系管理员添加. 在 db, mail 同级配置 scriptEnable: true, 并重启服务 即可 Co-authored-by: ariesly <ariesly@arieslymac13.local>
1 parent ed6771a commit 59bade3

File tree

5 files changed

+31
-33
lines changed

5 files changed

+31
-33
lines changed

common/postmanLib.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,13 @@ async function crossRequest(defaultOptions, preScript, afterScript, commonContex
300300
axios: axios
301301
});
302302

303-
if (preScript) {
303+
let scriptEnable = false;
304+
try {
305+
const yapi = require('../server/yapi');
306+
scriptEnable = yapi.WEBCONFIG.scriptEnable === true;
307+
} catch (err) {}
308+
309+
if (preScript && scriptEnable) {
304310
context = await sandbox(context, preScript);
305311
defaultOptions.url = options.url = URL.format({
306312
protocol: urlObj.protocol,
@@ -340,7 +346,7 @@ async function crossRequest(defaultOptions, preScript, afterScript, commonContex
340346
});
341347
}
342348

343-
if (afterScript) {
349+
if (afterScript && scriptEnable) {
344350
context.responseData = data.res.body;
345351
context.responseHeader = data.res.header;
346352
context.responseStatus = data.res.status;

package-lock.json

Lines changed: 17 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "yapi-vendor",
3-
"version": "1.10.2",
3+
"version": "1.11.0",
44
"description": "YAPI",
55
"main": "server/app.js",
66
"scripts": {

server/controllers/base.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ class baseController {
5959
let token = params.token;
6060

6161
// 如果前缀是 /api/open,执行 parse token 逻辑
62-
if (token && (openApiRouter.indexOf(ctx.path) > -1 || ctx.path.indexOf('/api/open/') === 0 )) {
63-
62+
if (token && typeof token === 'string' && (openApiRouter.indexOf(ctx.path) > -1 || ctx.path.indexOf('/api/open/') === 0 )) {
63+
6464
let tokens = parseToken(token)
6565

6666
const oldTokenUid = '999999'
@@ -83,7 +83,7 @@ class baseController {
8383
// }
8484
// return (this.$tokenAuth = true);
8585
// }
86-
86+
8787
let checkId = await this.getProjectIdByToken(token);
8888
if(!checkId){
8989
ctx.body = yapi.commons.resReturn(null, 42014, 'token 无效');
@@ -105,7 +105,7 @@ class baseController {
105105
let userInst = yapi.getInst(userModel); //创建user实体
106106
result = await userInst.findById(tokenUid);
107107
}
108-
108+
109109
this.$user = result;
110110
this.$auth = true;
111111
}

server/middleware/mockServer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ module.exports = async (ctx, next) => {
328328
if (project.is_mock_open && project.project_mock_script) {
329329
// 项目层面的mock脚本解析
330330
let script = project.project_mock_script;
331-
yapi.commons.handleMockScript(script, context);
331+
await yapi.commons.handleMockScript(script, context);
332332
}
333333

334334
await yapi.emitHook('mock_after', context);

0 commit comments

Comments
 (0)