# Gitea: "SECRET\_KEY" usage and security

**URL:** <https://forum.gitea.com/t/gitea-secret-key-usage-and-security/9061>\
**Category:** Install/Maintain/Configure\
**Created:** [April 30, 2024, 9:43am UTC](https://forum.gitea.com/t/gitea-secret-key-usage-and-security/9061 "2024-04-30T09:43:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Niclas](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/niclas/32/2616_2.png) [@Niclas](https://forum.gitea.com/u/Niclas)\
**Post date:** [April 30, 2024, 9:43am UTC](https://forum.gitea.com/t/gitea-secret-key-usage-and-security/9061/1 "2024-04-30T09:43:52Z")

</div>

Hey there, I´v setted up a new gitea Instance and noticed that under:

```auto
[security]                                                  
INSTALL_LOCK = true                                         
SECRET_KEY =       

```

the Secret Key is empty. After some research, i found out, that if this happend a hardcoded default value will be used.  
My Questions are:

What doses this actually encrypts?

If the Secret is hardcoded, isn t it a security risk, because its the same over most of the instances? If for example my Database is compromised, everybody can decrypt my Secrets, because the Key is global and not random per Instance?

Thanks for help!

---

<div class="post-metadata">

**Author:** ![remram44](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/remram44/32/3152_2.png) [@remram44](https://forum.gitea.com/u/remram44)\
**Post date:** [May 3, 2024, 2:06am UTC](https://forum.gitea.com/t/gitea-secret-key-usage-and-security/9061/2 "2024-05-03T02:06:08Z")

</div>

That’s why it is not hardcoded, you can set your own value, and you should.

There is an open issue about rotating this secret, for example from the empty value to a unique secret value: [Secret rotation / secret loss recovery · Issue #16832 · go-gitea/gitea · GitHub](https://github.com/go-gitea/gitea/issues/16832)

---

<div class="post-metadata">

**Author:** ![Niclas](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/niclas/32/2616_2.png) [@Niclas](https://forum.gitea.com/u/Niclas)\
**Post date:** [May 12, 2024, 11:01am UTC](https://forum.gitea.com/t/gitea-secret-key-usage-and-security/9061/3 "2024-05-12T11:01:22Z")

</div>

So there is no way to change it yet?

Maybe it would be a good approach, to set a random string at default installation.

---

<div class="post-metadata">

**Author:** ![matrss](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/matrss/32/5936_2.png) [@matrss](https://forum.gitea.com/u/matrss)\
**Post date:** [May 14, 2024, 9:41am UTC](https://forum.gitea.com/t/gitea-secret-key-usage-and-security/9061/4 "2024-05-14T09:41:31Z")

</div>

I also just noticed that my gitea instance has an empty SECRET\_KEY set since installation. What are the implications of this for an internet-facing gitea instance, with a trusted database (i.e. I don’t care if someone could decrypt stuff in the database, because I control it)? Is the SECRET\_KEY used for client-server communication in some way; could someone forge a session cookie knowing the SECRET\_KEY?

---

<div class="post-metadata">

**Author:** ![lunny](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/lunny/32/4701_2.png) [@lunny](https://forum.gitea.com/u/lunny)\
**Post date:** [May 25, 2024, 1:58pm UTC](https://forum.gitea.com/t/gitea-secret-key-usage-and-security/9061/5 "2024-05-25T13:58:46Z")

</div>

The secret\_key will be used to encrypt some sensetive data in the database. It will not be exposed out of Gitea and **WON’T** be used to encrypt/decrpt data from/to clients.

---

<div class="post-metadata">

**Author:** ![lunny](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/lunny/32/4701_2.png) [@lunny](https://forum.gitea.com/u/lunny)\
**Post date:** [May 25, 2024, 2:00pm UTC](https://forum.gitea.com/t/gitea-secret-key-usage-and-security/9061/6 "2024-05-25T14:00:28Z")

</div>

I think we need a command line tool to regenerate a new security key and also replace all encrypted data on the database. So that the administrator could change the security key easily.

---

<div class="post-metadata">

**Author:** ![Niclas](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/niclas/32/2616_2.png) [@Niclas](https://forum.gitea.com/u/Niclas)\
**Post date:** [May 26, 2024, 7:56pm UTC](https://forum.gitea.com/t/gitea-secret-key-usage-and-security/9061/7 "2024-05-26T19:56:27Z")

</div>

If the Secret Key dose not encrypt anything in the Database, what’s its purpose?
