Skip to main content

Parse and validate a safe subset of CSS

Project description

Build Status

cssfilter.py extracted from reddit’s source code.

This library allows you to filter “unsafe” css from your users.

This library requires attribution!:

When using this library, reddit requires you to put the following information in the splash or the “about” section of your application.

EXHIBIT B. Attribution Information

Attribution Copyright Notice: Copyright (c) 2006-2015 reddit Inc. All Rights Reserved.

Attribution Phrase (not exceeding 10 words): Powered by reddit

Attribution URL: http://code.reddit.com

Graphic Image as provided in the Covered Code: http://code.reddit.com/reddit_logo.png

Info

Parse and validate a safe subset of CSS.

The goal of this validation is not to ensure functionally correct stylesheets but rather that the stylesheet is safe to show to downstream users. This includes:

  • not generating requests to third party hosts (information leak)

  • xss via strange syntax in buggy browsers

Beyond that, every effort is made to allow the full gamut of modern CSS.

How to use

import reddit_cssfilter.cssfilter
cssfilter.validate_css(stylesheet, images)

Validate and re-serialize the user submitted stylesheet.

images is a mapping of subreddit image names to their URLs. The re-serialized stylesheet will have %%name%% tokens replaced with their appropriate URLs.

The return value is a two-tuple of the re-serialized (and minified) stylesheet and a list of errors. If the list is empty, the stylesheet is valid.

Licence

Copyright (c) 2006-2015 reddit Inc. All Rights Reserved.

Common Public Attribution License Version 1.0 (CPAL)

The full license is available here: reddit Inc. Common Public Attribution License Version 1.0 (CPAL).

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

reddit-cssfilter-1.2.tar.gz (7.7 kB view details)

Uploaded Source

File details

Details for the file reddit-cssfilter-1.2.tar.gz.

File metadata

File hashes

Hashes for reddit-cssfilter-1.2.tar.gz
Algorithm Hash digest
SHA256 d058ad2597d10dc482eda2445ab5c70a6b0cd9c3a96df487035ba5db23f860ec
MD5 a6d2838d5d286677070b45e94ea4dd64
BLAKE2b-256 40ebc651584fb3d335f14c757bdaed7830202b58ff3af385c2785ea9cc236f56

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