yapi mock漏洞处理

前言

针对yapi被爆出高级Mock可以获取到系统操作权限相关处理

解决方案

关闭注册

config.json 添加如下配置项

{
  "port": "*****",
  "closeRegister":true
}

关闭mock

config.json 添加如下配置项

{
  "port": "*****",
  "mock": false,
}

在exts/yapi-plugin-andvanced-mock/server.js文件中找到如下代码:

if (caseData && caseData.case_enable) {...}

添加代码:

if(!yapi.WEBCONFIG.mock) { return false; }

过滤敏感词

新增配置项

{
  "port": "*****",
  "filter": "process|exec|require",
}

修改公共函数 yapi/common/postmanLib.js 第178行

function sandboxByNode(sandbox = {}, script) {
  let filter = yapi.WEBCONFIG.filter; 
  let reg = new RegExp("["+filter+"]", "g"); 
  if(reg.test(script)) { 
   throw new Error("执行失败,脚本中含敏感操作....");
  }
  const vm = require('vm');
  script = new vm.Script(script);
  const context = new vm.createContext(sandbox);
  script.runInContext(context, {
    timeout: 10000
  });
  return sandbox;
}

设置访问白名单

nginx 或 ip端口号

参考链接

https://github.com/YMFE/yapi/issues/2099

原文地址:https://www.cnblogs.com/smallbo/p/15017450.html