Skip to content

Commit 3792c57

Browse files
authored
fix: Update the algorithm to calculate nonce (#1295)
Signed-off-by: Sheng Chen <[email protected]>
1 parent b8c464e commit 3792c57

File tree

5 files changed

+35
-27
lines changed

5 files changed

+35
-27
lines changed

package-lock.json

Lines changed: 27 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@
322322
"@types/fs-extra": "^9.0.13",
323323
"@types/lodash": "^4.14.186",
324324
"@types/minimatch": "^3.0.5",
325-
"@types/node": "^16.11.65",
325+
"@types/node": "18.x",
326326
"@types/path-exists": "^3.0.0",
327327
"@types/react": "^17.0.50",
328328
"@types/react-dom": "^16.9.16",

src/beginner-tips/index.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import * as path from "path";
55
import * as vscode from "vscode";
66
import { sendInfo } from "vscode-extension-telemetry-wrapper";
7-
import { webviewCmdLinkHandler } from "../utils";
7+
import { getNonce, webviewCmdLinkHandler } from "../utils";
88

99
const WEBVIEW_ID = "java.gettingStarted";
1010
const WEBVIEW_TITLE = "Tips for Beginners";
@@ -127,12 +127,3 @@ class BeginnerTipsPage {
127127
</html>`;
128128
}
129129
}
130-
131-
function getNonce() {
132-
let text = "";
133-
const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
134-
for (let i = 0; i < 32; i++) {
135-
text += possible.charAt(Math.floor(Math.random() * possible.length));
136-
}
137-
return text;
138-
}

src/utils/adoptiumApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export async function latestCompatibleAsset(featureVersion: string, jvmImpl: str
104104
os = "linux";
105105
}
106106

107-
let arch = process.arch;
107+
let arch = process.arch as string;
108108
if (arch === "arm64") {
109109
arch = "aarch64";
110110
}

src/utils/index.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4+
import * as crypto from "crypto";
45
import * as vscode from "vscode";
56
import { readFile as fsReadFile } from "fs";
67
import * as util from "util";
@@ -79,10 +80,8 @@ export function isInsiders() {
7980
}
8081

8182
export function getNonce() {
82-
let text = "";
83-
const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
84-
for (let i = 0; i < 32; i++) {
85-
text += possible.charAt(Math.floor(Math.random() * possible.length));
86-
}
87-
return text;
83+
let array = new Uint32Array(16);
84+
array = crypto.getRandomValues(array);
85+
const buffer = Buffer.from(array);
86+
return buffer.toString('base64');
8887
}

0 commit comments

Comments
 (0)