Migrating to 1.0
After more than 12 years since it’s initial inception, django-cookie-consent finally has a 1.0 version number. It means that the public API is stable, and breaking changes will be reflected in a new major version number.
Some breaking changes compared to version 0.9 and earlier may affect you. This document helps you upgrade from the earlier versions to 1.0.
Accept/decline views now use form data and only support POST requests
Before 1.0, the accept and decline URLs would (optionally) take a comma-separated URL path variable for the cookie group varnames:
.../accept/social,analytics/.../decline/social,analytics/
while the URLs without the varnames would imply that all cookie groups are being accepted or declined.
Instead of using {% url 'cookie_consent_accept' varname='social,analytics' %}, in 1.0, use proper form semantics instead:
<form action="{% url 'cookie_consent_accept' %}" method="post">
{% csrf_token %}
<input type="hidden" name="cookie_groups" value="social">
<input type="hidden" name="cookie_groups" value="analytics">
<button type="submit">Accept</button>
</form>
or, to accept/decline all cookie groups, instead of
{% url 'cookie_consent_accept_all' %}:
<form action="{% url 'cookie_consent_accept' %}" method="post">
{% csrf_token %}
<input type="hidden" name="all_groups" value="true">
<button type="submit">Accept all</button>
</form>
Warning
The accept/decline views now require a CSRF token to be provided. The new cookiebar module already handles this.
Warning
The DELETE support to decline cookies is removed. Use POST instead.
Enable safety/strictness features
The legacy situation may have prevented you from applying some security hardening or improvements in your project(s). Below, we point out some things that are possible now.
Enable the httpOnly flag for cookie consent’s own cookie
Since the legacy Javascript that was writing directly to document.cookie is removed,
you can block access to this cookie from Javascript entirely now.
The default settings already enable this.
Use a strict(er) Content-Security-Policy
The legacy cookiebar required unsave-eval, which is a serious weakening of
cross-site scripting protections. If you were using it because of django-cookie-consent,
you can now remove it after upgrading to the new cookiebar module.
Site/view cache can be enabled
By relying on template nodes, Javascript and JSON-based endpoints for the dynamic
per-user information, your main views/page templates can now be safely cached using
Django’s cache framework without serving cookie consent information from the wrong
user.
The future
Future major versions will primarily be caused by dropping support for old Python and/or Django version, notably when those go end-of-life. The Python/Django backwards compatibility has an excellent track record, so we don’t expect big impacts from this.
One larger rework that is planned, is the overhaul of the cookie accept/decline logging. This will likely be another major release, but we expect a smooth upgrade path.