Skip to content

Commit 1bf3650

Browse files
Kubik2000juffalow
authored andcommitted
added PermissionsPolicy and ReferrerPolicy security checks
1 parent b32b891 commit 1bf3650

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

src/security/PermissionsPolicy.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import Test from '../Test';
2+
3+
/**
4+
*
5+
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Feature-Policy
6+
*/
7+
class PermissionsPolicy extends Test {
8+
protected request: IRequest;
9+
10+
protected logger: ILogger;
11+
12+
constructor(request: IRequest, logger: ILogger) {
13+
super();
14+
this.request = request;
15+
this.logger = logger;
16+
}
17+
18+
public async run(url: string): Promise<IResult> {
19+
this.logger.info('Starting Permissions-Policy test...');
20+
const result = await this.request.get(url);
21+
22+
if (!result.response.headers.hasOwnProperty('permissions-policy')) {
23+
return this.getResult('permissions-policy', 'UNSUCCESSFUL');
24+
}
25+
26+
return this.getResult('Permissions-Policy', 'SUCCESSFUL');
27+
}
28+
}
29+
30+
export default PermissionsPolicy;

src/security/ReferrerPolicy.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import Test from '../Test';
2+
3+
/**
4+
*
5+
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy
6+
*/
7+
class ReferrerPolicy extends Test {
8+
protected request: IRequest;
9+
10+
protected logger: ILogger;
11+
12+
constructor(request: IRequest, logger: ILogger) {
13+
super();
14+
this.request = request;
15+
this.logger = logger;
16+
}
17+
18+
public async run(url: string): Promise<IResult> {
19+
this.logger.info('Starting Referrer-Policy test...');
20+
const result = await this.request.get(url);
21+
22+
if (!result.response.headers.hasOwnProperty('referrer-policy')) {
23+
return this.getResult('referrer-policy', 'UNSUCCESSFUL');
24+
}
25+
26+
return this.getResult('Referrer-Policy', 'SUCCESSFUL');
27+
}
28+
}
29+
30+
export default ReferrerPolicy;

src/security/Security.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import Cookies from './Cookies';
44
import FingerPrint from './FingerPrint';
55
import HSTS from './HSTS';
66
import HTTPS from './HTTPS';
7+
import PermissionsPolicy from './PermissionsPolicy';
8+
import ReferrerPolicy from './ReferrerPolicy';
79
import XFrameOptions from './XFrameOptions';
810
import XXSSProtection from './XXSSProtection';
911

@@ -21,6 +23,8 @@ class Security extends Test {
2123

2224
const results = [
2325
await this.runTest('https', new HTTPS(request, logger), url),
26+
await this.runTest('PermissionsPolicy', new PermissionsPolicy(request, logger), url),
27+
await this.runTest('ReferrerPolicy', new ReferrerPolicy(request, logger), url),
2428
await this.runTest('XFrameOptions', new XFrameOptions(request, logger), url),
2529
await this.runTest('XXSSProtection', new XXSSProtection(request, logger), url),
2630
await this.runTest('hsts', new HSTS(request, logger), url),

0 commit comments

Comments
 (0)