From cd944a4582d05d4fba782f10399333066fef3da5 Mon Sep 17 00:00:00 2001 From: Guilherme Afonso Date: Fri, 23 Aug 2024 02:35:12 -0300 Subject: [PATCH] feat: improve security by moving from anonymous tls to mutual tls --- src/services/marquinhosApi.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/services/marquinhosApi.ts b/src/services/marquinhosApi.ts index 9929f72..4ace645 100644 --- a/src/services/marquinhosApi.ts +++ b/src/services/marquinhosApi.ts @@ -1,6 +1,23 @@ import axios from 'axios'; +import { readFileSync } from 'fs'; +import { Agent } from 'https'; +import { join } from 'path'; import { LastfmTopListenedPeriod, PlaybackData } from '@marquinhos/types'; +const httpsAgent = new Agent({ + cert: + process.env.NODE_ENV === 'production' + ? readFileSync(join(__dirname, '/etc/ssl/certificate.pem')) + : undefined, + key: + process.env.NODE_ENV === 'production' + ? readFileSync(join(__dirname, '/etc/ssl/private.pem')) + : undefined, + rejectUnauthorized: process.env.NODE_ENV === 'production', +}); + +axios.defaults.httpsAgent = httpsAgent; + export class MarquinhosApiService { async addToScrobbleQueue(playbackData: PlaybackData) { const options = {