API tokens are stored in cleartext in the database #10818

Closed
opened 2025-12-29 21:36:16 +01:00 by adam · 2 comments
Owner

Originally created by @hikhvar on GitHub (Feb 27, 2025).

Deployment Type

Self-hosted

NetBox Version

v4.2.3

Python Version

3.12

Steps to Reproduce

Create an API token via the UI or API.

Then connect to the database and run the following sql to see all tokens in clear text:

SELECT t.key
FROM public.users_token t

Expected Behavior

I expect the tokens to be hashed with a salt in the database, as we do it for passwords. An attacker obtaining a dump of the database (e.g. restoring a backup/finding a dump) can easily now impersonate everyone in the netbox API.

Observed Behavior

The SQL query gives away all tokens in clear text.

Originally created by @hikhvar on GitHub (Feb 27, 2025). ### Deployment Type Self-hosted ### NetBox Version v4.2.3 ### Python Version 3.12 ### Steps to Reproduce Create an API token via the UI or API. Then connect to the database and run the following sql to see all tokens in clear text: ``` SELECT t.key FROM public.users_token t ``` ### Expected Behavior I expect the tokens to be hashed with a salt in the database, as we do it for passwords. An attacker obtaining a dump of the database (e.g. restoring a backup/finding a dump) can easily now impersonate everyone in the netbox API. ### Observed Behavior The SQL query gives away all tokens in clear text.
adam closed this issue 2025-12-29 21:36:16 +01:00
Author
Owner

@jeremystretch commented on GitHub (Feb 27, 2025):

This is by design. Please use the feature request template to propose changes to existing behavior.

@jeremystretch commented on GitHub (Feb 27, 2025): This is by design. Please use the [feature request template](https://github.com/netbox-community/netbox/issues/new?template=01-feature_request.yaml) to propose changes to existing behavior.
Author
Owner

@hikhvar commented on GitHub (Feb 27, 2025):

Can I read up the design decision back then? I know this PR when ALLOW_TOKEN_RETRIEVAL was introduced. The thread modelling there where that somebody as access to the shell of netbox. What was not considered back then, that somebody got access to the database or a backup/dumb of that database.

@hikhvar commented on GitHub (Feb 27, 2025): Can I read up the design decision back then? I know this [PR](https://github.com/netbox-community/netbox/issues/8853#issuecomment-1276544219) when ALLOW_TOKEN_RETRIEVAL was introduced. The thread modelling there where that somebody as access to the shell of netbox. What was not considered back then, that somebody got access to the database or a backup/dumb of that database.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10818