Skip to content
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

Sanitise the note's path #148

Merged
merged 2 commits into from Dec 4, 2017
Merged

Sanitise the note's path #148

merged 2 commits into from Dec 4, 2017

Conversation

korelstar
Copy link
Member

I've implemented some enhancements in order to let the notes app to be more fail-safe.

  • Remove characters in note's file path (i.e. note's title and category) that are forbidden on other operating systems (i.e. Windows). The problem is, that we can title a note Math <> Philosophy on a (linux) server, but when the user wants to synchronize the account with a Windows system, synchronization fails. Therefore, we should remove all characters that lead to failed synchronization (fixes Solution for reserved characters in filenames notes-android#228).
  • Renaming a note (e.g. title or category has changed) can lead to an exception. Until now, we only catched the NotPermittedException (user has not the right to write to a (shared) folder), but other exceptions can happen, too (e.g. InvalidPathException if the filename is invalid due to several reasons). Those are now catched, too. This allows the note content to be saved while although renaming has failed.
  • An example for when the InvalidPathException is thrown, is when using an emoji in the title and having a MySQL database without 4-byte support. The new function sanitisePath removes such illegal characters from the path in such a case (fixes Creating a note with emoji in the title constantly spawns New Note, New Note (2) etc while trying to sync notes-android#237).

@korelstar korelstar added the bug Something isn't working label Nov 4, 2017
Copy link
Member

@Henni Henni left a comment

Choose a reason for hiding this comment

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

two minor comments
Otherwise looks good!

\xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
| [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
| \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
)%xs', '', $str);
Copy link
Member

Choose a reason for hiding this comment

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

Would you mind adding some explanatory comments to this regex magic?

@@ -222,9 +246,6 @@ private function getSafeTitleFromContent($content) {
$title = $this->l10n->t('New note');
}

// prevent directory traversal
$title = str_replace(array('/', '\\'), '', $title);
Copy link
Member

Choose a reason for hiding this comment

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

Did you look at the core code and how it is prevented there?
I would prefer if we wouldn't have to implement this ourselves...

@korelstar
Copy link
Member Author

korelstar commented Nov 14, 2017 via email

@Henni
Copy link
Member

Henni commented Nov 14, 2017

@korelstar thanks for the clarification.
I would be happy with a short reference to the core code inside a comment for both code pieces.

@korelstar
Copy link
Member Author

done

@Henni Henni merged commit 8018c30 into master Dec 4, 2017
@Henni Henni deleted the sanitise branch December 4, 2017 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants