Improve Helmet publicKeyPins definitions (#9017)

`helmet.publicKeyPins` takes an object of a certain shape instead of any
Object.
This commit is contained in:
Evan Hahn
2016-04-22 23:12:45 -07:00
committed by Masahiro Wakame
parent b20485f598
commit db57ec3afd
2 changed files with 44 additions and 2 deletions

View File

@@ -110,10 +110,39 @@ function noSniffTest() {
*/
function publicKeyPinsTest() {
app.use(helmet.publicKeyPins({
maxAge: 7776000000,
sha256s: ["AbCdEf123=", "ZyXwVu456="],
}));
app.use(helmet.publicKeyPins({
maxAge: 7776000000,
sha256s: ["AbCdEf123=", "ZyXwVu456="],
includeSubdomains: false
}));
app.use(helmet.publicKeyPins({
maxAge: 7776000000,
sha256s: ["AbCdEf123=", "ZyXwVu456="],
includeSubdomains: true
}));
app.use(helmet.publicKeyPins({
maxAge: 7776000000,
sha256s: ["AbCdEf123=", "ZyXwVu456="],
includeSubdomains: true,
reportUri: "http://example.com"
}));
app.use(helmet.publicKeyPins({
maxAge: 7776000000,
sha256s: ["AbCdEf123=", "ZyXwVu456="],
reportOnly: true
}));
app.use(helmet.publicKeyPins({
maxAge: 7776000000,
sha256s: ["AbCdEf123=", "ZyXwVu456="],
setIf: function (req, res) { return true; }
}));
}
/**

15
helmet/helmet.d.ts vendored
View File

@@ -40,6 +40,19 @@ declare module "helmet" {
directives? : IHelmetCspDirectives
}
interface IHelmetPublicKeyPinsSetIfFunction {
(req: express.Request, res: express.Response): boolean;
}
interface IHelmetPublicKeyPinsConfiguration {
maxAge : number;
sha256s : string[];
includeSubdomains? : boolean;
reportUri? : string;
reportOnly? : boolean;
setIf?: IHelmetPublicKeyPinsSetIfFunction
}
interface IHelmetXssFilterConfiguration {
setOnOldIE? : boolean;
}
@@ -107,7 +120,7 @@ declare module "helmet" {
* @summary Adds the "Public-Key-Pins" header.
* @return {RequestHandler} The Request handler.
*/
publicKeyPins(options ?: Object):express.RequestHandler;
publicKeyPins(options ?: IHelmetPublicKeyPinsConfiguration):express.RequestHandler;
/**
* @summary Mitigate cross-site scripting attacks with the "X-XSS-Protection" header.