inject-stylesheet

WebJar for inject-stylesheet

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

inject-stylesheet
Last Version

Last Version

2.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

inject-stylesheet
WebJar for inject-stylesheet
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/braintree/inject-stylesheet

Download inject-stylesheet

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/inject-stylesheet/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>inject-stylesheet</artifactId>
    <version>2.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/inject-stylesheet/
implementation 'org.webjars.npm:inject-stylesheet:2.0.0'
// https://jarcasting.com/artifacts/org.webjars.npm/inject-stylesheet/
implementation ("org.webjars.npm:inject-stylesheet:2.0.0")
'org.webjars.npm:inject-stylesheet:jar:2.0.0'
<dependency org="org.webjars.npm" name="inject-stylesheet" rev="2.0.0">
  <artifact name="inject-stylesheet" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='inject-stylesheet', version='2.0.0')
)
libraryDependencies += "org.webjars.npm" % "inject-stylesheet" % "2.0.0"
[org.webjars.npm/inject-stylesheet "2.0.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

inject-stylesheet

This library takes a blocklist (or allowlist) of CSS properties and sanitizes for known CSS exploits.

API

Where mentioned, styles is an object with its keys being CSS selectors and values being CSS property key-value pairs.

var stylesheet = injectStylesheet.injectWithBlocklist(styles [, blocklist]);
var stylesheet = injectStylesheet.injectWithAllowlist(styles [, allowlist]);

After usage, stylesheet will refer to the <style> tag that was injected into the <head> of the document.

var injectStylesheet = require("inject-stylesheet");
var styles = {
  input: {
    "font-size": "16pt",
    color: "#3A3A3A",
  },
  ".invalid": {
    color: "tomato",
  },
  "@media screen and (max-width: 700px)": {
    input: {
      "font-size": "14pt",
    },
  },
};
var allowlist = ["font-size", "color"];
var blocklist = ["background", "display"];

injectStylesheet.injectWithBlocklist(styles, blocklist);
injectStylesheet.injectWithAllowlist(styles, allowlist);

Sanitization

Selectors

Selectors are filtered for things such as {}, @import, etc.

Keys

Keys are filtered based on whether or not a blocklist or allowlist was given. injectStylesheet will assume that its second parameter is a blocklist unless the third parameter is true, which will designate it as a allowlist. This listing is used to filter the given CSS properties for exclusion or inclusion.

Values

Values are checked against usages of url(), evaluate(), and other potentially abused and powerful CSS functions.

Browser Support

All modern browsers, and IE9+

org.webjars.npm

Braintree

Versions

Version
2.0.0
1.0.0