Git Product home page Git Product logo

safevalues's Introduction

safevalues

Safevalues is a library to help you prevent Cross-Site Scripting vulnerabilities in TypeScript (and JavaScript). It is meant to be used together with tsec to provide strong security guarantees and help you deploy Trusted Types and other CSP restrictions in your applications. Google has used these components together to reduce DOM XSS (paper), and we hope it will be useful in your codebase.

Features

Policy definition for building safe-by-construction Trusted Types

Trusted Types is a browser API that enables developers to control the values that can be assigned to XSS sinks. Developers need to define a Trusted Type policy to build these values, and then the Trusted Type API constrains these policies.

The Trusted Types API is not opinionated on what should be considered safe. It only acts as a tool for developers to mark values they can trust.

safevalues in contrast, defines functions that make security decisions on what is safe (by construction, via escaping or sanitization), so that developers who are not security experts don't need to.

safevalues produces Trusted Types (through its own policy) when available.

Additional types and functions for sinks not covered by Trusted Types

Some DOM APIs are not covered by Trusted Types, but can also be abused; leading to XSS or other security issues. Alternative security mechanisms such as the unsafe-inline CSP protection can help to secure these APIs, but not all browsers or apps support them.

safevalues defines additional types, builders, and setters to help protect these sinks.

DOM sink wrappers

To build a Trusted Type-compatible app and surface potential violations at compile time, we recommend that you compile your code with tsec. tsec bans certain DOM APIs. safevalues defines wrappers around these APIs which lets you assign Trusted Types with them.

Some wrappers don't require a particular type, but sanitize the argument they get before they assign it to the DOM sink (e.g. safeLocation.setHref).

Trusted Type polyfills

Whenever possible, safevalues uses Trusted Types to build its values, in order to benefit from the runtime protection of Trusted Types. When Trusted Types is not available, safevalues transparently defines its own types and your app will continue to work.

Known issues

ReferenceError: Can't find variable: process

When using a bundler that performs dead-code elimination, you must ensure that process.env.NODE_ENV is declared globally with either a value of development or production. This is done in Webpack by specifying a mode, in Terser using the --define flag and in Rollup using the rollup-plugin-define plugin. See (#212).


Read on about for more information on our APIs.

Disclaimer

This is not an officially supported Google product.

safevalues's People

Contributors

12wrigja avatar bjarkler avatar ddworken avatar engelsdamien avatar frigus02 avatar koto avatar neuracr avatar nreid260 avatar schcamille avatar securitymb avatar shicks avatar uraj avatar vrana avatar zemnmez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

safevalues's Issues

allowPartAttributes?

In the context of Web Components, part attributes are used to apply styles to the items under an open shadow DOM.
Having an option to allow part attributes for the Sanitizer Builder API would be helpful to make the sanitizer work with custom elements.
I thought the carried risk would be similar to allowClassAttributes, but I would love to hear your thoughts.

Safari support

Safari (version 16) does not support TrustedTypes and safevalues thus falls back to its own implementation (HtmlImpl).
But HtmlImpl is only working in nodejs environments as it checks for an environment variable via process.env (see html_impl.ts:20)
When using safevalues in Safari, this only leads to the error message 'ReferenceError: Can't find variable: process'.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.