Skip to main content

A tool to analyze your Django app access control

Project description

Django Access Inspector

Django Access Inspector is a comprehensive access control app for Django that helps you enforce fine-grained access control on your views. It provides a flexible and easy-to-use interface to check and analyze authentication and permission classes for each view in your Django project.

Installation

To install Django Access Inspector, you can use pip, poetry, or uv. Here are the commands:

pip install django-access-inspector
poetry add django-access-inspector
uv add django-access-inspector

After installing, make sure to add "django_access_inspector" to your INSTALLED_APPS setting in your Django project's settings.py file:

INSTALLED_APPS = [
    ...,
    "django_access_inspector",
]

Usage

Basic Usage

To run Django Access Inspector, use the following command:

python manage.py inspect_access_control

By default, it will provide a human-readable output. If you prefer a JSON output, you can use the --output json flag:

python manage.py inspect_access_control --output json

CI Mode

Django Access Inspector supports a CI mode that helps ensure your application's access control remains secure over time. This mode uses snapshots to track the current state of your endpoints and fails if new unauthenticated or unchecked endpoints are introduced.

Generating a Snapshot

First, generate a baseline snapshot of your current access control state:

python manage.py inspect_access_control --snapshot baseline.json

This will save the current state of all your endpoints to a JSON file.

Running in CI Mode

In your CI pipeline, use the snapshot to validate that no new security issues have been introduced:

python manage.py inspect_access_control --ci --snapshot baseline.json

The command will:

  • Compare the current analysis with the saved snapshot
  • Exit with code 0 if no new security issues are found
  • Exit with code 1 if new unauthenticated or unchecked endpoints are detected
  • Display detailed information about any changes found

This is particularly useful in CI/CD pipelines to prevent introducing new security vulnerabilities.

Debug Mode

When you need to troubleshoot authentication detection issues, you can enable detailed debug logging:

python manage.py inspect_access_control --debug

Debug mode provides detailed information about:

  • URL pattern extraction process
  • View function discovery and analysis
  • Authentication and permission detection logic
  • Categorization decisions for each endpoint
  • Detailed analysis of Django and DRF authentication mechanisms

This helps you understand why certain endpoints might be categorized as "unchecked" and allows you to verify that the tool correctly identifies your authentication setup.

Example

cli example output

Here's an interpretation of the output:

  • Unchecked views: Views that Django Access Inspector was not able to check. As the tool is still a work in progress, we aim to make it check all views in the future.
  • Model Admin views: Views generated by Django Admin that are checked with the Django Admin permission system.
  • Views: All views that Django Access Inspector was able to check, including their authentication and permission classes.

MCP Server (LLM Integration)

Django Access Inspector ships with a Model Context Protocol (MCP) server so LLM tools and editors can call the inspector programmatically. The server runs over STDIO and exposes a tool and a prompt designed for security reviews of your endpoints.

Start the server

Run the Django management command from your project:

python manage.py start_mcp_server

Enable debug logging:

python manage.py start_mcp_server --debug

If you prefer uv:

uv run manage.py start_mcp_server

Convenience targets (if using this repo):

make start_mcp      # starts the MCP server
make inspector      # opens the MCP Inspector UI

Try it with MCP Inspector

You can explore the server using the official MCP Inspector:

npx @modelcontextprotocol/inspector

In the Inspector, choose to launch a server and enter the command you use locally, for example python manage.py start_mcp_server (or uv run manage.py start_mcp_server). The Inspector will connect over STDIO and list the available tools and prompts.

Exposed tools and prompts

The server exposes one tool and one prompt:

  • analyze_endpoints(endpoint: str = "", snapshot_path: str = "")

    • Analyze all endpoints (no args) or a single endpoint by name.
    • When snapshot_path is provided, returns only CI‑failing changes compared to the snapshot (new unauthenticated or new unchecked endpoints).
    • Returns structured JSON with a summary and endpoint lists.
  • security_analysis_prompt(endpoint_name: str = "", snapshot_path: str = "")

    • Generates a ready‑to‑use Markdown prompt to guide an LLM through a security assessment workflow for your endpoints.

Notes

  • Transport is STDIO; no network port is opened.
  • The server relies on your Django project settings (same as other management commands). Ensure your environment can import your project and INSTALLED_APPS includes "django_access_inspector".
  • The MCP integration uses fastmcp under the hood and is included as a dependency.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_access_inspector-0.4.2.tar.gz (38.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_access_inspector-0.4.2-py3-none-any.whl (52.1 kB view details)

Uploaded Python 3

File details

Details for the file django_access_inspector-0.4.2.tar.gz.

File metadata

  • Download URL: django_access_inspector-0.4.2.tar.gz
  • Upload date:
  • Size: 38.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.14.2

File hashes

Hashes for django_access_inspector-0.4.2.tar.gz
Algorithm Hash digest
SHA256 d14ec53f75f26a9ac576b8368a16e767a4f98b757791156ca066c64c93776d75
MD5 856a02a02d8ec96a4b6f916b91ad54d8
BLAKE2b-256 a5285aa134e4d43d3a8748ea11dc58acd940759468e2c961f7f5860d41d03108

See more details on using hashes here.

File details

Details for the file django_access_inspector-0.4.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_access_inspector-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a214012b46159f39bff9a53da64c51d4ac788235bd83933e3fc7f4d75a146c12
MD5 3f8f649bd534996de8b3f174f16d1165
BLAKE2b-256 fce25578c52be7c3dbd4e714974cf80d0f45d30bf1fcd44fd8dd2d5255b841e4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page