Skip to content

Commit c67c8f0

Browse files
authored
send Cross-Origin-Resource-Policy header on all responses (#10420)
* send Cross-Origin-Resource-Policy header on all responses * don't re-add Access-Control-Allow-Origin on json responses this is re-adding a header we've already set earlier in the process * update tests
1 parent 6f4ebba commit c67c8f0

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

Diff for: core/base-service/legacy-result-sender.js

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ function sendSVG(res, askres, end) {
1717

1818
function sendJSON(res, askres, end) {
1919
askres.setHeader('Content-Type', 'application/json')
20-
askres.setHeader('Access-Control-Allow-Origin', '*')
2120
askres.setHeader('Content-Length', Buffer.byteLength(res, 'utf8'))
2221
end(null, { template: streamFromString(res) })
2322
}

Diff for: core/server/server.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,12 @@ class Server {
541541
}
542542
}
543543

544-
// https://github.com/badges/shields/issues/3273
545544
camp.handle((req, res, next) => {
545+
// https://github.com/badges/shields/issues/3273
546546
res.setHeader('Access-Control-Allow-Origin', '*')
547+
// https://github.com/badges/shields/issues/10419
548+
res.setHeader('Cross-Origin-Resource-Policy', 'cross-origin')
549+
547550
next()
548551
})
549552

Diff for: core/server/server.spec.js

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ describe('The server', function () {
7979
)
8080
expect(statusCode).to.equal(200)
8181
expect(headers['access-control-allow-origin']).to.equal('*')
82+
expect(headers['cross-origin-resource-policy']).to.equal('cross-origin')
8283
})
8384

8485
it('should redirect colorscheme PNG badges as configured', async function () {
@@ -133,6 +134,7 @@ describe('The server', function () {
133134
expect(statusCode).to.equal(200)
134135
expect(headers['content-type']).to.equal('application/json')
135136
expect(headers['access-control-allow-origin']).to.equal('*')
137+
expect(headers['cross-origin-resource-policy']).to.equal('cross-origin')
136138
expect(headers['content-length']).to.equal('92')
137139
expect(() => JSON.parse(body)).not.to.throw()
138140
})

0 commit comments

Comments
 (0)