@@ -734,4 +734,65 @@ window.fsTests = [
734734 }
735735 }
736736 } ,
737+ {
738+ name : "testFSAppDirectoryIsolation" ,
739+ description : "Test that filesystem operations are properly sandboxed to the app directory and cannot access files outside of it" ,
740+ test : async function ( ) {
741+ try {
742+ // Test 1: Try to access parent directory with ../
743+ try {
744+ await puter . fs . readdir ( '~/Desktop' ) ;
745+ fail ( "testFSAppDirectoryIsolation failed: Should not be able to read Desktop directory" ) ;
746+ } catch ( error ) {
747+ if ( error . code !== "subject_does_not_exist" ) {
748+ fail ( "testFSAppDirectoryIsolation failed: Wrong error code for Desktop directory access: " + error . code ) ;
749+ }
750+ }
751+
752+ // Test 2: Try to access absolute path outside app directory
753+ try {
754+ await puter . fs . read ( '/some/absolute/path.txt' ) ;
755+ fail ( "testFSAppDirectoryIsolation failed: Should not be able to read absolute paths" ) ;
756+ } catch ( error ) {
757+ if ( error . code !== "access_denied" && error . code !== "invalid_path" && error . code !== "subject_does_not_exist" ) {
758+ fail ( "testFSAppDirectoryIsolation failed: Wrong error code for absolute path access: " + error . code ) ;
759+ }
760+ }
761+
762+ // Test 3: Try to write outside app directory
763+ try {
764+ await puter . fs . write ( '../escape_file.txt' , 'should not work' ) ;
765+ fail ( "testFSAppDirectoryIsolation failed: Should not be able to write outside app directory" ) ;
766+ } catch ( error ) {
767+ if ( error . code !== "subject_does_not_exist" ) {
768+ fail ( "testFSAppDirectoryIsolation failed: Wrong error code for writing outside directory: " + error . code ) ;
769+ }
770+ }
771+
772+ // Test 4: Try to create directory outside app directory
773+ try {
774+ await puter . fs . mkdir ( '../escape_dir' ) ;
775+ fail ( "testFSAppDirectoryIsolation failed: Should not be able to create directory outside app directory" ) ;
776+ } catch ( error ) {
777+ if ( error . code !== "subject_does_not_exist" ) {
778+ fail ( "testFSAppDirectoryIsolation failed: Wrong error code for creating directory outside: " + error . code ) ;
779+ }
780+ }
781+
782+ // Test 5: Try to access home directory directly
783+ try {
784+ await puter . fs . read ( '~/some_file.txt' ) ;
785+ fail ( "testFSAppDirectoryIsolation failed: Should not be able to read from home directory" ) ;
786+ } catch ( error ) {
787+ if ( error . code !== "access_denied" && error . code !== "invalid_path" && error . code !== "subject_does_not_exist" ) {
788+ fail ( "testFSAppDirectoryIsolation failed: Wrong error code for home directory access: " + error . code ) ;
789+ }
790+ }
791+
792+ pass ( "testFSAppDirectoryIsolation passed" ) ;
793+ } catch ( error ) {
794+ fail ( "testFSAppDirectoryIsolation failed:" , error ) ;
795+ }
796+ }
797+ } ,
737798] ;
0 commit comments