-
Notifications
You must be signed in to change notification settings - Fork 1k
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
dokterbob
wants to merge
8
commits into
main
Choose a base branch
from
dokterbob/avatar_url_clientside
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8e41d78
* Minimal e2e test for documentation echo example.
dokterbob d924b4c
Only process default avatar name from config.
dokterbob 5369915
Revert "Allow spaces in avatar filenames. Fixes #1370. (#1418)"
dokterbob a82b991
Further limit allowed input to actually generated filenames.
dokterbob bea9c9e
Extend client-side substitution to replace any invalid characters wit…
dokterbob 2ae1954
Give it a type, too.
dokterbob 4b59baa
Refine ignores to not forget test settings etc.
dokterbob 6aa287a
Checkin echo e2e test settings.
dokterbob File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
[project] | ||
# Whether to enable telemetry (default: true). No personal data is collected. | ||
enable_telemetry = true | ||
|
||
|
||
# List of environment variables to be provided by each user to use the app. | ||
user_env = [] | ||
|
||
# Duration (in seconds) during which the session is saved when the connection is lost | ||
session_timeout = 3600 | ||
|
||
# Enable third parties caching (e.g LangChain cache) | ||
cache = false | ||
|
||
# Authorized origins | ||
allow_origins = ["*"] | ||
|
||
# Follow symlink for asset mount (see https://github.com/Chainlit/chainlit/issues/317) | ||
# follow_symlink = false | ||
|
||
[features] | ||
# Process and display HTML in messages. This can be a security risk (see https://stackoverflow.com/questions/19603097/why-is-it-dangerous-to-render-user-generated-html-or-javascript) | ||
unsafe_allow_html = false | ||
|
||
# Process and display mathematical expressions. This can clash with "$" characters in messages. | ||
latex = false | ||
|
||
# Automatically tag threads with the current chat profile (if a chat profile is used) | ||
auto_tag_thread = true | ||
|
||
# Allow users to edit their own messages | ||
edit_message = true | ||
|
||
# Authorize users to spontaneously upload files with messages | ||
[features.spontaneous_file_upload] | ||
enabled = true | ||
accept = ["*/*"] | ||
max_files = 20 | ||
max_size_mb = 500 | ||
|
||
[features.audio] | ||
# Sample rate of the audio | ||
sample_rate = 24000 | ||
|
||
[UI] | ||
# Name of the assistant. | ||
name = "My Assistant" | ||
|
||
# Description of the assistant. This is used for HTML tags. | ||
# description = "" | ||
|
||
# Large size content are by default collapsed for a cleaner ui | ||
default_collapse_content = true | ||
|
||
# Chain of Thought (CoT) display mode. Can be "hidden", "tool_call" or "full". | ||
cot = "full" | ||
|
||
# Link to your github repo. This will add a github button in the UI's header. | ||
# github = "" | ||
|
||
# Specify a CSS file that can be used to customize the user interface. | ||
# The CSS file can be served from the public directory or via an external link. | ||
# custom_css = "/public/test.css" | ||
|
||
# Specify a Javascript file that can be used to customize the user interface. | ||
# The Javascript file can be served from the public directory. | ||
# custom_js = "/public/test.js" | ||
|
||
# Specify a custom font url. | ||
# custom_font = "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap" | ||
|
||
# Specify a custom meta image url. | ||
# custom_meta_image_url = "https://chainlit-cloud.s3.eu-west-3.amazonaws.com/logo/chainlit_banner.png" | ||
|
||
# Specify a custom build directory for the frontend. | ||
# This can be used to customize the frontend code. | ||
# Be careful: If this is a relative path, it should not start with a slash. | ||
# custom_build = "./public/build" | ||
|
||
[UI.theme] | ||
default = "dark" | ||
#layout = "wide" | ||
#font_family = "Inter, sans-serif" | ||
# Override default MUI light theme. (Check theme.ts) | ||
[UI.theme.light] | ||
#background = "#FAFAFA" | ||
#paper = "#FFFFFF" | ||
|
||
[UI.theme.light.primary] | ||
#main = "#F80061" | ||
#dark = "#980039" | ||
#light = "#FFE7EB" | ||
[UI.theme.light.text] | ||
#primary = "#212121" | ||
#secondary = "#616161" | ||
|
||
# Override default MUI dark theme. (Check theme.ts) | ||
[UI.theme.dark] | ||
#background = "#FAFAFA" | ||
#paper = "#FFFFFF" | ||
|
||
[UI.theme.dark.primary] | ||
#main = "#F80061" | ||
#dark = "#980039" | ||
#light = "#FFE7EB" | ||
[UI.theme.dark.text] | ||
#primary = "#EEEEEE" | ||
#secondary = "#BDBDBD" | ||
|
||
[meta] | ||
generated_by = "1.2.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Echo app | ||
|
||
Based on [In Pure Python](https://docs.chainlit.io/get-started/pure-python) documentation section. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import chainlit as cl | ||
|
||
|
||
@cl.on_message | ||
async def main(message: cl.Message): | ||
"""Example from 'In Pure Python' docs section.""" | ||
# Your custom logic goes here... | ||
|
||
# Send a response back to the user | ||
await cl.Message( | ||
content=f"Received: {message.content}", | ||
).send() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { runTestServer, submitMessage } from '../../support/testUtils'; | ||
|
||
describe('Basic echo example', () => { | ||
before(() => { | ||
runTestServer(); | ||
}); | ||
|
||
describe('Steps', () => { | ||
beforeEach(() => { | ||
cy.visit('/'); | ||
submitMessage("I'm functional."); | ||
cy.get('.step').as('steps'); | ||
}); | ||
|
||
it('should show 2 steps', () => { | ||
cy.get('@steps').should('have.length', 2); | ||
}); | ||
|
||
describe('User message', () => { | ||
beforeEach(() => { | ||
cy.get('@steps').eq(0).as('user_message'); | ||
}); | ||
|
||
it('should contain the submitted message ', () => { | ||
cy.get('@user_message').should('contain', "I'm functional."); | ||
}); | ||
}); | ||
|
||
describe('AI message', () => { | ||
beforeEach(() => { | ||
cy.get('@steps').eq(1).as('ai_message'); | ||
}); | ||
|
||
it('should echo submitted message, prefixed by: "Received: "', () => { | ||
cy.get('@ai_message').should('contain', "Received: I'm functional."); | ||
}); | ||
|
||
describe('avatar', () => { | ||
beforeEach(() => { | ||
cy.get('@ai_message').find('.message-avatar').as('message_avatar'); | ||
cy.get('@message_avatar') | ||
.find('.MuiAvatar-root img') | ||
.as('avatar_img'); | ||
}); | ||
|
||
it('should have "My Assistant" as label', () => { | ||
cy.get('@message_avatar') | ||
.find('.MuiAvatar-root') | ||
.should('have.attr', 'aria-label', 'My Assistant'); | ||
}); | ||
|
||
it('should load /avatars/my_assistant', () => { | ||
cy.get('@avatar_img') | ||
.should('have.length', 1) | ||
.should('have.attr', 'src') | ||
.and('include', '/avatars/my_assistant'); | ||
|
||
cy.get('@avatar_img') | ||
.should('be.visible') | ||
.and(($img) => { | ||
const img = $img[0] as HTMLImageElement; | ||
expect(img.naturalWidth).to.be.greaterThan(0); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 don't think doing this in the client is a good idea since developers also use chainlit with custom frontends
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.
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.
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.
Proposed compromise:
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.