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

Use POST to change user selected language #10725

Closed
techknowlogick opened this issue Mar 14, 2020 · 3 comments · Fixed by #12785
Closed

Use POST to change user selected language #10725

techknowlogick opened this issue Mar 14, 2020 · 3 comments · Fixed by #12785
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented type/enhancement An improvement of existing functionality

Comments

@techknowlogick
Copy link
Member

Looking at logs of various Gitea instances, many robots crawl the change language functionality resulting in many additional pages indexed.

Perhaps we could change the "switch user language" functionality to POST so that a GET isn't an action that changes something. Similar to how logout, star, and user follow actions work now. I'm thinking an endpoint /switch_user_language, and a return_to query param to bring the user back to the page that they were on.

@techknowlogick techknowlogick added the type/proposal The new feature has not been accepted yet but needs to be discussed first. label Mar 14, 2020
@lafriks lafriks added type/enhancement An improvement of existing functionality and removed type/proposal The new feature has not been accepted yet but needs to be discussed first. labels Mar 14, 2020
@stale
Copy link

stale bot commented May 13, 2020

This issue has been automatically marked as stale because it has not had recent activity. I am here to help clear issues left open even if solved or waiting for more insight. This issue will be closed if no further activity occurs during the next 2 weeks. If the issue is still valid just add a comment to keep it alive. Thank you for your contributions.

@stale stale bot added the issue/stale label May 13, 2020
@techknowlogick techknowlogick added issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented and removed issue/stale labels May 13, 2020
@techknowlogick
Copy link
Member Author

So some investigation into this:

The i18n library we use already supports accepting language change requests via POST already

> http --form POST https://codeberg.org/explore/repos lang='es-ES'                                                                                                                             
HTTP/1.1 404 Not Found
Connection: close
Content-Type: text/html; charset=UTF-8
Set-Cookie: lang=es-ES; Path=/; Max-Age=2147483647; Secure;SameSite
....

Now, of course we can't have a POST to every route changing languages as not all routes support GETs (as we can see from my example that the explore page 404s), this means that no logic for handling changing language needs to be added, however an approach like I suggested above (using a special route) may be the best path. The special route, instead of handling language changes, would just redirect the user back to the page they were on. Redirects are always a tricky thing when it comes to security, but likely any concerns can be alleviated using CSRF params in the form.

@silverwind
Copy link
Member

Can we just use an Ajax call to change the language and then perform a page reload?

There's also a unnecessary ?lang=de-DE added to the URL after changing language which should no longer be an issue after Ajax.

@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants