diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-09-11 17:03:51 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-11 17:03:51 +0800 |
commit | 998cea5888cb895159e35caf9fec969c440399d0 (patch) | |
tree | 1edbaa65443a824bcc1bbe2d1229a8ed7679214b /modules | |
parent | 6d96f0b0d1c74523b9f3d26360aa63d92c307959 (diff) | |
download | gitea-998cea5888cb895159e35caf9fec969c440399d0.tar.gz gitea-998cea5888cb895159e35caf9fec969c440399d0.zip |
Use secure cookie for HTTPS sites (#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.
![image](https://github.com/go-gitea/gitea/assets/2114189/7bc9a859-dcc1-467d-bc7c-1dd6a10389e3)
Diffstat (limited to 'modules')
-rw-r--r-- | modules/setting/session.go | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/modules/setting/session.go b/modules/setting/session.go index d0bc938973..664c66f869 100644 --- a/modules/setting/session.go +++ b/modules/setting/session.go @@ -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://")) SessionConfig.Gclifetime = sec.Key("GC_INTERVAL_TIME").MustInt64(86400) SessionConfig.Maxlifetime = sec.Key("SESSION_LIFE_TIME").MustInt64(86400) SessionConfig.Domain = sec.Key("DOMAIN").String() |