-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: clean token from logged urls (#107)
* chore: remove unused log file * feat: clean token from logged urls and export helper
- Loading branch information
1 parent
4f82d0c
commit 9894911
Showing
5 changed files
with
56 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const { URL } = require('url') | ||
|
||
const replace = '***' | ||
const tokenRegex = /\bnpm_[a-zA-Z0-9]{36}\b/g | ||
const guidRegex = /\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/g | ||
|
||
const cleanUrl = (str) => { | ||
if (typeof str !== 'string' || !str) { | ||
return str | ||
} | ||
|
||
try { | ||
const url = new URL(str) | ||
if (url.password) { | ||
str = str.replace(url.password, replace) | ||
} | ||
} catch {} | ||
|
||
return str | ||
.replace(tokenRegex, `npm_${replace}`) | ||
.replace(guidRegex, `npm_${replace}`) | ||
} | ||
|
||
module.exports = cleanUrl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -239,3 +239,5 @@ function getHeaders (uri, auth, opts) { | |
|
||
return headers | ||
} | ||
|
||
module.exports.cleanUrl = require('./clean-url.js') |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters