Skip to content

Commit a674725

Browse files
authored
do not pass cred on command line (#108)
1 parent c170eef commit a674725

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

dist/index.js

+18-5
Original file line numberDiff line numberDiff line change
@@ -5271,11 +5271,24 @@ function prepareExistingDirectory(git, repositoryPath, repositoryUrl, clean) {
52715271
}
52725272
function configureAuthToken(git, authToken) {
52735273
return __awaiter(this, void 0, void 0, function* () {
5274-
// Add extraheader (auth)
5275-
const base64Credentials = Buffer.from(`x-access-token:${authToken}`, 'utf8').toString('base64');
5276-
core.setSecret(base64Credentials);
5277-
const authConfigValue = `AUTHORIZATION: basic ${base64Credentials}`;
5278-
yield git.config(authConfigKey, authConfigValue);
5274+
// Configure a placeholder value. This approach avoids the credential being captured
5275+
// by process creation audit events, which are commonly logged. For more information,
5276+
// refer to https://docs.microsoft.com/en-us/windows-server/identity/ad-ds/manage/component-updates/command-line-process-auditing
5277+
const placeholder = `AUTHORIZATION: basic ***`;
5278+
yield git.config(authConfigKey, placeholder);
5279+
// Determine the basic credential value
5280+
const basicCredential = Buffer.from(`x-access-token:${authToken}`, 'utf8').toString('base64');
5281+
core.setSecret(basicCredential);
5282+
// Replace the value in the config file
5283+
const configPath = path.join(git.getWorkingDirectory(), '.git', 'config');
5284+
let content = (yield fs.promises.readFile(configPath)).toString();
5285+
const placeholderIndex = content.indexOf(placeholder);
5286+
if (placeholderIndex < 0 ||
5287+
placeholderIndex != content.lastIndexOf(placeholder)) {
5288+
throw new Error('Unable to replace auth placeholder in .git/config');
5289+
}
5290+
content = content.replace(placeholder, `AUTHORIZATION: basic ${basicCredential}`);
5291+
yield fs.promises.writeFile(configPath, content);
52795292
});
52805293
}
52815294
function removeGitConfig(git, configKey) {

src/git-source-provider.ts

+25-5
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,34 @@ async function configureAuthToken(
259259
git: IGitCommandManager,
260260
authToken: string
261261
): Promise<void> {
262-
// Add extraheader (auth)
263-
const base64Credentials = Buffer.from(
262+
// Configure a placeholder value. This approach avoids the credential being captured
263+
// by process creation audit events, which are commonly logged. For more information,
264+
// refer to https://docs.microsoft.com/en-us/windows-server/identity/ad-ds/manage/component-updates/command-line-process-auditing
265+
const placeholder = `AUTHORIZATION: basic ***`
266+
await git.config(authConfigKey, placeholder)
267+
268+
// Determine the basic credential value
269+
const basicCredential = Buffer.from(
264270
`x-access-token:${authToken}`,
265271
'utf8'
266272
).toString('base64')
267-
core.setSecret(base64Credentials)
268-
const authConfigValue = `AUTHORIZATION: basic ${base64Credentials}`
269-
await git.config(authConfigKey, authConfigValue)
273+
core.setSecret(basicCredential)
274+
275+
// Replace the value in the config file
276+
const configPath = path.join(git.getWorkingDirectory(), '.git', 'config')
277+
let content = (await fs.promises.readFile(configPath)).toString()
278+
const placeholderIndex = content.indexOf(placeholder)
279+
if (
280+
placeholderIndex < 0 ||
281+
placeholderIndex != content.lastIndexOf(placeholder)
282+
) {
283+
throw new Error('Unable to replace auth placeholder in .git/config')
284+
}
285+
content = content.replace(
286+
placeholder,
287+
`AUTHORIZATION: basic ${basicCredential}`
288+
)
289+
await fs.promises.writeFile(configPath, content)
270290
}
271291

272292
async function removeGitConfig(

0 commit comments

Comments
 (0)