Skip to content

Commit 10397db

Browse files
Package Common Npm Bearer Auth Mask (#327)
* mask bearer auth apitoken * removed the password64 accidently, adding back * test case fix mock
1 parent 5164346 commit 10397db

File tree

5 files changed

+11
-7
lines changed

5 files changed

+11
-7
lines changed

common-npm-packages/packaging-common/Tests/npm/npmL0.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ export function npmcommon() {
202202
},
203203
getHttpProxyConfiguration: (endpoint) => {
204204
return null;
205-
}
205+
},
206+
setSecret : msg => null
206207
};
207208
mocker.registerMock('azure-pipelines-task-lib/task', mockTask);
208209

common-npm-packages/packaging-common/locationUtilities.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export async function getPackagingUris(protocolType: ProtocolType): Promise<Pack
112112
return pkgLocation;
113113
}
114114

115+
/** Return a masked SystemAccessToken */
115116
export function getSystemAccessToken(): string {
116117
tl.debug('Getting credentials for local feeds');
117118
const auth = tl.getEndpointAuthorization('SYSTEMVSSCONNECTION', false);

common-npm-packages/packaging-common/npm/npmregistry.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class NpmRegistry implements INpmRegistry {
2525
this.authOnly = authOnly || false;
2626
}
2727

28+
/** Return NpmRegistry with masked auth from Service Endpoint. */
2829
public static async FromServiceEndpoint(endpointId: string, authOnly?: boolean): Promise<NpmRegistry> {
2930
const lineEnd = os.EOL;
3031
let endpointAuth: tl.EndpointAuthorization;
@@ -59,31 +60,32 @@ export class NpmRegistry implements INpmRegistry {
5960
username = endpointAuth.parameters['username'];
6061
password = endpointAuth.parameters['password'];
6162
email = username; // npm needs an email to be set in order to publish, this is ignored on npmjs
62-
password64 = (new Buffer(password).toString('base64'));
63-
tl.setSecret(password64);
63+
password64 = Buffer.from(password).toString('base64');
6464

6565
auth = nerfed + ':username=' + username + lineEnd;
6666
auth += nerfed + ':_password=' + password64 + lineEnd;
6767
auth += nerfed + ':email=' + email + lineEnd;
6868
break;
6969
case 'Token':
7070
const apitoken = endpointAuth.parameters['apitoken'];
71+
tl.setSecret(apitoken);
7172
if (!isVstsTokenAuth){
7273
// Use Bearer auth as it was intended.
7374
auth = nerfed + ':_authToken=' + apitoken + lineEnd;
7475
} else {
7576
// Azure DevOps does not support PATs+Bearer only JWTs+Bearer
7677
email = 'VssEmail';
7778
username = 'VssToken';
78-
password64 = (new Buffer(apitoken).toString('base64'));
79-
tl.setSecret(password64);
79+
password64 = Buffer.from(apitoken).toString('base64');
8080

8181
auth = nerfed + ':username=' + username + lineEnd;
8282
auth += nerfed + ':_password=' + password64 + lineEnd;
8383
auth += nerfed + ':email=' + email + lineEnd;
8484
}
8585
break;
8686
}
87+
tl.setSecret(password);
88+
tl.setSecret(password64);
8789

8890
auth += nerfed + ':always-auth=true';
8991
return new NpmRegistry(url, auth, authOnly);

common-npm-packages/packaging-common/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common-npm-packages/packaging-common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "azure-pipelines-tasks-packaging-common",
3-
"version": "3.241.0",
3+
"version": "3.241.1",
44
"description": "Azure Pipelines Packaging Tasks Common",
55
"scripts": {
66
"test": "mocha _build/Tests/L0.js",

0 commit comments

Comments
 (0)