Skip to main content

XCG security middleware for Django to mandate explicit authorization checks.

Project description

govtech-csg-xcg-viewpermissions

This package belongs to the eXtended Code Guardrails (XCG) project, which consists of a series of packages that harden the Django web framework to prevent common web application vulnerabilities.

Specifically, the View Permissions package modifies Django's default behaviour such that all views are "private" by default (i.e. inaccessible to all, whether authenticated or not). This acts as an extra layer of defense against coding mistakes or misconfigurations, forcing developers to explicitly define permissions for each view before they can be accessed. Access is given using Django's built in authentication and authorization system - for example through decorators such as django.contrib.auth.decorators.login_required - which should be familiar to existing Django developers.

Do note that the README in this repository is intentionally limited in scope and is catered towards developers. For detailed instructions on installation, usage, and community guidelines, please refer to the published documentation at https://xcg.tech.gov.sg.

Security-related matters

For instructions on how to report a vulnerability, refer to the official documentation website.

Additionally, enable email alerts for security issues by "watching" this repository. The "watch" button can be found near the top right corner of this repo's home page, and there are various options for configuring notification volume. To receive security alerts, either enable notifications for "All Activity" or "Custom -> Security alerts".

Installing development dependencies

Before building or testing the package, or committing changes, install the development dependencies into a virtual environment:

# In the project root directory
python -m venv .venv && source .venv/bin/activate
pip install -r requirements-dev.txt

Building

The package can be built using build as the build frontend and setuptools as the build backend.

Run the build command below:

# In the project root directory
python -m build .

This creates a directory named dist/, which should contain 2 files:

  1. A .whl (wheel) file, which is a binary distribution format for Python packages
  2. A .tar.gz file, which is a source distribution format for Python packages

To view the source files included in the source distribution, use the tar utility as follows:

tar --list -f dist/<filename>.tar.gz

To install the package directly from either distribution files:

pip install <name_of_distribution_file>

Testing

This project leverages on the Django test runner to run tests. Starting from the project root directory, execute the commands below to run the test suite:

pip install -e . # Performs an "editable install" of the govtech-csg-xcg-viewpermissions package
cd tests
python manage.py test

Running pre-commit hooks

Note: This section is only relevant if you intend to contribute code

This project uses the pre-commit tool to run Git pre-commit hooks for linting and code quality checks. The pre-commit tool itself should have been installed along with the development dependencies. After cloning the repository for the first time, run the command below to "install" the Git hooks:

pre-commit install

The command above creates a file .git/hooks/pre-commit, which defines the shell commands to run before any Git commit is created.

Subsequently, any invocation of git commit will trigger the commands, rejecting the commit if there are linting errors. Issues should be automatically fixed, but you will need to re-stage the changes before attempting the commit again.

For a list of hooks run by pre-commit, see its configuration file.

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

govtech-csg-xcg-viewpermissions-0.1.0.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file govtech-csg-xcg-viewpermissions-0.1.0.tar.gz.

File metadata

File hashes

Hashes for govtech-csg-xcg-viewpermissions-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3739d4b119e25e25593ee24e8d901fba30dd9c71aafdc01e46d29026b52acc46
MD5 6b243064355c711e5869ba12eb576850
BLAKE2b-256 fe07bc0df07c9a6185494ba85e58a6030f908d75d71feed9bff7869cfc3b9bf3

See more details on using hashes here.

File details

Details for the file govtech_csg_xcg_viewpermissions-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for govtech_csg_xcg_viewpermissions-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eb8cca7fcc8a832dd60c5894076d61df7c482d8ccd903e7e56450b9bdfb7ea96
MD5 7af664c1411dd71e44cae9c6afd4a936
BLAKE2b-256 3fb8cf34c31553ea952f04bf2d2f06a1235887c3b807f5031e2ebfcb5a04ac6c

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