@@ -259,6 +259,19 @@ function validateUriIsCanonical(uri: vscode.Uri): void {
259259 }
260260}
261261
262+ /**
263+ * Throws `error` or a `vscode.FileSystemError.FileNotFound` error when `uri`
264+ * is an invalid dot folder or is in an invalid dot folder. `.vscode`
265+ * is allowed for any workspace folder, but other dot folders are only
266+ * allowed in web app workspace folders. This filtering is done here to
267+ * avoid spamming the server with requests that will never return meaningful data.
268+ */
269+ function assertDotPathValid ( uri : vscode . Uri , error ?: vscode . FileSystemError ) : void {
270+ if ( ! isfsConfig ( uri ) . csp && uri . path . includes ( "/." ) && ! / \/ \. v s c o d e ( $ | \/ ) / . test ( uri . path ) ) {
271+ throw error ?? vscode . FileSystemError . FileNotFound ( uri ) ;
272+ }
273+ }
274+
262275export class FileSystemProvider implements vscode . FileSystemProvider {
263276 private superRoot = new Directory ( "" , "" ) ;
264277
@@ -299,6 +312,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
299312 public async stat ( uri : vscode . Uri ) : Promise < vscode . FileStat > {
300313 const api = new AtelierAPI ( uri ) ;
301314 if ( ! api . active ) throw vscode . FileSystemError . Unavailable ( "Server connection is inactive" ) ;
315+ assertDotPathValid ( uri ) ;
302316 validateUriIsCanonical ( uri ) ;
303317 let entryPromise : Promise < Entry > ;
304318 let result : Entry ;
@@ -349,6 +363,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
349363 }
350364
351365 public async readDirectory ( uri : vscode . Uri ) : Promise < [ string , vscode . FileType ] [ ] > {
366+ assertDotPathValid ( uri ) ;
352367 if ( uri . path . includes ( ".vscode/" ) || uri . path . endsWith ( ".vscode" ) ) {
353368 throw new vscode . FileSystemError ( "Cannot read the /.vscode directory" ) ;
354369 }
@@ -465,6 +480,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
465480 }
466481
467482 public createDirectory ( uri : vscode . Uri ) : void | Thenable < void > {
483+ assertDotPathValid ( uri , new vscode . FileSystemError ( "dot-folders are not supported by the server" ) ) ;
468484 uri = redirectDotvscodeRoot ( uri , new vscode . FileSystemError ( "Server does not have a /_vscode web application" ) ) ;
469485 const basename = path . posix . basename ( uri . path ) ;
470486 const dirname = uri . with ( { path : path . posix . dirname ( uri . path ) } ) ;
@@ -481,6 +497,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
481497 }
482498
483499 public async readFile ( uri : vscode . Uri ) : Promise < Uint8Array > {
500+ assertDotPathValid ( uri ) ;
484501 validateUriIsCanonical ( uri ) ;
485502 // Use _lookup() instead of _lookupAsFile() so we send
486503 // our cached mtime with the GET /doc request if we have it
@@ -495,13 +512,11 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
495512 overwrite : boolean ;
496513 }
497514 ) : void | Thenable < void > {
515+ assertDotPathValid ( uri , new vscode . FileSystemError ( "dot-folders are not supported by the server" ) ) ;
498516 const originalUriString = uri . toString ( ) ;
499517 const originalUri = vscode . Uri . parse ( originalUriString ) ;
500518 this . _needsUpdate . delete ( originalUriString ) ;
501519 uri = redirectDotvscodeRoot ( uri , new vscode . FileSystemError ( "Server does not have a /_vscode web application" ) ) ;
502- if ( uri . path . startsWith ( "/." ) ) {
503- throw new vscode . FileSystemError ( "dot-folders are not supported by server" ) ;
504- }
505520 validateUriIsCanonical ( uri ) ;
506521 const csp = isCSP ( uri ) ;
507522 const fileName = isfsDocumentName ( uri , csp ) ;
@@ -697,6 +712,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
697712 }
698713
699714 public async delete ( uri : vscode . Uri , options : { recursive : boolean } ) : Promise < void > {
715+ assertDotPathValid ( uri ) ;
700716 uri = redirectDotvscodeRoot ( uri , vscode . FileSystemError . FileNotFound ( uri ) ) ;
701717 validateUriIsCanonical ( uri ) ;
702718 const { project } = isfsConfig ( uri ) ;
0 commit comments