Add getNonce function to generate webview nonces

This commit is contained in:
Matt Bierner
2021-07-13 10:02:09 -07:00
parent 31185ce96e
commit 5b8ce768f3
4 changed files with 41 additions and 4 deletions

View File

@@ -85,7 +85,7 @@ export class SimpleBrowserView extends Disposable {
private getHtml(url: string) {
const configuration = vscode.workspace.getConfiguration('simpleBrowser');
const nonce = new Date().getTime() + '' + new Date().getMilliseconds();
const nonce = getNonce();
const mainJs = this.extensionResourceUrl('media', 'index.js');
const mainCss = this.extensionResourceUrl('media', 'main.css');
@@ -154,3 +154,13 @@ export class SimpleBrowserView extends Disposable {
function escapeAttribute(value: string | vscode.Uri): string {
return value.toString().replace(/"/g, '"');
}
function getNonce() {
let text = '';
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (let i = 0; i < 64; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}