Skip to content

Commit

Permalink
send Cross-Origin-Resource-Policy header on all responses (#10420)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
chris48s committed Jul 28, 2024
1 parent 6f4ebba commit c67c8f0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 0 additions & 1 deletion core/base-service/legacy-result-sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ function sendSVG(res, askres, end) {

function sendJSON(res, askres, end) {
askres.setHeader('Content-Type', 'application/json')
askres.setHeader('Access-Control-Allow-Origin', '*')
askres.setHeader('Content-Length', Buffer.byteLength(res, 'utf8'))
end(null, { template: streamFromString(res) })
}
Expand Down
5 changes: 4 additions & 1 deletion core/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,12 @@ class Server {
}
}

// https://github.com/badges/shields/issues/3273
camp.handle((req, res, next) => {
// https://github.com/badges/shields/issues/3273
res.setHeader('Access-Control-Allow-Origin', '*')
// https://github.com/badges/shields/issues/10419
res.setHeader('Cross-Origin-Resource-Policy', 'cross-origin')

next()
})

Expand Down
2 changes: 2 additions & 0 deletions core/server/server.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ describe('The server', function () {
)
expect(statusCode).to.equal(200)
expect(headers['access-control-allow-origin']).to.equal('*')
expect(headers['cross-origin-resource-policy']).to.equal('cross-origin')
})

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

0 comments on commit c67c8f0

Please sign in to comment.