mirror of
https://github.com/healthchecks/healthchecks.git
synced 2026-04-25 15:05:49 +03:00
[PR #1167] [MERGED] Store API keys in the database in hashed form #1085
Labels
No labels
bug
bug
bug
feature
good-first-issue
new integration
pull-request
question
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/healthchecks#1085
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/healthchecks/healthchecks/pull/1167
Author: @cuu508
Created: 5/30/2025
Status: ✅ Merged
Merged: 6/2/2025
Merged by: @cuu508
Base:
master← Head:hashed_api_keys📝 Commits (9)
9a8366fStore API keys in the database in hashed formcbe282dFix mypy warningsb6cfaa4Add Project.set_ping_key()f42fdafAdd testsfe06619Use "." as a delimiter between key[:8] and key hash5c435d3Remove "Show Keys" button552a44cFix "create key" and "revoke" click handlers to not add "#" to URL583e557Update Prometheus docse6d96b0Remove "show_keys" template variable📊 Changes
14 files changed (+281 additions, -127 deletions)
View changed files
📝
hc/accounts/models.py(+51 -0)📝
hc/accounts/tests/test_project.py(+21 -23)📝
hc/accounts/views.py(+3 -18)📝
hc/api/decorators.py(+47 -9)➕
hc/api/tests/test_auth.py(+71 -0)📝
static/css/project.css(+4 -0)➕
static/img/docs/prometheus_api_keys.png(+0 -0)➖
static/img/docs/prometheus_endpoint.png(+0 -0)📝
static/img/integrations/setup_prometheus_1.png(+0 -0)📝
static/js/project.js(+25 -15)📝
templates/accounts/project.html(+33 -42)📝
templates/docs/configuring_prometheus.html-fragment(+8 -6)📝
templates/docs/configuring_prometheus.md(+10 -6)📝
templates/integrations/add_prometheus.html(+8 -8)📄 Description
Currently API keys are stored in in plain text in the database.
The PR implements storing future API keys in a hashed form (the existing plain text API keys still work as before).
The format of the keys presented to the user:
hcw_sO9zU1olGylct7RMyUAkDaPMFHgx(prefixhcw_followed by 28 random characters)hcr_ZJz50yB761pJ0do1YOe56Iofng76(prefixhcr_followed by 28 random characters)(32 characters total)
The format of the keys stored in the database:
(73 characters total)
The value stored in the database includes first 8 plaintext characters of the key for the purpose of being able to efficiently look up a project by its API key –
HMAC is calculated from the full API key as presented to the user using python's hmac module:
Since the API keys (excluding the first 8 characters) are now stored in a hashed form, we can only show them to the user right after they are generated. The user will no longer be able to see their API keys in the Project Settings page at a later time.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.