https://github.com/leecjson/koa-path-validation
Validate koa's ctx.path
https://github.com/leecjson/koa-path-validation
Last synced: 16 days ago
JSON representation
Validate koa's ctx.path
- Host: GitHub
- URL: https://github.com/leecjson/koa-path-validation
- Owner: leecjson
- License: mit
- Created: 2018-11-28T13:58:23.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-28T14:07:09.000Z (over 7 years ago)
- Last Synced: 2026-05-09T09:48:15.237Z (about 2 months ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Start
```
npm i --save koa-path-validation
```
# Source code
```javascript
module.exports = async (ctx, next) => {
if (ctx.path.startsWith('./') || ctx.path.startsWith('../') ||
ctx.path.indexOf('/./') > 0 || ctx.path.indexOf('/../') > 0 || ctx.path.indexOf('\0') > 0) {
ctx.throw(403);
}
await next();
}
```