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

fix(ai-help): handle invalid chat ids correctly #11678

Merged
merged 6 commits into from
Sep 10, 2024

Conversation

argl
Copy link
Contributor

@argl argl commented Aug 23, 2024

Summary

This fixes an issue where an AI Help URL with a chat id parameter (&c=...) is being requested and the chat referenced either

  • has been deleted
  • does belong to a different user

While not leaking information to unauthorized accounts, there were a set of of confusing errors displayed.

The behaviour now has changed. If the chat belongs to a different user or has been deleted, the backend's 404 response is being catched and the user gets a fresh AI Help chat with the parameter cleared from the URL.

We also clear the plate if history is disabled for the user.

(MP-1455)

How did you test this change?

1

  • With history enabled, create a chat. Click on the corresponding history item to include the chat id parameter in the URL.
  • Copy/note down the URL
  • Log in to another account
  • Paste the URL from above
  • Response is a pristine AI Help page and the parameter has been cleared from the URL.

2

  • Log in to the original account
  • Delete the chat from the history
  • Paste the URL from above
  • Response is a pristine AI Help page and the parameter has been cleared from the URL.

3

  • Log into the original account
  • Turn off history
  • Paste the URL from above
  • Response is a pristine AI Help page and the parameter has been cleared from the URL.

4

  • Log into the secondary account
  • Turn history off
  • Paste in the URL from above
  • Response is a pristine AI Help page and the parameter has been cleared from the URL.

@github-actions github-actions bot added plus work around features related to MDN Plus plus:ai-help labels Aug 23, 2024
@argl argl marked this pull request as ready for review August 23, 2024 15:14
@argl argl requested a review from a team as a code owner August 23, 2024 15:14
@argl argl changed the title Mp 1455 ai url sharing fix fix(ai-help): handle invalid chat ids correctly Aug 23, 2024
@fiji-flo fiji-flo self-requested a review September 3, 2024 09:30
Copy link
Member

@LeoMcA LeoMcA left a comment

Choose a reason for hiding this comment

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

Looks fine, but might be possible to do this with useSearchParams directly.

Also missing a useEffect depencency

Comment on lines 416 to 421
navigate(
{
search: searchParams.toString(),
},
{ replace: true }
);
Copy link
Member

Choose a reason for hiding this comment

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

I think it might be possible to just use useSearchParams if the docs can be believed:

The setSearchParams function works like navigate, but only for the search portion of the URL. Also note that the second arg to setSearchParams is the same type as the second arg to navigate.
https://reactrouter.com/en/main/hooks/use-search-params

Something like:

const [_, setSearchParams] = useSearchParams();

...

setSearchParams(
  (searchParams) => {
    const x = new URLSearchParams(searchParams)
    x.delete("c")
    return x
  },
  { replace: true }
)

@fiji-flo fiji-flo merged commit 225fe24 into main Sep 10, 2024
15 checks passed
@fiji-flo fiji-flo deleted the MP-1455-ai-url-sharing-fix branch September 10, 2024 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plus:ai-help plus work around features related to MDN Plus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants