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 avatar URL client-side #1420

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

dokterbob
Copy link
Collaborator

@dokterbob dokterbob commented Oct 9, 2024

More structural solution to #1370.

  • 'Echo' E2E test based on In Pure Python example from docs.[1]
  • Assertions for avatar loading and URL.
  • Sanitise avatar URL client-side, substituting anything other than [a-zA-Z0-9] with _.
  • Disallow spaces again in avatar names (e.g. only allow 'clean' filenames).
  • (Only) sanitise avatar filename when defaulting to config value.

[1] Instead of having chainlit start again and again, we can merge tests with identical configuration, significantly speeding up tests (chainlit takes several seconds every time to start). Making tests cheaper, will enable us to run and write more of them, faster, allowing for a more mature product.

@dokterbob dokterbob force-pushed the dokterbob/avatar_url_clientside branch from 369f481 to 775bc71 Compare October 9, 2024 17:46
@dokterbob dokterbob marked this pull request as ready for review October 9, 2024 18:00
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Oct 9, 2024
@dokterbob dokterbob requested a review from willydouhard October 9, 2024 18:01
@dosubot dosubot bot added backend Pertains to the Python backend. frontend Pertains to the frontend. labels Oct 9, 2024
@dokterbob dokterbob added the review-me Ready for review! label Oct 10, 2024
@@ -28,7 +38,9 @@ const MessageAvatar = ({ author, hide }: Props) => {
if (isAssistant && selectedChatProfile?.icon) {
return selectedChatProfile.icon;
}
return apiClient?.buildEndpoint(`/avatars/${author || 'default'}`);

const authorAvatarId = getAuthorAvatarId(author);
Copy link
Collaborator

Choose a reason for hiding this comment

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

i don't think doing this in the client is a good idea since developers also use chainlit with custom frontends

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe we can give custom frontend implementors (2-line!) instructions to implement this?

This patch would not only improve security, but being consistent in how we deal with filenames will make the developer experience much more robust. This would replace a . (and other characters, think unicode) with _, allowing any characters in avatar names.

We currently do not: a lot of author names will prevent the avatar from working. This patch solves that, fully, without compromising security again.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Proposed compromise:

  1. We keep allowing spaces and upper characters (basically not change the backend).
  2. We throw a deprecation error every time an 'invalid' URL comes in.
  3. We update the frontend code already.

This would let existing users know of what's coming, recover pre-existing functionality in cases of special characters, guarantee sufficient security for now and maximal security long-term.

@dokterbob dokterbob marked this pull request as draft October 17, 2024 11:17
@dokterbob
Copy link
Collaborator Author

I actually want to implement the compromise stated above before continuing. #1420 (comment)

@dokterbob dokterbob removed the review-me Ready for review! label Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Pertains to the Python backend. frontend Pertains to the frontend. size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants