-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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 secure cookie for HTTPS sites #26999
Conversation
c770513
to
c9d0ec9
Compare
@@ -50,7 +50,7 @@ func loadSessionFrom(rootCfg ConfigProvider) { | |||
} | |||
SessionConfig.CookieName = sec.Key("COOKIE_NAME").MustString("i_like_gitea") | |||
SessionConfig.CookiePath = AppSubURL + "/" // there was a bug, old code only set CookePath=AppSubURL, no trailing slash | |||
SessionConfig.Secure = sec.Key("COOKIE_SECURE").MustBool(false) | |||
SessionConfig.Secure = sec.Key("COOKIE_SECURE").MustBool(strings.HasPrefix(strings.ToLower(AppURL), "https://")) |
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.
On second thought, I would actually drop reading setting key at all and remove it from configs and leaving just this assignment based on app url. From security point of view there is no point in making it use unsecured cookie over https
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.
See #26953
Theoretically yes. But:
- There is no "dynamic cookie secure" support in the go-chi package (it could be improved separately)
- "dynamic cookie secure" will leave security problems if the site admin doesn't configure the X-Forwarded-Proto correctly, because Gitea self might be running in HTTP mode behind an HTTPS proxy.
- Why the
COOKIE_SECURE
is still kept because in case the user really would like to run Gitea on HTTP and HTTPS at the same time and they know what they are doing.
Maybe we can use a new (breaking) approach in 1.21 or 1.22 and drop COOKIE_SECURE then
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.
points 1 and 2 are not really relevant for this solution but as for 3 I don't really see such use-case so in name of security I would propose to drop this setting in future
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.
Sure, the change has been backported to 1.20, let's break it for 1.21 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.
points 1 and 2 are not really relevant for this solution but as for 3 I don't really see such use-case so in name of security I would propose to drop this setting in future
The case: #29451
I was unable to create a backport for 1.20. @wxiaoguang, please send one manually. 🍵
|
If the AppURL(ROOT_URL) is an HTTPS URL, then the COOKIE_SECURE's default value should be true. And, if a user visits an "http" site with "https" AppURL, they won't be able to login, and they should have been warned. The only problem is that the "language" can't be set either in such case, while I think it is not a serious problem, and it could be fixed easily if needed.
Backport #26999 If the AppURL(ROOT_URL) is an HTTPS URL, then the COOKIE_SECURE's default value should be true. And, if a user visits an "http" site with "https" AppURL, they won't be able to login, and they should have been warned. The only problem is that the "language" can't be set either in such case, while I think it is not a serious problem, and it could be fixed easily if needed.
* upstream/main: Add more package registry paths to the labeler (go-gitea#27032) Extract auth middleware from service (go-gitea#27028) S3: log human readable error on connection failure (go-gitea#26856) [skip ci] Updated translations via Crowdin Fix "delete" modal dialog for issue/PR (go-gitea#27015) Fix context cache bug & enable context cache for dashabord commits' authors (go-gitea#26991) fix: typo (go-gitea#27009) Use secure cookie for HTTPS sites (go-gitea#26999) Add fetch wrappers, ignore network errors in actions view (go-gitea#26985)
This PR contains the following updates: | Package | Update | Change | |---|---|---| | [docker.io/gitea/gitea](https://github.com/go-gitea/gitea) | patch | `1.20.4` -> `1.20.5` | --- ### ⚠ Dependency Lookup Warnings ⚠ Warnings were logged while processing this repo. Please check the logs for more information. --- ### Release Notes <details> <summary>go-gitea/gitea (docker.io/gitea/gitea)</summary> ### [`v1.20.5`](https://github.com/go-gitea/gitea/blob/HEAD/CHANGELOG.md#1205---2023-10-03) [Compare Source](go-gitea/gitea@v1.20.4...v1.20.5) - ENHANCEMENTS - Fix z-index on markdown completion ([#​27237](go-gitea/gitea#27237)) ([#​27242](go-gitea/gitea#27242) & [#​27238](go-gitea/gitea#27238)) - Use secure cookie for HTTPS sites ([#​26999](go-gitea/gitea#26999)) ([#​27013](go-gitea/gitea#27013)) - BUGFIXES - Fix git 2.11 error when checking IsEmpty ([#​27393](go-gitea/gitea#27393)) ([#​27396](go-gitea/gitea#27396)) - Allow get release download files and lfs files with oauth2 token format ([#​26430](go-gitea/gitea#26430)) ([#​27378](go-gitea/gitea#27378)) - Fix orphan check for deleted branch ([#​27310](go-gitea/gitea#27310)) ([#​27320](go-gitea/gitea#27320)) - Quote table `release` in sql queries ([#​27205](go-gitea/gitea#27205)) ([#​27219](go-gitea/gitea#27219)) - Fix release URL in webhooks ([#​27182](go-gitea/gitea#27182)) ([#​27184](go-gitea/gitea#27184)) - Fix successful return value for `SyncAndGetUserSpecificDiff` ([#​27152](go-gitea/gitea#27152)) ([#​27156](go-gitea/gitea#27156)) - fix pagination for followers and following ([#​27127](go-gitea/gitea#27127)) ([#​27138](go-gitea/gitea#27138)) - Fix issue templates when blank isses are disabled ([#​27061](go-gitea/gitea#27061)) ([#​27082](go-gitea/gitea#27082)) - Fix context cache bug & enable context cache for dashabord commits' authors([#​26991](go-gitea/gitea#26991)) ([#​27017](go-gitea/gitea#27017)) - Fix INI parsing for value with trailing slash ([#​26995](go-gitea/gitea#26995)) ([#​27001](go-gitea/gitea#27001)) - Fix PushEvent NullPointerException jenkinsci/github-plugin ([#​27203](go-gitea/gitea#27203)) ([#​27249](go-gitea/gitea#27249)) - Fix organization field being null in POST /orgs/{orgid}/teams ([#​27150](go-gitea/gitea#27150)) ([#​27167](go-gitea/gitea#27167) & [#​27162](go-gitea/gitea#27162)) - Fix bug of review request number ([#​27406](go-gitea/gitea#27406)) ([#​27104](go-gitea/gitea#27104)) - TESTING - services/wiki: Close() after error handling ([#​27129](go-gitea/gitea#27129)) ([#​27137](go-gitea/gitea#27137)) - DOCS - Improve actions docs related to `pull_request` event ([#​27126](go-gitea/gitea#27126)) ([#​27145](go-gitea/gitea#27145)) - MISC - Add logs for data broken of comment review ([#​27326](go-gitea/gitea#27326)) ([#​27344](go-gitea/gitea#27344)) - Load reviewer before sending notification ([#​27063](go-gitea/gitea#27063)) ([#​27064](go-gitea/gitea#27064)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zLjIiLCJ1cGRhdGVkSW5WZXIiOiIzNy4zLjIiLCJ0YXJnZXRCcmFuY2giOiJtYWluIn0=--> Reviewed-on: https://git.home/nrdufour/home-ops/pulls/129 Co-authored-by: Renovate <renovate@ptinem.io> Co-committed-by: Renovate <renovate@ptinem.io>
If the AppURL(ROOT_URL) is an HTTPS URL, then the COOKIE_SECURE's default value should be true.
And, if a user visits an "http" site with "https" AppURL, they won't be able to login, and they should have been warned. The only problem is that the "language" can't be set either in such case, while I think it is not a serious problem, and it could be fixed easily if needed.