mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-03-07 18:01:40 -05:00
fix: only log if the request has an Origin header (#59920)
This commit is contained in:
committed by
GitHub
parent
6ea8c33170
commit
db07c718b9
@@ -32,4 +32,16 @@ describe('cors', () => {
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('should not log if the origin is undefined', async () => {
|
||||
const logger = fastify.log.child({ req: { url: '/api/some-endpoint' } });
|
||||
const spies = LOG_LEVELS.map(level => jest.spyOn(logger, level));
|
||||
await fastify.inject({
|
||||
url: '/api/some-endpoint'
|
||||
});
|
||||
|
||||
spies.forEach(spy => {
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -22,7 +22,7 @@ const cors: FastifyPluginCallback = (fastify, _options, done) => {
|
||||
// @fastify/cors instead.
|
||||
void reply.header('Access-Control-Allow-Origin', HOME_LOCATION);
|
||||
|
||||
if (!req.url?.startsWith('/status/')) {
|
||||
if (origin && !req.url?.startsWith('/status/')) {
|
||||
logger.info(`Received request from disallowed origin: ${origin}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user