Skip to content

Commit cb8eda2

Browse files
security(api): fix format string injection in logger calls
Replace template string interpolation in logger calls with object-based logging to prevent format string injection vulnerabilities detected by CodeQL. - Use object-based logging instead of template strings - Prevents external control of format strings in logs - Maintains same logging functionality with better security
1 parent 9699eed commit cb8eda2

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/api/guards/auth.guard.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async function apikey(req: Request, _: Response, next: NextFunction) {
3737
if (key.length > 255 && instance.integration === Integration.WHATSAPP_BUSINESS) {
3838
const cacheKey = `instance:${param.instanceName}:fullToken`;
3939
await cache.set(cacheKey, key, 0);
40-
logger.log(`Stored full token in cache for ${param.instanceName} from request`);
40+
logger.log({ message: 'Stored full token in cache from request', instanceName: param.instanceName });
4141

4242
// Atualiza a instância em memória se existir
4343
if (waMonitor.waInstances[param.instanceName]) {
@@ -52,9 +52,9 @@ async function apikey(req: Request, _: Response, next: NextFunction) {
5252
number: instance.number,
5353
businessId: instance.businessId,
5454
});
55-
logger.log(`Updated full token in memory for ${param.instanceName}`);
55+
logger.log({ message: 'Updated full token in memory', instanceName: param.instanceName });
5656
} catch (error) {
57-
logger.error(`Error updating token in memory: ${error}`);
57+
logger.error({ message: 'Error updating token in memory', error, instanceName: param.instanceName });
5858
}
5959
}
6060
}
@@ -72,7 +72,7 @@ async function apikey(req: Request, _: Response, next: NextFunction) {
7272
if (key.length > 255 && instanceByKey.integration === Integration.WHATSAPP_BUSINESS) {
7373
const cacheKey = `instance:${instanceByKey.name}:fullToken`;
7474
await cache.set(cacheKey, key, 0);
75-
logger.log(`Stored full token in cache for ${instanceByKey.name} from request`);
75+
logger.log({ message: 'Stored full token in cache from request', instanceName: instanceByKey.name });
7676

7777
// Atualiza a instância em memória se existir
7878
if (waMonitor.waInstances[instanceByKey.name]) {
@@ -87,9 +87,9 @@ async function apikey(req: Request, _: Response, next: NextFunction) {
8787
number: instanceByKey.number,
8888
businessId: instanceByKey.businessId,
8989
});
90-
logger.log(`Updated full token in memory for ${instanceByKey.name}`);
90+
logger.log({ message: 'Updated full token in memory', instanceName: instanceByKey.name });
9191
} catch (error) {
92-
logger.error(`Error updating token in memory: ${error}`);
92+
logger.error({ message: 'Error updating token in memory', error, instanceName: instanceByKey.name });
9393
}
9494
}
9595
}

src/api/integrations/channel/meta/whatsapp.business.service.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,19 @@ export class BusinessStartupService extends ChannelStartupService {
6666
this.fullToken = instance.token;
6767
const cacheKey = `instance:${instance.instanceName}:fullToken`;
6868
await this.cache.set(cacheKey, instance.token, 0);
69-
this.logger.log(`Stored full token in cache for ${instance.instanceName}`);
69+
this.logger.log({ message: 'Stored full token in cache', instanceName: instance.instanceName });
7070
} else {
7171
// Tenta carregar token completo do cache
7272
const cacheKey = `instance:${instance.instanceName}:fullToken`;
7373
const fullToken = await this.cache.get(cacheKey);
7474
if (fullToken) {
7575
this.fullToken = fullToken;
76-
this.logger.log(`Loaded full token from cache for ${instance.instanceName}`);
76+
this.logger.log({ message: 'Loaded full token from cache', instanceName: instance.instanceName });
7777
} else {
78-
this.logger.warn(`Full token not found in cache for ${instance.instanceName}, using truncated token`);
78+
this.logger.warn({
79+
message: 'Full token not found in cache, using truncated token',
80+
instanceName: instance.instanceName,
81+
});
7982
}
8083
}
8184
}

0 commit comments

Comments
 (0)