Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 9191185

Browse files
mask basic credentials
1 parent b5c5467 commit 9191185

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed

src/agent/common.ts

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ export interface IConfiguration {
174174
poolId: number;
175175
createDiagnosticWriter?: () => IDiagnosticWriter;
176176
agent: agentifm.TaskAgent;
177+
creds?: any;
177178
}
178179

179180
export interface IServiceChannel extends NodeJS.EventEmitter {
@@ -426,13 +427,31 @@ interface IndexFunction {
426427
(input: string): ReplacementPosition[];
427428
}
428429

429-
function createMaskFunction(jobEnvironment: agentifm.JobEnvironment): ReplacementFunction {
430+
function createMaskFunction(jobEnvironment: agentifm.JobEnvironment, config: IConfiguration): ReplacementFunction {
430431
var noReplacement = (input: string) => {
431432
return input;
432433
};
433434

434435
var envMasks = jobEnvironment.mask || [];
435436
var maskHints = [];
437+
438+
// add masks for basic creds, in case force-basic was specified
439+
if (config && config.creds) {
440+
if (config.creds.username) {
441+
var maskHint = {
442+
value: config.creds.username
443+
};
444+
maskHints.push(maskHint);
445+
}
446+
if (config.creds.password) {
447+
var maskHint = {
448+
value: config.creds.password
449+
};
450+
maskHints.push(maskHint);
451+
}
452+
}
453+
454+
// add masks sent by the server
436455
envMasks.forEach((maskHint: agentifm.MaskHint) => {
437456
if (maskHint.type === agentifm.MaskType.Variable && maskHint.value) {
438457
if (jobEnvironment.variables[maskHint.value]) {
@@ -447,19 +466,7 @@ function createMaskFunction(jobEnvironment: agentifm.JobEnvironment): Replacemen
447466
if (maskHints.length > 0) {
448467
var indexFunctions: IndexFunction[] = [];
449468
maskHints.forEach((maskHint: agentifm.MaskHint, index: number) => {
450-
if (maskHint.type === agentifm.MaskType.Variable) {
451-
var toReplace = jobEnvironment.variables[maskHint.value];
452-
indexFunctions.push((input: string) => {
453-
var results: ReplacementPosition[] = [];
454-
var index: number = input.indexOf(toReplace);
455-
while (index > -1) {
456-
results.push({ start: index, length: toReplace.length });
457-
index = input.indexOf(toReplace, index + 1);
458-
}
459-
return results;
460-
});
461-
}
462-
else if (maskHint.type === agentifm.MaskType.Regex) {
469+
if (maskHint.type === agentifm.MaskType.Regex) {
463470
indexFunctions.push((input: string) => {
464471
var stubInput: string = input;
465472
var results: ReplacementPosition[] = [];
@@ -479,6 +486,21 @@ function createMaskFunction(jobEnvironment: agentifm.JobEnvironment): Replacemen
479486
return results;
480487
});
481488
}
489+
else {
490+
var toReplace = maskHint.value;
491+
if (maskHint.type === agentifm.MaskType.Variable) {
492+
toReplace = jobEnvironment.variables[maskHint.value];
493+
}
494+
indexFunctions.push((input: string) => {
495+
var results: ReplacementPosition[] = [];
496+
var index: number = input.indexOf(toReplace);
497+
while (index > -1) {
498+
results.push({ start: index, length: toReplace.length });
499+
index = input.indexOf(toReplace, index + 1);
500+
}
501+
return results;
502+
});
503+
}
482504
});
483505

484506
return (input: string) => {
@@ -537,7 +559,7 @@ function createMaskFunction(jobEnvironment: agentifm.JobEnvironment): Replacemen
537559
// TODO: JobInfo is going away soon. We should just offer the task context the full job message.
538560
// Until then, we're making the full job message available
539561
//
540-
export function jobInfoFromJob(job: agentifm.JobRequestMessage, systemAuthHandler: baseifm.IRequestHandler): IJobInfo {
562+
export function jobInfoFromJob(job: agentifm.JobRequestMessage, systemAuthHandler: baseifm.IRequestHandler, config: IConfiguration): IJobInfo {
541563
var info: IJobInfo = {
542564
description: job.jobName,
543565
jobId: job.jobId,
@@ -548,7 +570,7 @@ export function jobInfoFromJob(job: agentifm.JobRequestMessage, systemAuthHandle
548570
lockToken: job.lockToken,
549571
systemAuthHandler: systemAuthHandler,
550572
variables: job.environment.variables,
551-
mask: createMaskFunction(job.environment)
573+
mask: createMaskFunction(job.environment, config)
552574
};
553575

554576
return info;

src/agent/vsoworker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export function run(msg: cm.IWorkerMessage, consoleOutput: boolean,
109109
var agentUrl = hostContext.config.settings.serverUrl;
110110
var taskUrl = job.environment.systemConnection.url;
111111

112-
var jobInfo = cm.jobInfoFromJob(job, systemAuthHandler);
112+
var jobInfo = cm.jobInfoFromJob(job, systemAuthHandler, hostContext.config);
113113
var serviceChannel: cm.IServiceChannel = createFeedbackChannel(agentUrl, taskUrl, jobInfo, hostContext);
114114

115115
var jobContext: cm.IExecutionContext = new ctxm.ExecutionContext(jobInfo, systemAuthHandler, job.jobId, serviceChannel, hostContext);

0 commit comments

Comments
 (0)