Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent axios error message from leaking sensitive data into logs #75

Merged
merged 3 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 0 additions & 77 deletions .circleci/config.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Snyk Tech Services will be required for a review on every PR
* @snyk-tech-services/snyk-tech-services
# CS Engineering will be required for a review on every PR
* @snyk-labs/cs-engineers
63 changes: 63 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# This is a basic workflow to help you get started with Actions

name: ci

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches:
- '**'
pull_request:
branches:
- 'master'

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build-test:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: |
npm install
- name: Run tests
run: |
npm test
- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/node@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --severity-threshold=high
build-test-monitor:
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
needs: build-test
steps:
- uses: actions/checkout@v3
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: |
npm install semantic-release @semantic-release/exec pkg --save-dev
npm install
- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/node@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --org=cse-snyk-labs
command: monitor
36 changes: 36 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Release action
on:
push:
branches:
- master

permissions:
contents: read # for checkout

jobs:
build-and-publish:
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
permissions:
contents: write # to be able to publish a GitHub release
issues: write # to be able to comment on released issues
pull-requests: write # to be able to comment on released pull requests
id-token: write # to enable use of OIDC for npm provenance
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "lts/*"
- name: Install dependencies
run: npm install
- name: Verify the integrity of provenance attestations and registry signatures for installed dependencies
run: npm audit signatures
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"homepage": "https://github.com/snyk-tech-services/snyk-request-manager#readme",
"dependencies": {
"@snyk/configstore": "^3.2.0-rc1",
"@types/babel__traverse": "7.17.1",
"@types/debug": "^4.1.7",
"@types/uuid": "^7.0.3",
"axios": "0.27.2",
Expand Down
5 changes: 5 additions & 0 deletions src/lib/request/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ const makeSnykRequest = async (
},
timeout: 30_000, // 5 mins same as Snyk APIs
});
// sanitize error to avoid leaking sensitive data
apiClient.interceptors.response.use(undefined, async (error) => {
error.config.headers.Authorization = '****';
return Promise.reject(error);
});

try {
let res;
Expand Down
22 changes: 22 additions & 0 deletions test/lib/request/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ beforeEach(() => {
.reply(512, '512')
.post(/\/genericerror/)
.reply(512, '512')
.get(/\/gotimeout/)
.delayConnection(32000)
.reply(504, '504')
.get(/\/apiautherror/)
.reply(401, '401')
.post(/\/apiautherror/)
Expand Down Expand Up @@ -206,4 +209,23 @@ describe('Test Snyk Utils error handling/classification', () => {
expect(err).toBeInstanceOf(GenericError);
}
});

it('Test Timeout error on GET command', async () => {
try {
const bodyToSend = {
testbody: {},
};
await makeSnykRequest(
{
verb: 'GET',
url: '/gotimeout',
body: JSON.stringify(bodyToSend),
},
'token123',
);
} catch (err) {
expect(err).toBeInstanceOf(GenericError);
expect(err.message.config.headers.Authorization).toBe('****');
}
});
});
23 changes: 23 additions & 0 deletions test/lib/request/rest-request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ beforeEach(() => {
.reply(512, '512')
.post(/\/genericerror/)
.reply(512, '512')
.get(/\/gotimeout/)
.delayConnection(32000)
.reply(504, '504')
.get(/\/apiautherror/)
.reply(401, '401')
.post(/\/apiautherror/)
Expand Down Expand Up @@ -287,4 +290,24 @@ describe('Test Snyk Utils error handling/classification', () => {
expect(err).toBeInstanceOf(GenericError);
}
});

it('Test Timeout error on GET command', async () => {
try {
const bodyToSend = {
testbody: {},
};
await makeSnykRequest(
{
verb: 'GET',
url: '/gotimeout',
body: JSON.stringify(bodyToSend),
useRESTApi: true,
},
'token123',
);
} catch (err) {
expect(err).toBeInstanceOf(GenericError);
expect(err.message.config.headers.Authorization).toBe('****');
}
});
});