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

@@ -78,7 +78,7 @@ export class MarkdownContentProvider {
this.logger.log('provideTextDocumentContent', initialData);
// Content Security Policy
const nonce = new Date().getTime() + '' + new Date().getMilliseconds();
const nonce = getNonce();
const csp = this.getCsp(resourceProvider, sourceUri, nonce);
const body = await this.engine.render(markdownDocument, resourceProvider);
@@ -228,3 +228,12 @@ export class MarkdownContentProvider {
}
}
}
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;
}