Skip to content

refactor(backup): enhance backup system with legacy backup and path security#13587

Merged
kangfenmao merged 3 commits intomainfrom
refactor/backup-v6
Mar 18, 2026
Merged

refactor(backup): enhance backup system with legacy backup and path security#13587
kangfenmao merged 3 commits intomainfrom
refactor/backup-v6

Conversation

@kangfenmao
Copy link
Copy Markdown
Collaborator

@kangfenmao kangfenmao commented Mar 18, 2026

What this PR does

Before this PR:

  • Backup system used a complex nested structure that was harder to maintain
  • No support for legacy backup format (LAN transfer)
  • Limited path security validation
  • electron-store config.json was stored in userData root, not included in backups

After this PR:

  • Implements direct backup and restore methods for IndexedDB and Local Storage
  • Adds legacy backup (LAN transfer) functionality for backward compatibility
  • Implements startup restoration support
  • Enhances path security with resolveAndValidatePath to prevent directory traversal attacks
  • Simplifies BackupManager constructor and methods
  • Adds Joplin and Siyuan icons
  • Updates backup metadata structure and progress handling
  • Moves electron-store config.json to userData/Data directory so it's included in backups
  • Adds automatic migration from legacy config location

Fixes #

Why we need it and why it was done in this way

The following tradeoffs were made:

  • Added path validation overhead for enhanced security
  • Legacy backup format support increases code complexity but ensures backward compatibility

The following alternatives were considered:

  • Keeping the old backup structure, but it was harder to maintain and extend

Links to places where the discussion took place: N/A

Breaking changes

The backup format has been updated to a new version. Existing backups created with older versions will still be supported through the legacy backup functionality.

Special notes for your reviewer

  • The resolveAndValidatePath utility prevents path traversal attacks by validating that resolved paths stay within expected directories
  • The BasicDataSettings component was extracted to improve code organization
  • Tests have been updated to cover the new backup functionality
  • electron-store config location changed from userData/config.json to userData/Data/config.json with automatic migration

Checklist

This checklist is not enforcing, but it's a reminder of items that could be relevant to every PR.
Approvers are expected to review this list.

Release note

Enhanced backup system with new format (v6), legacy backup support, improved path security, and config.json now included in backups

…ecurity

- Implement direct backup and restore methods for IndexedDB and Local Storage
- Add legacy backup (LAN transfer) functionality
- Implement startup restoration support
- Enhance path security with resolveAndValidatePath to prevent traversal attacks
- Simplify BackupManager constructor and methods
- Add Joplin and Siyuan icons
- Update backup metadata structure and progress handling

Signed-off-by: kangfenmao <[email protected]>
@kangfenmao kangfenmao added this to the v1.8.1 milestone Mar 18, 2026
…inclusion

- Change electron-store storage location from userData/config.json to userData/Data/config.json
- Add migration function to automatically migrate config from legacy location
- Add electron-store mock in test setup to avoid file system operations

Signed-off-by: kangfenmao <[email protected]>
Copy link
Copy Markdown
Collaborator

@DeJeune DeJeune left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the refactor — the overall direction makes sense, but I found two runtime issues that should be addressed before merge: direct restore now overwrites active data directories without the previous resource cleanup/swap safeguards, and the LAN/file-export backup name only has minute-level precision, which can silently overwrite a backup created earlier in the same minute.

@kangfenmao kangfenmao merged commit 622c39e into main Mar 18, 2026
10 checks passed
@kangfenmao kangfenmao deleted the refactor/backup-v6 branch March 18, 2026 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants