Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
screw-axios
Advanced tools
axios 的扩展包,封装了常规方法并且具备以下特性
npm 安装
npm i screw-axios -S
yarn 安装
yarn add screw-axios -S
pnpm 安装
pnpm add screw-axios -S
新建一个 request.js 文件,文件名可以随便起,然后在这个文件中创建 ScrewAxios 的实
import ScrewAxios from "ScrewAxios";
const request = new ScrewAxios({
headers: {},
retry:3, //这是全局的retry次数,也可以为单个请求设置retry次数,默认为0,代表全部不重连
retryDelay:3000,//设置断开、错误重连的间隔时间,默认2秒,单位毫秒
baseURL: "", //基础url前缀
timeout: 200000, //前端请求超时时间,单位是毫秒,默认5秒
canRepeat: true,//相同的连接是否可以重复发送,默认是true,如果设置成false,那么想通过请求则不可以重复
hasTimestamp: true,//启动时间戳,设置为true之后,所有的请求都会带有时间戳 默认为false
reqInterceptor(config) {}, //request 拦截器的扩展方法
resInterceptor(config) {}, //response 拦截器的扩展方法
responseHandle: {
//设置需要扩展的response的处理函数
200: res => {
console.log("返回了200")
return res
},
},
})
export default request
//在调用的api文件
import request from "./request"
export default {
middleViewData: data => request.get('/jscApi/middleViewData', { data }), // 正常请求
cancelReq: data => request.post('http://localhost:3003/jscApi/middleViewData', { data, cancelRequest: true }), // 测试取消请求
reqAgainSend: data => request.get('/equ/equTypeList11', { data, retry: 3, retryDelay: 1000 }), // 测试请求重发,除了原请求外还会重发3次
cacheEquList: data => request.get('/equ/equList', { data, cache: true, setExpireTime: 30000 }), // 测试缓存请求带参数:setExpireTime 为缓存有效时间ms
cacheEquListParams: data => request.get('/equ/equList', { data, cache: true }) // 测试缓存请求参数值不一样
};
const request = new ScrewAxios({
...
})
//根据methods进行请求
request.get("/jscApi/middleViewData", { data: { a: 1 } })
request.post("/jscApi/middleViewData", { data: { a: 1 } })
request.delete("/jscApi/middleViewData", { data: { a: 1 } })
request.put("/jscApi/middleViewData", { data: { a: 1 } })
request.head("/jscApi/middleViewData", { data: { a: 1 } })
request.options("/jscApi/middleViewData", { data: { a: 1 } })
//调用axios方法请求
request.axios({
url: "http://localhost:3000/api/img2",
methods: "get",
data: { a: 1 },
retry: 3, //配置参数
retryDelay: 1000, //配置参数
}).then(res => {
console.log(res)
})
初始化配置时 canRepeat 为 false
const request = new ScrewAxios({
...
canRepeat:false //不允许重复
})
request.get('/jscApi/middleViewData', { data:{a:1} })
request.get('/jscApi/middleViewData', { data:{a:1} })
request.get('/jscApi/middleViewData', { data:{a:1} })
上述三个请求只会请求一次。
const request = new ScrewAxios({
...
})
const source1 = request.getCancelTokenSource()
request
.get("http://localhost:3000/api/img", {
data: { a: 3 },
cancelTokenSource: source1,
})
.then(res => {
console.log(res)
})
//取消
source1.cancel() 或者 source1.cancel('这个请求取消了')
const request = new ScrewAxios({
...
})
//取消所有请求
request.cancelAll()
//为所有连接设置重连次数和重连间隔
const request = new ScrewAxios({
...
retry:3, //重连次数
retryDelay:4000,//每4秒重连
})
//单个请求错误、断开重连,单个请求设置重连后,当前连接重连次数和重连间隔会覆盖全局的
request.get('/equ/equTypeList11', { data, retry: 3, retryDelay: 1000 })
FAQs
Extension of Axios
The npm package screw-axios receives a total of 0 weekly downloads. As such, screw-axios popularity was classified as not popular.
We found that screw-axios demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.