-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
214bd53
commit 5ea3047
Showing
22 changed files
with
395 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
/* | ||
* @adonisjs/shield | ||
* | ||
* (c) Harminder Virk <virk@adonisjs.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
/// <reference path="./shield.ts" /> | ||
/// <reference path="./context.ts" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* @adonisjs/shield | ||
* | ||
* (c) Harminder Virk <virk@adonisjs.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
import { ShieldConfig } from '@ioc:Adonis/Addons/Shield' | ||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' | ||
|
||
import * as shield from '../../standalone' | ||
|
||
/** | ||
* Shield middleware to protect web applications against common | ||
* web attacks | ||
*/ | ||
export class ShieldMiddleware { | ||
/** | ||
* Actions to be performed | ||
*/ | ||
private actions = [ | ||
shield.csrfFactory(this.config.csrf || {}, ''), | ||
shield.cspFactory(this.config.csp || {}), | ||
shield.dnsPrefetchFactory(this.config.dnsPrefetch || {}), | ||
shield.frameGuardFactory(this.config.xFrame || {}), | ||
shield.hstsFactory(this.config.hsts || {}), | ||
shield.noOpenFactory(this.config.noOpen || {}), | ||
shield.noSniffFactory(this.config.contentTypeSniffing || {}), | ||
shield.xssFactory(this.config.xss || {}), | ||
] | ||
|
||
constructor (private config: ShieldConfig) { | ||
} | ||
|
||
/** | ||
* Handle request | ||
*/ | ||
public async handle (ctx: HttpContextContract, next: () => Promise<void>) { | ||
for (let action of this.actions) { | ||
await action(ctx) | ||
} | ||
|
||
await next() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.