This repository has been archived by the owner on Jan 22, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
*** Reason for rollback *** Moved SanitizedContent itself (but not its subclasses) to Closure too so that typechecking works. *** Original change description *** Automated g4 rollback *** Reason for rollback *** Broke Closure. *** Original change description *** goog.soy to check that templates are either returning string or SanitizedHtml and not other types. Add an @define for projects to force Strict mode. Move soydata.SanitizedContentKind definitions into Closure's Soy directory goog.soy can depend on it. Have soydata.SanitizedContentKind ... description truncated by g4 rollback ... R=kai DELTA=687 (482 added, 140 deleted, 65 changed) Revision created by MOE tool push_codebase. MOE_MIGRATION=5780 git-svn-id: http://closure-library.googlecode.com/svn/trunk@2280 0b95b8e8-c90f-11de-9d4f-f947ee5921c8
- Loading branch information
gboyer@google.com
committed
Nov 8, 2012
1 parent
33354d3
commit f49c45e
Showing
5 changed files
with
305 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,118 @@ | |||
// Copyright 2012 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 Soy data primitives. | |||
* | |||
* The goal is to encompass data types used by Soy, especially to mark content | |||
* as known to be "safe". | |||
* | |||
* @author gboyer@google.com (Garrett Boyer) | |||
*/ | |||
|
|||
goog.provide('goog.soy.data'); | |||
goog.provide('goog.soy.data.SanitizedContent'); | |||
goog.provide('goog.soy.data.SanitizedContentKind'); | |||
|
|||
|
|||
/** | |||
* A type of textual content. | |||
* | |||
* This is an enum of type Object so that these values are unforgeable. | |||
* | |||
* @enum {!Object} | |||
*/ | |||
goog.soy.data.SanitizedContentKind = { | |||
|
|||
/** | |||
* A snippet of HTML that does not start or end inside a tag, comment, entity, | |||
* or DOCTYPE; and that does not contain any executable code | |||
* (JS, {@code <object>}s, etc.) from a different trust domain. | |||
*/ | |||
HTML: goog.DEBUG ? {sanitizedContentKindHtml: true} : {}, | |||
|
|||
/** | |||
* A sequence of code units that can appear between quotes (either kind) in a | |||
* JS program without causing a parse error, and without causing any side | |||
* effects. | |||
* <p> | |||
* The content should not contain unescaped quotes, newlines, or anything else | |||
* that would cause parsing to fail or to cause a JS parser to finish the | |||
* string its parsing inside the content. | |||
* <p> | |||
* The content must also not end inside an escape sequence ; no partial octal | |||
* escape sequences or odd number of '{@code \}'s at the end. | |||
*/ | |||
JS_STR_CHARS: goog.DEBUG ? {sanitizedContentJsStrChars: true} : {}, | |||
|
|||
/** A properly encoded portion of a URI. */ | |||
URI: goog.DEBUG ? {sanitizedContentUri: true} : {}, | |||
|
|||
/** An attribute name and value such as {@code dir="ltr"}. */ | |||
HTML_ATTRIBUTE: goog.DEBUG ? {sanitizedContentHtmlAttribute: true} : {}, | |||
|
|||
// TODO: Consider separating rules, declarations, and values into | |||
// separate types, but for simplicity, we'll treat explicitly blessed | |||
// SanitizedContent as allowed in all of these contexts. | |||
/** | |||
* A CSS3 declaration, property, value or group of semicolon separated | |||
* declarations. | |||
*/ | |||
CSS: goog.DEBUG ? {sanitizedContentCss: true} : {}, | |||
|
|||
/** | |||
* Unsanitized plain-text content. | |||
* | |||
* This is effectively the "null" entry of this enum, and is sometimes used | |||
* to explicitly mark content that should never be used unescaped. Since any | |||
* string is safe to use as text, being of ContentKind.TEXT makes no | |||
* guarantees about its safety in any other context such as HTML. | |||
*/ | |||
TEXT: goog.DEBUG ? {sanitizedContentKindText: true} : {} | |||
}; | |||
|
|||
|
|||
|
|||
/** | |||
* A string-like object that carries a content-type. | |||
* | |||
* IMPORTANT! Do not create these directly, nor instantiate the subclasses. | |||
* Instead, use a trusted, centrally reviewed library as endorsed by your team | |||
* to generate these objects. Otherwise, you risk accidentally creating | |||
* SanitizedContent that is attacker-controlled and gets evaluated unescaped in | |||
* templates. | |||
* | |||
* @param {string} content The assumed-sanitized string. Be careful! | |||
* @constructor | |||
*/ | |||
goog.soy.data.SanitizedContent = function(content) { | |||
/** | |||
* The textual content. | |||
* @type {string} | |||
*/ | |||
this.content = content; | |||
}; | |||
|
|||
|
|||
/** | |||
* The context in which this content is safe from XSS attacks. | |||
* @type {goog.soy.data.SanitizedContentKind} | |||
*/ | |||
goog.soy.data.SanitizedContent.prototype.contentKind; | |||
|
|||
|
|||
/** @override */ | |||
goog.soy.data.SanitizedContent.prototype.toString = function() { | |||
return this.content; | |||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.