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

Attempting to create a team with the URL of an existing team shows the wrong error message #26841

Closed
hmhealey opened this issue Apr 22, 2024 · 8 comments · Fixed by #26956
Closed
Assignees

Comments

@hmhealey
Copy link
Member

Repro steps:

  1. Click on the header of the channel list in the sidebar of the web app
  2. Click on Create Team
  3. On the Team Name scree, enter anything and click Next
  4. On the Team URL screen, change the URL to be the URL of an existing team
  5. Click Finish

Observed: The error message reads “Must call update for existing team.”
image-20240416-175228
Expected: The error message reads “A team with that URL already exists.”


To do this, we should have the web app intercept the existing error message by its ID and show the more friendly error message instead.


If you're interested please comment here and come join our "Contributors" community channel on our daily build server, where you can discuss questions with community members and the Mattermost core team. For technical advice or questions, please join our "Developers" community channel.

New contributors please see our Developer's Guide.

JIRA: https://mattermost.atlassian.net/browse/MM-57877

@MeHow25
Copy link
Contributor

MeHow25 commented Apr 22, 2024

Can you assign me?

@MeHow25
Copy link
Contributor

MeHow25 commented Apr 23, 2024

@hmhealey I was trying to reproduce this bug accordingly to your description and for me it shows a different error message. I added a screenshot of the message at the bottom. Honestly, for me it looks quite friendly. What do you think?

Can you also tell me what version of Mattermost are you using here? I'm using Mattermost Team Edition with the latest master branch.

image

@hmhealey
Copy link
Member Author

I also saw the "This URL is taken" error message when I just tested on my admin account, but I see the incorrect error message on my other account, so there's something else going on here. It seems like either there's something here caused by incorrect permissions or perhaps it has to do with being on that other team.

Hopefully that gives you something to work off of, but let me know if neither of those end up being the issue, and I can take another look.

Also, if it still matters, I'm on the latest master branch as well

@MeHow25
Copy link
Contributor

MeHow25 commented Apr 25, 2024

@hmhealey thanks for a hint about permissions. I found a way to recreate this behavior.

Here are the steps to reproduce the bug:

  1. Create User No. 1.
  2. Create a team with the URL “/lorem” using that user, but do not invite anyone.
  3. Create User No. 2.
  4. As User No. 2, attempt to create a new team with the same URL “/lorem.”
  5. An error message stating “Must call update for existing team” will be displayed.

Now I'm trying to fix the issue.

@MeHow25
Copy link
Contributor

MeHow25 commented Apr 27, 2024

@hmhealey I believe I've identified the code responsible for this issue. The team.go file contains a teamExists function that checks if the name of a new team is available or already taken, but I'm puzzled by its logic. Not only does it verify the team name, but it also checks if the current user has access to that team if it exists. If the user lacks access, the function returns false, implying the team doesn't exist. Shouldn't it return true instead?

I'm curious about this because the teamExists function is invoked during team creation and it's causing this issue.

Here is the link to this function:

func teamExists(c *Context, w http.ResponseWriter, r *http.Request) {

@hmhealey
Copy link
Member Author

Looking back further, that permission check goes back to #12130 which is to fix a minor security issue where guest users could figure out if a team exists using that endpoint when they shouldn't have been able to. Unfortunately, that makes it so that the teamExists API is kind of useless for what it's supposed to do.

Since I don't think we can change the API to make that more helpful, I guess the next best thing would be to detect the "must call update" error in the frontend and show a nicer error message to the end user. There's an error ID that you could use for that.

How does that sound?


Also, CC @jespino in case he has any ideas for how to make that API more useful again for non-admin, non-guest users

@MeHow25
Copy link
Contributor

MeHow25 commented May 1, 2024

@hmhealey Sure. The error on the frontend side comes from this line of code where we are calling the endpoint to create a team:

const createTeamData = await createTeam(teamSignup.team);

I'm just not sure what should be the error message here. Wouldn't A team with that URL already exists also cause the same security issue? Maybe it should be something more general like You cannot use this URL?

@hmhealey
Copy link
Member Author

hmhealey commented May 3, 2024

That's a good point. I guess the difference here is that the createTeam endpoint requires stricter permissions than teamExists, and guests shouldn't have that permission so they'd get a "permission denied" before they could find if a team with that URL exists.

Because of that, I think it's fine to still use "A team with this URL already exists" in this case

hmhealey added a commit that referenced this issue May 13, 2024
* Add new error message

* make i18n-extract

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Co-authored-by: Harrison Healey <harrisonmhealey@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants