-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refuse to overwrite any directory containing the home directory or the profile directory #68
Refuse to overwrite any directory containing the home directory or the profile directory #68
Conversation
@@ -168,7 +168,7 @@ describe("Backup", function () { | |||
}); | |||
|
|||
it(`relative paths`, async () => { | |||
const backupPath = "../"; | |||
const backupPath = "../foo"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, the backupPath
was a parent directory of the test profile directory. As such, the relative path has been changed.
Just so I understand it correctly, the PR is supposed to prevent backups from being made without a subfolder in |
The goal of this pull request is to prevent the plugin from deleting Joplin's profile directory or the user's home directory. Example 1Suppose that
This change would then prevent the plugin from overwriting Example 2Suppose that
Because the root directory of the drive contains the profile directory, this change should prevent the contents of the USB drive from being overwritten. |
possibleChild: string, | ||
|
||
// Testing only | ||
pathModule: typeof path = path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this not possible otherwise, via a spy or the like?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the difficulties here are that
path.sep
is a readonly-nonfunction property, so we can'tjest.spyOn(path, 'resolve')
path
is imported at the top ofsrc/helper.ts
, sojest.doMock
will only affect the import at the top of the file.jest.spyOn(path, 'resolve').mockImplementation((...args) => path.posix.resolve(...args))
causes infinite recursion on POSIX systems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The third issue above seems to be the most significant.
Even this alternative implementation causes a stack overflow:
src/Backup.ts
Outdated
if (helper.isSubdirectoryOrEqual(this.backupBasePath, os.homedir())) { | ||
await handleInvalidPath("msg.error.backupPathContainsHomeDir"); | ||
} else if (helper.isSubdirectoryOrEqual(this.backupBasePath, profileDir)) { | ||
await handleInvalidPath("msg.error.backupPathContainsJoplinDir"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we should also check a few other directories here.
- Desktop
- OS Folder (Like c:\windows, or other system folders)
Or perhaps the entire deletion routine should be reworked. So that it only deletes its own files ...
I think I'll have a look at it when this PR has been merged. Fits in with another idea I have.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed this!
I'm not sure how necessary system folders are though — when I set the backup directory to C:\ProgramFiles
or C:\Windows
, I get an "operation not permitted" error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes when the user runs his system with UAC and or a administrator user.
Summary
Prevents the plugin from overwriting
os.homedir()
or the Joplin profile directory.Rationale
laurent22/joplin#9857 suggests backing up to a subdirectory of the home directory by default. One way to do this is to set Simple Backup's
path
setting to the HOME directory.Without additional checks, this could be dangerous if a user unchecks the "create subfolder" option.
Alternatives
Testing
This pull request has a related automated test. However, this only tests one part of this pull request.
To test the pull request manually,
.config
directory (e.g./home/user/.config/
)This has been tested successfully with commit 2f8ccda on OpenSUSE 20240202 with Joplin 2.14.12.