Skip to content

Commit ded4415

Browse files
committed
avoid exposing API keys in logs
1 parent 3d33c4b commit ded4415

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

content/guides/use-case/wiremock.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,26 @@ Follow the steps to setup a non-containerized Node application:
159159
}
160160
```
161161
162+
> [!TIP]
163+
> For the production environment, it's recommended not to expose API keys details in logs. Instead, you can log a placeholder message to indicate whether the API key is loaded:
164+
165+
```
166+
const API_KEY = process.env.ACCUWEATHER_API_KEY;
167+
168+
console.log('API_ENDPOINT_BASE:', API_ENDPOINT_BASE); // Log after it's defined
169+
console.log('ACCUWEATHER_API_KEY is set:', !!API_KEY); // Log a boolean value instead of the actual key
170+
171+
if (!API_ENDPOINT_BASE) {
172+
throw new Error("API_ENDPOINT_BASE is not defined in environment variables");
173+
}
174+
175+
// Only check for API key if not using WireMock
176+
if (API_ENDPOINT_BASE !== 'http://localhost:8080' && !API_KEY) {
177+
throw new Error("ACCUWEATHER_API_KEY is not defined in environment variables");
178+
}
179+
```
180+
181+
> This approach ensures that you only log whether the key is set without revealing its value.
162182
163183
4. Start the Node server
164184

0 commit comments

Comments
 (0)