Skip to main content

A small library that adds optional security headers and cookie presets for Responder

Project description

Secure

Secure 🔒 is a small library that adds optional security headers and cookie presets for Responder.

Install

pipenv install secure

Headers

Strict-Transport-Security (HSTS)

Ensure application is loaded over HTTPS
Value: max-age=63072000; includeSubdomains

X-Frame-Options

Disable iframes (Clickjacking protection)
Value: DENY

X-XSS-Protection

Enable Cross-Site Scripting filters
Value: X-XSS-Protection", "1; mode=block

X-Content-Type-Options

Prevent MIME-sniffing
Value: nosniff

Content-Security-Policy (CSP)

Prevent Cross-site injections
Value: script-src 'self'; object-src 'self'

Recommendations used by Secure 🔒 and more information regarding security headers can be found at the OWASP Secure Headers Project.

Cookies

Path

The Path directive instructs the browser to only send the cookie if provided path exists in the URL.

Secure

The Secure flag instructs the browser to only the cookie via HTTPS.

HttpOnly

The HttpOnly flag instructs the browser to not allow any client side code to access the cookie's contents.

SameSite

The SameSite flag directs the browser not to include cookies on certain cross-site requests. There are two values that can be set for the same-site attribute, lax or strict. The lax value allows the cookie to be sent via certain cross-site GET requests, but disallows the cookie on all POST requests. For example cookies are still sent on links <a href=“x”>, prerendering <link rel=“prerender” href=“x” and forms sent by GET requests <form-method=“get”..., but cookies will not be sent via POST requests <form-method=“post”..., images <img src=“x”> or iframes <iframe src=“x”>. The strict value prevents the cookie from being sent cross-site in any context. Strict offers greater security but may impede functionality. This approach makes authenticated CSRF attacks impossible with the strict flag and only possible via state changing GET requests with the lax flag.

Responder Headers

Usage

import responder
import secure

api = responder.API()

... 

@api.route(before_request=True)
def prepare_response(req, resp):
    secure.responder_headers(req, resp)

HTTP response headers:

x-frame-options: DENY
x-xss-protection: 1; mode=block
x-content-type-options: nosniff

Options (not required)

Example: secure.responder_headers(req, resp, csp=True)

  • hsts (default=False) *
  • frame (default=True)
  • xss (default=True)
  • content (default=True)
  • csp (default=False) *

You should use Responder's built in HSTS option and the CSP headers should be carefully constructed, however you can use the defaults by including the hsts=True and/or csp=True options.

Responder Cookies

Usage

import responder
import secure

api = responder.API()

... 

@api.route("/secure")
async def greet_world(req, resp):
    resp.text = "Secure"
    secure.responder_cookies(
        req, resp, name="responder-cookie", value="ABC123", secure=False
    )

Set-Cookie HTTP response header:

set-cookie: responder-cookie=ABC123; Path=/; Secure; HttpOnly; SameSite=Lax;

Options (not required)

Example:

secure.responder_cookies(req,resp, name="responder-cookie", value="ABC123", secure=False)

  • path (default="/")
  • secure (default=True)
  • httponly (default=True)
  • samesite Options: lax or strict (default="lax")

Attribution/References

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

secure-0.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

secure-0.1.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file secure-0.1.0.tar.gz.

File metadata

  • Download URL: secure-0.1.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for secure-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ad29d50a9eabd6b9dae7bfe7f4409adfe13244cd56ee079586b0c9ae0538f51c
MD5 21c238d052f9b336d7940467f8a8a932
BLAKE2b-256 aa43445404da1e62f5c3ab1f8767fb9f8f7d6dbcf2862d1bd176635e51b174a2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: secure-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for secure-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8983b68f607cb35c58b642cd77ab52a275770e0a4a21a1ab300702e5a8ff38e4
MD5 bef19ac3c8c5d4e087226dd27942b7fa
BLAKE2b-256 fddfa94e8f1e8f2b2f287d7fbee704cc6e57937be74373c8b4a9a2d0d4ee24f2

See more details on using hashes here.

Supported by

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