Skip to content

Commit 533e000

Browse files
authored
fix: prevent axios error message from leaking sensitive data into logs (#75)
Updated CODEOWNERS moved ci to github actions included response interceptor to sanitize axios error included timeout testcase on v1 and REST api endpoints pinned 1 dependencies package
1 parent 062fcdc commit 533e000

File tree

8 files changed

+152
-79
lines changed

8 files changed

+152
-79
lines changed

.circleci/config.yml

-77
This file was deleted.

.github/CODEOWNERS

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# Snyk Tech Services will be required for a review on every PR
2-
* @snyk-tech-services/snyk-tech-services
1+
# CS Engineering will be required for a review on every PR
2+
* @snyk-labs/cs-engineers

.github/workflows/ci.yml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# This is a basic workflow to help you get started with Actions
2+
3+
name: ci
4+
5+
# Controls when the workflow will run
6+
on:
7+
# Triggers the workflow on push or pull request events but only for the "main" branch
8+
push:
9+
branches:
10+
- '**'
11+
pull_request:
12+
branches:
13+
- 'master'
14+
15+
# Allows you to run this workflow manually from the Actions tab
16+
workflow_dispatch:
17+
18+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
19+
jobs:
20+
build-test:
21+
# The type of runner that the job will run on
22+
runs-on: ubuntu-latest
23+
# Steps represent a sequence of tasks that will be executed as part of the job
24+
steps:
25+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
26+
- uses: actions/checkout@v3
27+
- name: Setup Node.js environment
28+
uses: actions/setup-node@v3
29+
with:
30+
node-version: 18
31+
- name: Install dependencies
32+
run: |
33+
npm install
34+
- name: Run tests
35+
run: |
36+
npm test
37+
- name: Run Snyk to check for vulnerabilities
38+
uses: snyk/actions/node@master
39+
env:
40+
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
41+
with:
42+
args: --severity-threshold=high
43+
build-test-monitor:
44+
if: github.ref == 'refs/heads/master'
45+
runs-on: ubuntu-latest
46+
needs: build-test
47+
steps:
48+
- uses: actions/checkout@v3
49+
- name: Setup Node.js environment
50+
uses: actions/setup-node@v3
51+
with:
52+
node-version: 18
53+
- name: Install dependencies
54+
run: |
55+
npm install semantic-release @semantic-release/exec pkg --save-dev
56+
npm install
57+
- name: Run Snyk to check for vulnerabilities
58+
uses: snyk/actions/node@master
59+
env:
60+
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
61+
with:
62+
args: --org=cse-snyk-labs
63+
command: monitor

.github/workflows/release.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Release action
2+
on:
3+
push:
4+
branches:
5+
- master
6+
7+
permissions:
8+
contents: read # for checkout
9+
10+
jobs:
11+
build-and-publish:
12+
if: github.ref == 'refs/heads/master'
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write # to be able to publish a GitHub release
16+
issues: write # to be able to comment on released issues
17+
pull-requests: write # to be able to comment on released pull requests
18+
id-token: write # to enable use of OIDC for npm provenance
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v3
22+
with:
23+
fetch-depth: 0
24+
- name: Setup Node.js
25+
uses: actions/setup-node@v3
26+
with:
27+
node-version: "lts/*"
28+
- name: Install dependencies
29+
run: npm install
30+
- name: Verify the integrity of provenance attestations and registry signatures for installed dependencies
31+
run: npm audit signatures
32+
- name: Release
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
36+
run: npx semantic-release

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"homepage": "https://github.com/snyk-tech-services/snyk-request-manager#readme",
3434
"dependencies": {
3535
"@snyk/configstore": "^3.2.0-rc1",
36+
"@types/babel__traverse": "7.17.1",
3637
"@types/debug": "^4.1.7",
3738
"@types/uuid": "^7.0.3",
3839
"axios": "0.27.2",

src/lib/request/request.ts

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ const makeSnykRequest = async (
5858
},
5959
timeout: 30_000, // 5 mins same as Snyk APIs
6060
});
61+
// sanitize error to avoid leaking sensitive data
62+
apiClient.interceptors.response.use(undefined, async (error) => {
63+
error.config.headers.Authorization = '****';
64+
return Promise.reject(error);
65+
});
6166

6267
try {
6368
let res;

test/lib/request/request.test.ts

+22
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ beforeEach(() => {
3030
.reply(512, '512')
3131
.post(/\/genericerror/)
3232
.reply(512, '512')
33+
.get(/\/gotimeout/)
34+
.delayConnection(32000)
35+
.reply(504, '504')
3336
.get(/\/apiautherror/)
3437
.reply(401, '401')
3538
.post(/\/apiautherror/)
@@ -206,4 +209,23 @@ describe('Test Snyk Utils error handling/classification', () => {
206209
expect(err).toBeInstanceOf(GenericError);
207210
}
208211
});
212+
213+
it('Test Timeout error on GET command', async () => {
214+
try {
215+
const bodyToSend = {
216+
testbody: {},
217+
};
218+
await makeSnykRequest(
219+
{
220+
verb: 'GET',
221+
url: '/gotimeout',
222+
body: JSON.stringify(bodyToSend),
223+
},
224+
'token123',
225+
);
226+
} catch (err) {
227+
expect(err).toBeInstanceOf(GenericError);
228+
expect(err.message.config.headers.Authorization).toBe('****');
229+
}
230+
});
209231
});

test/lib/request/rest-request.test.ts

+23
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ beforeEach(() => {
3232
.reply(512, '512')
3333
.post(/\/genericerror/)
3434
.reply(512, '512')
35+
.get(/\/gotimeout/)
36+
.delayConnection(32000)
37+
.reply(504, '504')
3538
.get(/\/apiautherror/)
3639
.reply(401, '401')
3740
.post(/\/apiautherror/)
@@ -287,4 +290,24 @@ describe('Test Snyk Utils error handling/classification', () => {
287290
expect(err).toBeInstanceOf(GenericError);
288291
}
289292
});
293+
294+
it('Test Timeout error on GET command', async () => {
295+
try {
296+
const bodyToSend = {
297+
testbody: {},
298+
};
299+
await makeSnykRequest(
300+
{
301+
verb: 'GET',
302+
url: '/gotimeout',
303+
body: JSON.stringify(bodyToSend),
304+
useRESTApi: true,
305+
},
306+
'token123',
307+
);
308+
} catch (err) {
309+
expect(err).toBeInstanceOf(GenericError);
310+
expect(err.message.config.headers.Authorization).toBe('****');
311+
}
312+
});
290313
});

0 commit comments

Comments
 (0)