ckanext-resource-type-validation
Overview
A CKAN extension that performs stricter validation of resource formats for uploaded files, ensuring that the file extension, file contents, and selected resource format are all compatible with each other.
- Reduces workload on back of house staff in fixing up format selection on miscategorised files.
- Better restrictions on allowed formats by also running them through magic/type sniffing systems. This ensures that an invalid file can't be uploaded by selecting a random format and changing the file type ending.
It is also possible to specify whitelists of allowed file extensions and/or allowed MIME types. Future development may allow a blacklist, but this is harder to make reliable.
This affects only uploaded resources. URL resources are not validated.
See the configuration file for more details.
Requirements
Compatibility with core CKAN versions:
| CKAN version | Compatibility |
|---|---|
| 2.7 | no |
| 2.8 | no |
| 2.9 | no |
| 2.10 | yes |
| 2.11 | yes |
| 2.12 | yes |
Installation
To install ckanext-resource-type-validation:
-
Install CKAN 2.10+.
-
Activate your CKAN virtual environment, eg:
. /usr/lib/ckan/default/bin/activate -
Install the extension into your virtual environment:
git clone https://github.com/qld-gov-au/ckanext-resource-type-validation.git cd ckanext-resource-type-validation pip install -e . pip install -r requirements.txt -
Add
resource_type_validationto theckan.pluginssetting in your CKAN config file (by default the config file is located at/etc/ckan/default/production.ini). -
Restart CKAN. Eg if you've deployed CKAN with Apache on Ubuntu:
sudo service apache2 reload
Configuration
ckan.plugins = resource_type_validation
Optional
# Path to the configuration file for specifying file types and their
# relationships. Defaults to built-in
# ckanext/resource_type_validation/resources/resource_types.json
ckanext.resource_validation.types_file = /path/to/file.json
# Support contact to list in any error messages
ckanext.resource_validation.support_contact = webmaster@example.com
# Whitelist of allowed mimetypes
ckan.mimetypes_allowed = application/pdf,text/plain,text/xml
The configuration file can contain the following, all optional and in any order:
-
allowed_extensions: A list of allowed file extensions, case-insensitive. If this is not specified, any extension is allowed. -
allowed_overrides: A dictionary specifying which MIME types are treated as subtypes of others, egapplication/xmlis a subtype oftext/plain, and anything is a subtype ofapplication/octet-stream. So, a file namedexample.xmlwith content that looks liketext/plain, and a specified resource format of "XML", would be accepted. The format of each entry is"parent-type": ["sub-type1", "sub-type2"]. Wildcards are partially supported; an override can be a single asterisk to allow any other type to be a subtype (typically used forapplication/octet-stream), or it can have the formprefix/*to allow any type with that prefix to be a subtype (egtext/*can overridetext/plain). -
equal_types: A list of lists of types that are interchangeable, egtext/xmlis the same asapplication/xml. This can be used in a similar manner toallowed_overrides, but is bidirectional, and will affect the resulting displayed format. Overrides will attempt to use the most specific subtype, whereas equal types take whichever is encountered first. For example, a file namedexample.rdfand containing XML data, withapplication/rdf+xmlas an override forapplication/xml, would have a resource mimetype ofapplication/rdf+xml, but ifapplication/xmlandapplication/rdf+xmlare configured as equal types, then the resource mimetype might be simplyapplication/xml. -
archive_types: A list of types that are archives and require special handling, egapplication/zip. Archives can specify any resource format (since the format might refer to the archive contents), so long as the archive is well-formed (file extension and contents match). -
generic_types: A list of types that are 'generic' ie supertype to many others (egtext/plainandapplication/octet-stream). File contents of these types can be overridden with a subtype, but if the file extension or format matches them, then that cannot be overridden. Eg a file withtext/plaincontent could specify a CSV extension and format, but a file with.txtextension could not specify a "CSV" format. Similarly, a resource with "TXT" format could not have a.xmlextension. This is intended to prevent browser-based content-sniffing attacks, where a file with an innocuous extension like.txtmay be handled in a different way by the browser based on the apparent type of its contents. -
extra_mimetypes: A dictionary of additional mappings to add to the Pythonmimetypeslibrary for guessing types based on file extensions. The format of each entry is".extension": "mime-type". For example, a site that expects to upload Quartus Tabular Text Files might define the.ttfextension to havetext/plainMIME type:"extra_mimetypes": { ".ttf": "text/plain" }
Testing
To run the tests:
-
Activate your CKAN virtual environment, eg
. /usr/lib/ckan/default/bin/activate -
Switch to the extension directory, eg
cd /usr/lib/ckan/default/src/ckanext-resource-type-validation -
Install test requirements:
pip install -r dev-requirements.txt -
Run the tests. This can be done in multiple ways.
-
Execute the test class directly:
python ckanext/resource_type_validation/test_mime_type_validation.py -
Run
pytest
-
Alternative testing with Docker
The Docker-based test environment currently relies on *nix shell scripts.
-
Install Docker Compose and Ahoy.
-
Build the test containers:
CKAN_VERSION=<version eg 2.11> bin/build.sh -
Run unit tests:
ahoy test-unit -
Set up test data:
ahoy install-site -
Run scenario tests:
ahoy test-bdd
Metadata
Release files for ckanext-resource-type-validation 1.0.15
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| ckanext_resource_type_validation-1.0.15.tar.gz | 32.1 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ckanext_resource_type_validation-1.0.15-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 62.6 kB
Release files / ckanext_resource_type_validation-1.0.15.tar.gz
| Download URL | ckanext_resource_type_validation-1.0.15.tar.gz |
|---|---|
| Size | 32.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3508fa8dc7d80219ab5ff4b16cacfc3e80d381ca61babfdb80e3ba16db402196
|
|
BLAKE2b-256 checksum How to use checksums |
c52ef72cd8a13a08eafe9f14b784fd16e359d736ba5eeb093ff45c876435a44a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.
Transparency logRelease files / ckanext_resource_type_validation-1.0.15-py3-none-any.whl
| Download URL | ckanext_resource_type_validation-1.0.15-py3-none-any.whl |
|---|---|
| Size | 30.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e4d5748a77ea008d9bca84c1bcbfdac409ef7426b625b776ec340efba1319634
|
|
BLAKE2b-256 checksum How to use checksums |
96b03d98bfd59aa35faa9d61066c6597ea379f263838cb694921429b3810532a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.
Transparency logSecurity for ckanext-resource-type-validation 1.0.15
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for ckanext_resource_type_validation-1.0.15.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.