@@ -819,6 +819,12 @@ window.addEventListener('keydown', (e) => {
819819 const cozulmusMetin = decodeURIComponent ( atob ( sifreliKisim ) . split ( '' ) . map ( c => '%' + ( '00' + c . charCodeAt ( 0 ) . toString ( 16 ) ) . slice ( - 2 ) ) . join ( '' ) ) ;
820820
821821 const gelenKart = JSON . parse ( cozulmusMetin ) ;
822+ if ( ! gelenKart || typeof gelenKart !== 'object' ||
823+ typeof gelenKart . title !== 'string' || ! gelenKart . title . trim ( ) ||
824+ typeof gelenKart . code !== 'string' ||
825+ typeof gelenKart . category !== 'string' || ! gelenKart . category . trim ( ) ) {
826+ throw new Error ( 'Invalid shared snippet structure' ) ;
827+ }
822828 hariciKartEkle ( `${ gelenKart . title } (Gelen)` , gelenKart . code , gelenKart . category ) ;
823829
824830 spotlightInput . value = '' ;
@@ -891,7 +897,24 @@ window.importCodeSnipData = async function () {
891897 try {
892898 const result = await window . codeSnipAPI . importData ( ) ;
893899 if ( result && result . success ) {
894- localStorage . setItem ( 'all_snippets_data' , result . data ) ;
900+ const importedSnippets = JSON . parse ( result . data ) ;
901+ const validBackup = Array . isArray ( importedSnippets ) &&
902+ importedSnippets . length <= 10000 &&
903+ importedSnippets . every ( snippet =>
904+ snippet && typeof snippet === 'object' && ! Array . isArray ( snippet ) &&
905+ typeof snippet . id === 'string' && snippet . id . trim ( ) . length > 0 &&
906+ typeof snippet . title === 'string' &&
907+ typeof snippet . category === 'string' &&
908+ typeof snippet . code === 'string' &&
909+ ( snippet . isFavorite === undefined || typeof snippet . isFavorite === 'boolean' )
910+ ) ;
911+
912+ if ( ! validBackup ) {
913+ alert ( currentLang === 'tr' ? 'Yedek dosyasının içeriği geçersiz.' : 'The backup file contents are invalid.' ) ;
914+ return ;
915+ }
916+
917+ localStorage . setItem ( 'all_snippets_data' , JSON . stringify ( importedSnippets ) ) ;
895918 alert ( currentLang === 'tr' ? 'Verileriniz başarıyla geri yüklendi! Uygulama yenilenecektir.' : 'Data successfully restored! App will reload.' ) ;
896919 window . location . reload ( ) ;
897920 } else if ( result && result . message ) {
0 commit comments