
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
plover-web
Advanced tools
【插件】集成常用koa中间件,提供通用web功能。
包括:
koa提供了 很多中间件 来满足各种各样的需求,这里集成了经常用到的一些中间件。
包括:
可通过配置 config/app.js 来开启和关闭这些中间件。配置示例如下:
module.exports = {
web: {
favicon: pathUtil.join(__dirname, '../public/favicon.ico'),
// cache相关,注释掉会关闭此中间件
rtime: {},
conditional: {},
etag: { enable: false },
// 默认开启的,具体参数可参考:
// https://github.com/koajs/bodyparser
bodyParser: {
formLimit: '1mb',
jsonLimit: '1mb'
},
static: {
root: pathUtil.join(__dirname, '../public')
}
}
}
框架默认集成了cookie session和redis sessioin用以满足一般场景下的session需求。如果什么都不配置,默认开启cookie-session。
使用session必须先配置keys。
{
web: {
keys: ['17e6b6bc6129097383dcad4fa1602233'], // <- 可使用工具如(`uuidgen`)重新生成一个。
}
}
如需使用redis作为session store,可作如下配置。
{
web: {
session: {
store: 'redis',
// 额外的配置,可参考:
// https://github.com/koajs/koa-redis#options
storeOpts: {
}
}
}
}
类似于express,提供this.params用于同时取得url和post提交中的参数。
module.exports = function* () {
const page = this.params.page;
// 相当于 this.query.page || this.request.body.page;
};
默认情况下this.query会将同名参数解析成数组,如
// GET /path?a=1&a=2
this.query
-> { a: ['1', '2'] }
这在实际使用中很容易出现问题,比如不小心多加个同名参数,页面很可能就500了,所以框架优化了此特性, 针对以上场景总是会返回最后一个参数值。
// GET /path?a=1&a=2
this.query
-> { a: '2' }
如果需要复杂的参数,需要明确使用以下形式:
// GET /path?a[]=1&a[]=2
this.query
-> { a: ['1', '2'] }
更复杂的嵌套类型也是支持的,具体的序列化细节可参考qs,这样就和POST请求时参数的解析逻辑保持一致了,因为后者就是使用qs库来解析的。
框架集成了koa-csrf。默认情况下对POST/PUT/DELETE等更新类请求会要求验证csrftoken; 即提交域中必须包含正确的_csrf字段才能正确访问页面。
特殊情况时,可通过配置来忽略或强制csrftoken的校验。
{
web: {
csrf: {
// 忽略csrftoken校验
// 路径规则见:https://github.com/pillarjs/path-to-regexp
ignore: [
'/api/*'
],
// 以下请求即使是get类型也要校验csrf token
match: [
'/update.jsonp'
]
}
}
}
如果配置还不满足需求时,可以在中间件或控制器中调用assertCsrf来校验csrftoken。
module.exports = function() {
return functioin* (next) {
if (this.path === '/some-special-case') {
this.assertCsrf(); // 校验csrftoken
}
};
};
默认对页面添加以下HTTP安全头:
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: SAMEORIGIN
可通过配置关闭
{
security: {
headers: {
'X-Frame-Options': false
}
}
}
断言以指定http method访问页面,否则抛出401异常,禁止页面访问。
module.exports = function() {
return function* (next) {
if (this.path === '/save') {
this.assertMethod('post'); // 只允许post访问
...
}
};
}
exports.index = function() {
this.ctx.assertMethod(['get', 'post']) // 只允许get/post访问
}
FAQs
【插件】集成常用web中间件,提供通用web功能。
We found that plover-web 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
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.