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(core): hide sensitive data from error messages #87

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
'use strict';

const { stripQueryFromURL } = require('../../tools/http');

const errors = require('../../errors');

const throwForStaleAuth = resp => {
if (resp.status === 401) {
const message = `Got ${resp.status} calling ${resp.request.method} ${
resp.request.url
}, triggering auth refresh.`;
const cleanURL = stripQueryFromURL(resp.request.url);
const message = `Got ${resp.status} calling ${resp.request.method} ${cleanURL}, triggering auth refresh.`;
throw new errors.RefreshAuthError(message);
}

Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/http-middlewares/after/throw-for-status.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use strict';

const { stripQueryFromURL } = require('../../tools/http');

const throwForStatus = resp => {
if (resp.status > 300) {
const message = `Got ${resp.status} calling ${resp.request.method} ${
resp.request.url
}, expected 2xx.`;
const cleanURL = stripQueryFromURL(resp.request.url);
const message = `Got ${resp.status} calling ${resp.request.method} ${cleanURL}, expected 2xx.`;
throw new Error(message);
}

Expand Down
11 changes: 10 additions & 1 deletion packages/core/src/tools/http.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { URL } = require('url');

const _ = require('lodash');
const fetch = require('node-fetch');

Expand Down Expand Up @@ -28,7 +30,7 @@ const parseHttpList = s => {
let part = '';

let escape = false;
let quote = false;
let quote = false;

for (let i = 0; i < s.length; i++) {
const cur = s.charAt(i);
Expand Down Expand Up @@ -97,11 +99,18 @@ const parseDictHeader = s => {
const unheader = h =>
h instanceof fetch.Headers && _.isFunction(h.toJSON) ? h.toJSON() : h;

const stripQueryFromURL = url => {
// Strip off querystring for any sensitive data
const u = new URL(url);
return u.origin + u.pathname;
};

module.exports = {
FORM_TYPE,
JSON_TYPE,
JSON_TYPE_UTF8,
getContentType,
parseDictHeader,
stripQueryFromURL,
unheader
};