Skip to content

Commit a811225

Browse files
authored
fix: protocol checking during random uuidv4 generation
fixes the #2750 issue
1 parent 1893c38 commit a811225

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

web/assets/js/util/index.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,18 @@ class RandomUtil {
124124
}
125125

126126
static randomUUID() {
127-
return window.crypto.randomUUID();
127+
if (window.location.protocol === "https:") {
128+
return window.crypto.randomUUID();
129+
} else {
130+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
131+
.replace(/[xy]/g, function (c) {
132+
const randomValues = new Uint8Array(1);
133+
window.crypto.getRandomValues(randomValues);
134+
let randomValue = randomValues[0] % 16;
135+
let calculatedValue = (c === 'x') ? randomValue : (randomValue & 0x3 | 0x8);
136+
return calculatedValue.toString(16);
137+
});
138+
}
128139
}
129140

130141
static randomShadowsocksPassword() {

0 commit comments

Comments
 (0)