-
Notifications
You must be signed in to change notification settings - Fork 1.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
Support browser query parameters on chat start #1239
Support browser query parameters on chat start #1239
Conversation
…tion of credentials in fetch
Hi @qtangs, thanks a bunch for this PR! I fully agree that having access to query parameters is a hot topic which many users, myself included, are aching for. In fact, I'd like to have this in chainlit in weeks rather than months. However, I am not sure if your proposed patch is the way to go. First of all, as I mentioned in #1213 , providing a full Secondly, having read your patch, you seem to be using the HTTP referrer header rather than the actual URL. Most notably, the referrer header is optional and not validated server-side, whereas, the request URL is validated by the server. They represent different things and can lead to unexpected behaviour and possibly, security issues! Specifically in your case, your patch seems to contain a lot of code which related specifically to authentication rather than mere access to the query header. Any referrer based authentication is a classic foot gun for security and not the way to go. Perhaps a resource like this might provide background on it: https://web.dev/articles/referrer-best-practices I also see you included fixes for one pre-existing issue and some additional issues as part of this PR. That's great! As it seems we still have some architectural decisions to take on the query params, perhaps it would be easier for us to have them as part of separate pull requests. Any chance you're able to pry the parts not related to query params out and fire (preferably) multiple PR's, one for each separate issue, with enough information for us to replicate the issue while we review your fixes? I know it's a lot to ask for, but reviewing all these issues at the same time makes it harder to do a thorough review and especially with auth stuff that can lead to dire consequences. Thanks for understanding! |
Hey @dokterbob, thanks for the super quick response to this. Really appreciate your taking time to look into these important issues. Let me try to respond as best as I can. I think you brought some very good points and I really like the Request object idea, in fact it'd be very useful to have it in many other handlers besides
Happy to discuss further. |
Hi @qtangs, This is what I ❤️ about open source. :)
Because the way chainlit is developed, as a websocket-based SPA app, the concept of a request is not so clearly defined. Rather, the websocket session (in addition to the data layer's session) is what's used to keep state. This is probably why a However, as we're finding now, having access to headers, query parameters etc. is essential to allow dev's like ourselves to go wild in terms of amazing features we want to implement. We don't always have a well-defined The auth issue is a bit of a trickier beast and, if I'm entirely honest, given the amount of issues related to auth and the insane variety of auth options, my current stance (which we still need to align on amongst maintainers!) is that we should delegate all auth to third-party libraries so we can focus on a silky smooth LLM-chat experience.
If you would do this, this seems to be the most obvious way to include this chunk of your work at this point. Please, provide
But your patch does add it to the tests. Tests are often used as a form of (authoritative, known to be working) example for other devs and (potentially) insecure examples are really something we should take care to stay clear of. As for now, I will be closing the current PR in favour of a PR with an (optional) To avoid that, in the future, I suggest using an issue to propose features to allow others to comment on it and to hold space to form a clearly crystallised concept before firing the PR -- that will provide a straight path to getting your code shipped out. (I hope to add this info to the contribution instructions once the process is a bit more crystallised itself. :p) Thanks for understanding and please keep the good contrib coming! |
@dokterbob I understand your decision. Will see what else can be done. For the moment, at least the code will be here as a reference for a quick workaround while waiting for the proper solution once Request object is made available. Rooting for this: :)
|
Here's my attempt to address this much-discussed issue: Make browser query parameters available in @on_chat_start
Also fix this bug: Logout Button Causing Issue w/ Header Auth
Here are the changes:
I have tested on my app: https://2in.ai