goog.labs.html.sanitizer.js Maven / Gradle / Ivy
// Copyright 2014 The Closure Library Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
* @fileoverview
* An HTML sanitizer that takes untrusted HTML snippets and produces
* safe HTML by filtering/rewriting tags and attributes that contain
* high-privilege instructions.
*/
goog.provide('goog.labs.html.Sanitizer');
goog.require('goog.asserts');
goog.require('goog.html.SafeUrl');
goog.require('goog.labs.html.attributeRewriterPresubmitWorkaround');
goog.require('goog.labs.html.scrubber');
goog.require('goog.object');
goog.require('goog.string');
/**
* A sanitizer that converts untrusted, messy HTML into more regular HTML
* that cannot abuse high-authority constructs like the ability to execute
* arbitrary JavaScript.
* @constructor
*/
goog.labs.html.Sanitizer = function() {
/**
* Maps the lower-case names of allowed elements to attribute white-lists.
* An attribute white-list maps lower-case attribute names to functions
* from values to values or undefined to disallow.
*
* The special element name {@code "*"} contains a white-list of attributes
* allowed on any tag, which is useful for attributes like {@code title} and
* {@code id} which are widely available with element-agnostic meanings.
* It should not be used for attributes like {@code type} whose meaning
* differs based on the element on which it appears:
* e.g. {@code } vs {@code