Skip to content

Commit

Permalink
[SecurityHeaders] Added a possibility for no follow redirects (#6212)
Browse files Browse the repository at this point in the history
* Added a possibility for no follow redirects

* Changed from noFollowRedirects to ignoreRedirects

* Update services/security-headers/security-headers.service.js

Co-authored-by: chris48s <chris48s@users.noreply.github.com>

* correct test color

Co-authored-by: chris48s <chris48s@users.noreply.github.com>
Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Feb 27, 2021
1 parent cd3774a commit 6128aa5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
15 changes: 13 additions & 2 deletions services/security-headers/security-headers.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { BaseService, NotFound } = require('..')

const queryParamSchema = Joi.object({
url: optionalUrl.required(),
ignoreRedirects: Joi.equal(''),
}).required()

const documentation = `
Expand Down Expand Up @@ -38,6 +39,15 @@ module.exports = class SecurityHeaders extends BaseService {
}),
documentation,
},
{
title: "Security Headers (Don't follow redirects)",
namedParams: {},
queryParams: { url: 'https://www.shields.io', ignoreRedirects: null },
staticPreview: this.render({
grade: 'R',
}),
documentation,
},
]

static defaultBadgeData = {
Expand All @@ -53,6 +63,7 @@ module.exports = class SecurityHeaders extends BaseService {
D: 'orange',
E: 'orange',
F: 'red',
R: 'blue',
}

return {
Expand All @@ -61,15 +72,15 @@ module.exports = class SecurityHeaders extends BaseService {
}
}

async handle(namedParams, { url }) {
async handle(namedParams, { url, ignoreRedirects }) {
const { res } = await this._request({
url: `https://securityheaders.com`,
options: {
method: 'HEAD',
qs: {
q: url,
hide: 'on',
followRedirects: 'on',
followRedirects: ignoreRedirects !== undefined ? null : 'on',
},
},
})
Expand Down
6 changes: 5 additions & 1 deletion services/security-headers/security-headers.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

const t = (module.exports = require('../tester').createServiceTester())

t.create('grade of http://shields.io')
t.create('grade of https://shields.io')
.get('/security-headers.json?url=https://shields.io')
.expectBadge({ label: 'security headers', message: 'F', color: 'red' })

t.create('grade of https://httpstat.us/301 as redirect')
.get('/security-headers.json?ignoreRedirects&url=https://httpstat.us/301')
.expectBadge({ label: 'security headers', message: 'R', color: 'blue' })

0 comments on commit 6128aa5

Please sign in to comment.