diff options
| author | Chirayu Krishnappa | 2013-10-17 19:44:36 -0700 |
|---|---|---|
| committer | Chirayu Krishnappa | 2013-10-30 17:01:51 -0700 |
| commit | 3d6a89e8888b14ae5cb5640464e12b7811853c7e (patch) | |
| tree | 9fd167fd0bd210569b507a80d91f0787b9278b84 /docs/content/error | |
| parent | 5b620653f61ae3d9f1de8346de271752fa12f26f (diff) | |
| download | angular.js-3d6a89e8888b14ae5cb5640464e12b7811853c7e.tar.bz2 | |
feat($parse): secure expressions by hiding "private" properties
BREAKING CHANGE:
This commit introduces the notion of "private" properties (properties
whose names begin and/or end with an underscore) on the scope chain.
These properties will not be available to Angular expressions (i.e. {{
}} interpolation in templates and strings passed to `$parse`) They are
freely available to JavaScript code (as before).
Motivation
----------
Angular expressions execute in a limited context. They do not have
direct access to the global scope, Window, Document or the Function
constructor. However, they have direct access to names/properties on
the scope chain. It has been a long standing best practice to keep
sensitive APIs outside of the scope chain (in a closure or your
controller.) That's easier said that done for two reasons: (1)
JavaScript does not have a notion of private properties so if you need
someone on the scope chain for JavaScript use, you also expose it to
Angular expressions, and (2) the new "controller as" syntax that's now
in increased usage exposes the entire controller on the scope chain
greatly increaing the exposed surface. Though Angular expressions are
written and controlled by the developer, they (1) typically deal with
user input and (2) don't get the kind of test coverage that JavaScript
code would. This commit provides a way, via a naming convention, to
allow publishing/restricting properties from controllers/scopes to
Angular expressions enabling one to only expose those properties that
are actually needed by the expressions.
Diffstat (limited to 'docs/content/error')
| -rw-r--r-- | docs/content/error/parse/isecprv.ngdoc | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/docs/content/error/parse/isecprv.ngdoc b/docs/content/error/parse/isecprv.ngdoc new file mode 100644 index 00000000..4bb02426 --- /dev/null +++ b/docs/content/error/parse/isecprv.ngdoc @@ -0,0 +1,50 @@ +@ngdoc error +@name $parse:isecprv +@fullName Referencing private Field in Expression + +@description + +Occurs when an Angular expression attempts to access a private field. + +Fields with names that begin or end with an underscore are considered +private fields. Angular expressions are not allowed to reference such +fields on the scope chain. This only applies to Angular expressions +(e.g. {{ }} interpolation and calls to `$parse` with a string expression +argument) – Javascript itself has no such notion. + +To resolve this error, use an alternate non-private field if available +or make the field public (by removing any leading and trailing +underscore characters from its name.) + +Example expression that would result in this error: + +```html +<div>{{user._private_field}}</div> +``` + +Background: +Though Angular expressions are written and controlled by the developer +and are trusted, they do represent an attack surface due to the +following two factors: + +- they typically deal with user input which is generally high risk +- they often don't get the kind of attention and test coverage that + JavaScript code would. + +If these expression were evaluated in a context with full trust, an +attacker, though unable to change the expression itself, can feed it +unexpected and dangerous input that could result in a security +breach/exploit. + +As such, Angular expressions are evaluated in a limited context. They +do not have direct access to the global scope, Window, Document, the +Function constructor or "private" properties (names beginning or ending +with an underscore character) on the scope chain. They should get their +work done via public properties and methods exposed on the scope chain +(keep in mind that this includes controllers as well as they are +published on the scope via the "controller as" syntax.) + +As a best practise, only "publish" properties on the scopes and +controllers that must be available to Angular expressions. All other +members should either be in closures or be "private" by giving them +names with a leading or trailing underscore character. |
