Skip to content

feat(backend): switch API token storage to hmac digest - #12850

Merged
SchrodingersGat merged 19 commits into
inventree:masterfrom
matmair:matmair/issue12027
Sep 16, 2026
Merged

SchrodingersGat merged 19 commits into
inventree:masterfrom
matmair:matmair/issue12027

Conversation

@matmair

@matmair matmair commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

Replaces the old token which are stored in plaintext with a peppered version that uses a HMAC-SHA265 zu ensure that gaining database read access via a sidechannel or IDOR attack is not causing a privilege escalation. For now the secret key is used as a pepper; that might be replaced with a rotating pepper in the future.

After merge only v2 tokens (which are slightly longer and have a slightly different format) will be issued. Old issues keep being valid but there is no API path to issue them. As a breaking change in the future we might remove those code paths.

There a 2 things in here that I consider breaking:

  • the new tokens are longer
  • calling the /api/user/me/token/ endpoint reissues a new token now on every call (and invalidates that old one of the same name) as we can not read out the token anymore; we do not know it.

Fixes #12027

@matmair matmair added this to the 1.6.0 milestone Sep 14, 2026
@matmair matmair self-assigned this Sep 14, 2026
@matmair matmair added api Relates to the API security Relates to a security issue breaking Indicates a major update or change which breaks compatibility labels Sep 14, 2026
@netlify

netlify Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for inventree-web-pui-preview canceled.

Name Link
🔨 Latest commit 4b67356
🔍 Latest deploy log https://app.netlify.com/projects/inventree-web-pui-preview/deploys/6aa9d4d3e65d84000809372d

@codecov

codecov Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.24561% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.30%. Comparing base (2251571) to head (4b67356).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #12850      +/-   ##
==========================================
+ Coverage   87.25%   87.30%   +0.05%     
==========================================
  Files        1501     1502       +1     
  Lines      101997   102139     +142     
  Branches    11654    11557      -97     
==========================================
+ Hits        88994    89173     +179     
+ Misses      12938    12901      -37     
  Partials       65       65              
Flag Coverage Δ
backend 91.87% <98.24%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Backend Apps 92.53% <99.39%> (+0.01%) ⬆️
Backend General 94.72% <ø> (ø)
Frontend 79.92% <ø> (+0.09%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@matmair

This comment has been minimized.

@matmair

matmair commented Sep 15, 2026

Copy link
Copy Markdown
Member Author

@SchrodingersGat @wolflu05 ready for review; this should fix security issues where a staff user is able to read out a superusers or other users api key and such can gain more right than they originally had.

I have kept this PR pretty minimal but there are some other areas in which the schema might be altert in the future or this PR if you find it prudent:

  • token issues (user field) as a dedicated field
  • revocation reason (text field)
  • revocation warning (text) - a message to return to the user if this token is tried
  • token version (text) - this is infered now

One thing that worries me a bit: rotating a secret key now means all tokens are invalid; is this something we need to address or is that acceptable?

@matmair
matmair marked this pull request as ready for review September 15, 2026 06:31
@SchrodingersGat

Copy link
Copy Markdown
Member

@matmair looks good in general, I think that the existing token docs (/docs/docs/api/index.md#tokens) should be updated to include information on v2 schema, and a small section regarding rotation of the secret key

@matmair

matmair commented Sep 15, 2026

Copy link
Copy Markdown
Member Author

@matmair looks good in general, I think that the existing token docs (/docs/docs/api/index.md#tokens) should be updated to include information on v2 schema, and a small section regarding rotation of the secret key

i have extended the docs in this regard and added a few more fields to make this revocation behavior transparent to users / admins

@SchrodingersGat

Copy link
Copy Markdown
Member

API version needs a bump also?

@SchrodingersGat
SchrodingersGat merged commit dca516b into inventree:master Sep 16, 2026
52 checks passed
@SchrodingersGat
SchrodingersGat deleted the matmair/issue12027 branch September 16, 2026 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Relates to the API breaking Indicates a major update or change which breaks compatibility security Relates to a security issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FR] switch API token storage to hmac digest

2 participants