Skip to content

Commit b6ac577

Browse files
Hashing clean up (#26417)
* Improve hashing * Updates checksum assertion for test stability * Fix test assertion
1 parent e809884 commit b6ac577

File tree

9 files changed

+13
-11
lines changed

9 files changed

+13
-11
lines changed

build/gulpfile.vscode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ function computeChecksum(filename) {
250250
const contents = fs.readFileSync(filename);
251251

252252
const hash = crypto
253-
.createHash('md5')
253+
.createHash('sha256')
254254
.update(contents)
255255
.digest('base64')
256256
.replace(/=+$/, '');

src/vs/base/node/crypto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { once } from 'vs/base/common/functional';
1010
export async function checksum(path: string, sha1hash: string | undefined): Promise<void> {
1111
const checksumPromise = new Promise<string | undefined>((resolve, reject) => {
1212
const input = fs.createReadStream(path);
13-
const hash = crypto.createHash('sha1');
13+
const hash = crypto.createHash('sha1'); // CodeQL [SM04514] Used by the update service to verify ADS update packages from Microsoft
1414
input.pipe(hash);
1515

1616
const done = once((err?: Error, result?: string) => {

src/vs/base/parts/ipc/node/ipc.net.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ export function createRandomIPCHandle(): string {
773773
}
774774

775775
export function createStaticIPCHandle(directoryPath: string, type: string, version: string): string {
776-
const scope = createHash('md5').update(directoryPath).digest('hex');
776+
const scope = createHash('md5').update(directoryPath).digest('hex'); // CodeQL [SM04514] The hash is just creating consistent, short identifiers for IPC socket names.
777777

778778
// Windows: use named pipe
779779
if (process.platform === 'win32') {

src/vs/platform/backup/electron-main/backupMainService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,6 @@ export class BackupMainService implements IBackupMainService {
410410
key = folderUri.toString().toLowerCase();
411411
}
412412

413-
return createHash('md5').update(key).digest('hex');
413+
return createHash('md5').update(key).digest('hex'); // CodeQL [SM04514] The hash doesn't need cryptographic strength - it just needs to create consistent, unique identifiers for backup folders.
414414
}
415415
}

src/vs/platform/checksum/node/checksumService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class ChecksumService implements IChecksumService {
1818
async checksum(resource: URI): Promise<string> {
1919
const stream = (await this.fileService.readFileStream(resource)).value;
2020
return new Promise<string>((resolve, reject) => {
21-
const hash = createHash('md5');
21+
const hash = createHash('sha256'); // {{ SQL CARBON EDIT }} - Use sha256
2222

2323
listenStream(stream, {
2424
onData: data => hash.update(data.buffer),

src/vs/platform/checksum/test/node/checksumService.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ suite('Checksum Service', () => {
3434
const checksumService = new ChecksumService(fileService);
3535

3636
const checksum = await checksumService.checksum(URI.file(FileAccess.asFileUri('vs/platform/checksum/test/node/fixtures/lorem.txt').fsPath));
37-
assert.ok(checksum === '8mi5KF8kcb817zmlal1kZA' || checksum === 'DnUKbJ1bHPPNZoHgHV25sg'); // depends on line endings git config
37+
console.log(`Checksum value: ${checksum}`)
38+
// {{ SQL CARBON EDIT }} - Update checksum assertion
39+
assert.ok(checksum === '8mi5KF8kcb817zmlal1kZA' || checksum === 'DnUKbJ1bHPPNZoHgHV25sg' || checksum === 'eJeeTIS0dzi8MZY+nHhjPBVtNbmGqxfVvgEOB4sqVIc' || checksum === 'd/9bMU0ydNCmc/hg8ItWeiLT/ePnf7gyPRQVGpd6tRI', `Checksum: ${checksum}`); // depends on line endings git config
3840
});
3941
});

src/vs/platform/languagePacks/node/languagePacks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class LanguagePacksCache extends Disposable {
169169

170170
private updateHash(languagePack: ILanguagePack): void {
171171
if (languagePack) {
172-
const md5 = createHash('md5');
172+
const md5 = createHash('md5'); // CodeQL [SM04514] The hash just needs to be unique and consistent for the same language pack version combination.
173173
for (const extension of languagePack.extensions) {
174174
md5.update(extension.extensionIdentifier.uuid || extension.extensionIdentifier.id).update(extension.version); // CodeQL [SM01510] The extension UUID is not sensitive info and is not manually created by a user
175175
}

src/vs/platform/workspaces/node/workspaces.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function getWorkspaceIdentifier(configPath: URI): IWorkspaceIdentifier {
2929
configPathStr = configPathStr.toLowerCase(); // sanitize for platform file system
3030
}
3131

32-
return createHash('md5').update(configPathStr).digest('hex');
32+
return createHash('md5').update(configPathStr).digest('hex'); // CodeQL [SM04514] The MD5 usage here is perfectly safe since it's only used to generate deterministic, unique identifiers from paths - not for security.
3333
}
3434

3535
return {
@@ -50,7 +50,7 @@ export function getSingleFolderWorkspaceIdentifier(folderUri: URI, folderStat?:
5050

5151
// Remote: produce a hash from the entire URI
5252
if (folderUri.scheme !== Schemas.file) {
53-
return createHash('md5').update(folderUri.toString()).digest('hex');
53+
return createHash('md5').update(folderUri.toString()).digest('hex'); // CodeQL [SM04514] The MD5 usage here is perfectly safe since it's only used to generate deterministic, unique identifiers from paths - not for security.
5454
}
5555

5656
// Local: we use the ctime as extra salt to the
@@ -77,7 +77,7 @@ export function getSingleFolderWorkspaceIdentifier(folderUri: URI, folderStat?:
7777
}
7878
}
7979

80-
return createHash('md5').update(folderUri.fsPath).update(ctime ? String(ctime) : '').digest('hex');
80+
return createHash('md5').update(folderUri.fsPath).update(ctime ? String(ctime) : '').digest('hex'); // CodeQL [SM04514] The MD5 usage here is perfectly safe since it's only used to generate deterministic, unique identifiers from paths - not for security.
8181
}
8282

8383
const folderId = getFolderId();

src/vs/server/node/remoteExtensionHostAgentServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class RemoteExtensionHostAgentServer extends Disposable implements IServerAPI {
204204

205205
// https://tools.ietf.org/html/rfc6455#section-4
206206
const requestNonce = req.headers['sec-websocket-key'];
207-
const hash = crypto.createHash('sha1');
207+
const hash = crypto.createHash('sha1'); // CodeQL [SM04514] This sha1 is part of the WebSocket RFC 6455 standard.
208208
hash.update(requestNonce + '258EAFA5-E914-47DA-95CA-C5AB0DC85B11');
209209
const responseNonce = hash.digest('base64');
210210

0 commit comments

Comments
 (0)