Skip to content

Security Tips

This page is a work in progress!

Some information on this page may be inaccurate. Please do not consider these security tips as definitive or fully reliable.

Your token is the entry point to your bot. Anyone in possession of this authentication key will be able to fully control your bot at will and perform potentially malicious actions, such as raiding multiple Discord servers (where the bot is present).

This documentation page will show you the different things to know in order to maximize the security of your token and avoid leaks or malicious use.

Use environment variables

A .env file located in the root directory of your self-hosted bot allows you to securely store sensitive information such as the Discord authentication token or other secrets such as passwords and API keys, without including them directly in the source code. This helps prevent your token from leaking.

iHorizon reads its whole configuration this way: Bun loads the .env file at the root of the project on its own, and the bot takes its token from the BOT_TOKEN variable. There is nothing to change in the source code.

Here is an example of a .env file:

.env
# This is an example token
BOT_TOKEN="MzI1NzE3NzY4NTIzOTg1Njc4.YH8e3g.ABCdefGhIJKlmnopQRStUvWxYZ1234567890"

To create it, copy the template shipped with the bot and fill in BOT_TOKEN:

cp .env.example .env

The other variables of this file (database password, API keys...) are just as sensitive as the token. The Configuration page lists all of them.

Use a .gitignore file

If you plan to use services based on the git version control system such as GitLab, GitHub, or Codeberg to publish the source code of your bot, either privately or publicly, then it is wise to create and use a .gitignore file. This file tells git which files or folders it should ignore. These files or folders (and their contents) will therefore not be "tracked" or published. This file is useful, for example, to avoid publishing your node_modules (which are too large: hundreds of megabytes unnecessary to push to your repository) or your environment variables file .env.

Here is an example of a .gitignore file you can use as a base:

.gitignore
# Bot dependencies
node_modules/

# Environment variables
.env

In that case, your self-hosted bot's dependencies and environment variables will not be published to your Git repository. Of course, you can modify this file as you see fit to exclude other files or folders that you feel are important to keep out of Git.