This commit is contained in:
Tutur33
2023-11-24 22:35:41 +01:00
parent 3c0b507a93
commit 7644b2a0f7
45165 changed files with 4803356 additions and 3 deletions
+6
View File
@@ -0,0 +1,6 @@
declare module '@ioc:Adonis/Core/Application' {
import { ShieldMiddlewareContract } from '@ioc:Adonis/Addons/Shield';
interface ContainerBindings {
'Adonis/Lucid/Shield': ShieldMiddlewareContract;
}
}
+8
View File
@@ -0,0 +1,8 @@
/*
* @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.
*/
+18
View File
@@ -0,0 +1,18 @@
/**
* @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.
*/
declare module '@ioc:Adonis/Core/Response' {
interface ResponseContract {
readonly nonce: string;
}
}
declare module '@ioc:Adonis/Core/Request' {
interface RequestContract {
csrfToken: string;
}
}
+8
View File
@@ -0,0 +1,8 @@
/**
* @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.
*/
+4
View File
@@ -0,0 +1,4 @@
/// <reference path="shield.d.ts" />
/// <reference path="context.d.ts" />
/// <reference path="container.d.ts" />
/// <reference path="tests.d.ts" />
+12
View File
@@ -0,0 +1,12 @@
/*
* @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" />
/// <reference path="./container.ts" />
/// <reference path="./tests.ts" />
+78
View File
@@ -0,0 +1,78 @@
/// <reference types="@adonisjs/http-server/build/adonis-typings" />
/// <reference types="@adonisjs/application/build/adonis-typings" />
declare module '@ioc:Adonis/Addons/Shield' {
import { CookieOptions } from '@ioc:Adonis/Core/Response';
import { ContentSecurityPolicyOptions } from 'helmet-csp';
import { ApplicationContract } from '@ioc:Adonis/Core/Application';
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
/**
* Config for `X-Frame-Options` header
*/
export type XFrameOptions = {
enabled: boolean;
action?: 'DENY' | 'SAMEORIGIN';
} | {
enabled: boolean;
action?: 'ALLOW-FROM';
domain: string;
};
/**
* Config for X-Content-Type-Options
*/
export type ContentTypeSniffingOptions = {
enabled: boolean;
};
/**
* Config for HTTP Strict Transport Security (HSTS)
*/
export type HstsOptions = {
enabled: boolean;
maxAge?: string | number;
includeSubDomains?: boolean;
preload?: boolean;
};
/**
* Config for X-DNS-Prefetch-Control
*/
export type DnsPrefetchOptions = {
enabled: boolean;
allow?: boolean;
};
/**
* Config for working with CSP
*/
export type CspOptions = {
enabled: boolean;
} & ContentSecurityPolicyOptions;
/**
* Config for working with CSRF options
*/
export type CsrfOptions = {
enabled: boolean;
exceptRoutes?: string[] | ((ctx: HttpContextContract) => boolean);
enableXsrfCookie?: boolean;
methods?: ReadonlyArray<string>;
cookieOptions?: Partial<CookieOptions>;
};
/**
* Shield config file types
*/
export type ShieldConfig = {
xFrame: XFrameOptions;
contentTypeSniffing: ContentTypeSniffingOptions;
hsts: HstsOptions;
dnsPrefetch: DnsPrefetchOptions;
csp: CspOptions;
csrf: CsrfOptions;
};
/**
* Shape of the shield middleware class constructor
*/
export interface ShieldMiddlewareContract {
new (application: ApplicationContract): {
handle(ctx: HttpContextContract, next: () => Promise<void>): any;
};
}
const ShieldMiddleware: ShieldMiddlewareContract;
export default ShieldMiddleware;
}
+8
View File
@@ -0,0 +1,8 @@
/*
* @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.
*/
+10
View File
@@ -0,0 +1,10 @@
import '@japa/api-client';
declare module '@japa/api-client' {
interface ApiRequest {
/**
* Send CSRF token to the server when making the
* API request.
*/
withCsrfToken(): this;
}
}
+11
View File
@@ -0,0 +1,11 @@
"use strict";
/*
* @adonisjs/shield
*
* (c) AdonisJS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Object.defineProperty(exports, "__esModule", { value: true });
require("@japa/api-client");