Skip to main content

A package that uses the HTTP referer header to provide credentials.

Detailed Documentation

HTTP-Referer Credentials

It is sometimes necessary to restrict access to a site by looking at the the site the user is coming from. For example, a user can only enter the site when he comes from within the corporate network. If the two sites cannot share any specific information, such as an authentication token, the only useful piece of information is the HTTP-Referer request header.

__Note__: Yes I know this is not fully secure and someone could spoof the header. But this is acceptable in this particular application. I guess it keeps away the honest. And yes, this is a real world scenario – would I implement this package otherwise? :-)

So let’s have a look at the credentials plugin:

>>> from z3c.referercredentials import credentials
>>> creds = credentials.HTTPRefererCredentials()

Let’s look at the positive case first. The referer credentials plugin has an attribute that specifies all allowed hosts:

>>> creds.allowedHosts
('localhost',)

In this example, we only want to allow peopl eto the site coming from www.zope.org.

>>> creds.allowedHosts = ('www.zope.org',)

Now, a user coming from that site will have a request containing this referer:

>>> from zope.publisher.browser import TestRequest
>>> request = TestRequest(HTTP_REFERER='http://www.zope.org/index.html')

The credentials can now be extracted as follows:

>>> creds.extractCredentials(request)

Nothing is returned. This is because we have not defined any credentials that represent the “referer user”. With setting the credentials, it should work:

>>> creds.credentials = {'login': 'mgr', 'password': 'mgrpw'}
>>> creds.extractCredentials(request)
{'login': 'mgr', 'password': 'mgrpw'}

Once an acceptable referer has been passed in, the credentials are always returned:

>>> del request._environ['HTTP_REFERER']
>>> creds.extractCredentials(request)
{'login': 'mgr', 'password': 'mgrpw'}

We have to log out in order to loose the credentials:

>>> creds.logout(request)
True

Now, no credentials are returned when not sending in a correct referer:

>>> creds.extractCredentials(request)

When the user could not be authenticated, the plugin is asked to pose a challenge:

>>> creds.challenge(request)
True
>>> request.response.getHeader('Redirect')

By default we are getting the “unauthorized.html” view on the site. But you can change the view name:

>>> creds.challengeView = 'challenge.html'
>>> creds.challenge(request)
True
>>> request.response.getHeader('Redirect')

Final Note: Of course, this credentials plugin only works with HTTP-based requests:

>>> request = object()
>>> creds.extractCredentials(request)
>>> creds.challenge(request)
False
>>> creds.logout(request)
False

CHANGES

Version 0.1.0 (6/??/2007)

  • Initial Release

    • Implementation of HTTP-Referer credentials plugin

Release files for z3c.referercredentials 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for z3c.referercredentials 0.1.0
File Size Uploaded
z3c.referercredentials-0.1.0.tar.gz 7.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for z3c.referercredentials 0.1.0
File Interpreter ABI Platform
z3c.referercredentials-0.1.0-py2.4.egg Legacy Egg format - - Details

Total release size: 19.3 kB

Release files / z3c.referercredentials-0.1.0.tar.gz

Download URL z3c.referercredentials-0.1.0.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f92a9708c1947abcf2f67538a7ab23a64483530b2df8317315b3b61e2f2a4267
BLAKE2b-256 checksum
How to use checksums
3637fc3e10731b274a54c7836e887c48d0b6b66aa89e797272e21b036140aa66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / z3c.referercredentials-0.1.0-py2.4.egg

Download URL z3c.referercredentials-0.1.0-py2.4.egg
Size 11.6 kB
Tags Egg
SHA-256 checksum
How to use checksums
64ff1c24e1ff3bb5232a42b6a3da2c38055020c59e005627d879a391cb39c87c
BLAKE2b-256 checksum
How to use checksums
3ce6de22fe1971625d8ccdc79902432c9b40dead98d2bd3c8a754523ea193aa0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page