File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -1169,7 +1169,13 @@ export class Drive implements Contents.IDrive {
1169
1169
getDownloadUrl ( localPath : string ) : Promise < string > {
1170
1170
const baseUrl = this . serverSettings . baseUrl ;
1171
1171
let url = URLExt . join ( baseUrl , FILES_URL , URLExt . encodeParts ( localPath ) ) ;
1172
- const xsrfTokenMatch = document . cookie . match ( '\\b_xsrf=([^;]*)\\b' ) ;
1172
+ let cookie = '' ;
1173
+ try {
1174
+ cookie = document . cookie ;
1175
+ } catch ( e ) {
1176
+ // e.g. SecurityError in case of CSP Sandbox
1177
+ }
1178
+ const xsrfTokenMatch = cookie . match ( '\\b_xsrf=([^;]*)\\b' ) ;
1173
1179
if ( xsrfTokenMatch ) {
1174
1180
const fullUrl = new URL ( url ) ;
1175
1181
fullUrl . searchParams . append ( '_xsrf' , xsrfTokenMatch [ 1 ] ) ;
Original file line number Diff line number Diff line change @@ -306,7 +306,7 @@ namespace Private {
306
306
authenticated = true ;
307
307
request . headers . append ( 'Authorization' , `token ${ settings . token } ` ) ;
308
308
}
309
- if ( typeof document !== 'undefined' && document ?. cookie ) {
309
+ if ( typeof document !== 'undefined' ) {
310
310
const xsrfToken = getCookie ( '_xsrf' ) ;
311
311
if ( xsrfToken !== undefined ) {
312
312
authenticated = true ;
@@ -334,7 +334,14 @@ namespace Private {
334
334
*/
335
335
function getCookie ( name : string ) : string | undefined {
336
336
// From http://www.tornadoweb.org/en/stable/guide/security.html
337
- const matches = document . cookie . match ( '\\b' + name + '=([^;]*)\\b' ) ;
337
+ let cookie = '' ;
338
+ try {
339
+ cookie = document . cookie ;
340
+ } catch ( e ) {
341
+ // e.g. SecurityError in case of CSP Sandbox
342
+ return ;
343
+ }
344
+ const matches = cookie . match ( '\\b' + name + '=([^;]*)\\b' ) ;
338
345
return matches ?. [ 1 ] ;
339
346
}
340
347
}
You can’t perform that action at this time.
0 commit comments