Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Security: florimondmanca/djangorestframework-api-key

Security

docs/security.md

Implementation details

Key generation scheme

An API key is composed of two items:

  • A prefixP, which is a generated string of 8 characters.
  • A secret keySK, which is a generated string of 32 characters.

The generated key that clients use tomake authorized requests isGK = P.SK. It is treated with the same level of care as passwords:

  • Only a hashed version is stored in the database. The hashing algorithm is sha512.1
  • The generated key is shown only once to the client upon API key creation.

Grant scheme

Access is granted if and only if all of the following is true:

  1. The configured API key header is present and correctly formatted.2
  2. A usable API key with the prefix of the given key exists in the database.3
  3. The hash of the given key matches that of the API key.

Caveats

API keys ≠ Security: depending on your situation, you should probably not use API keys only to authorize your clients.

Besides, it is NOT recommended to use this package for authentication, i.e. retrieving user information from API keys.

Indeed,using API keys shifts the responsibility of Information Security on your clients. This induces risks, especially if obtaining an API key gives access to confidential information or write operations. For example, an attacker could impersonate clients if they let their API keys leak.

As a best practice, you should apply thePrinciple of Least Privilege: allow only those who require resources to access those specific resources. In other words:if your client needs to access an endpoint, add API permissions on that endpoint only instead of the whole API.

Besides, it is highly recommended to serve the API overHTTPS to ensure the confidentiality of API keys passed in requests.

Act responsibly!

Footnotes

  1. Older versions of this module used the same hashers as Django'sPASSWORD_HASHERS. These hashers come with a large performance penalty and while critical for passwords, they aren't needed for high-entropy, randomly generated keys like the ones created by this module. Keys stored using these slower hashers will be upgraded when used.

  2. To customize this behavior, seeAPI key parsing.

  3. Only unrevoked keys are usable by default, but this can be customized with acustom manager.

There aren’t any published security advisories


[8]ページ先頭

©2009-2025 Movatter.jp