File: conformance_proto.txt

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (420 lines) | stat: -rw-r--r-- 18,333 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
# proto-file: third_party/java_src/jscomp/java/com/google/javascript/jscomp/conformance.proto
# proto-message: ConformanceConfig

# Conformance users:
#
# DO NOT COPY PASTE THESE RULES. If you do, changes to Closure can break your
# build and you also won't get new or improved rules. Instead use this file in
# your project and extend the rules to disable them or to add their allowlists.

### Platform restrictions ###

requirement: {
  rule_id: "closure:callee"
  type: BANNED_PROPERTY
  error_message: "Arguments.prototype.callee is not allowed. See https://google.github.io/closure-library/develop/conformance_rules.html#callee"

  value: "Arguments.prototype.callee"

  allowlist_regexp: ".+/closure/goog/debug/"  # legacy stack trace support, etc
  # TODO(mlourenco): Fix this? Not sure if possible or not.
  allowlist_regexp: ".+/closure/goog/testing/stacktrace.js"
}

requirement: {
  rule_id: "closure:throwOfNonErrorTypes"
  type: CUSTOM
  java_class: "com.google.javascript.jscomp.ConformanceRules$BanThrowOfNonErrorTypes"
  error_message: "Only Error or Error subclass objects may be thrown. See https://google.github.io/closure-library/develop/conformance_rules.html#throwOfNonErrorTypes"
  # TODO(user): Violation occurs in code generated by Emscripten.
  allowlist_regexp: ".+_wasm_js_library_generated.js"
  allowlist_regexp: ".+/closure/goog/storage/"  # throws numbers as part of its api
  allowlist_regexp: ".+/closure/goog/testing/mock.js"  # throws Object in $recordAndThrow
}

requirement: {
  rule_id: "closure:globalVars"
  type: CUSTOM
  java_class: "com.google.javascript.jscomp.ConformanceRules$BanGlobalVars"
  error_message: "Global declarations are not allowed. See https://google.github.io/closure-library/develop/conformance_rules.html#globalVars"
  allowlist_regexp: ".+/closure/goog/base.js"  # global 'goog'
  allowlist_regexp: ".+/closure/goog/labs/testing/"  # global matchers, etc
  allowlist_regexp: ".+/closure/goog/locale/locale.js"  # dumb api
  allowlist_regexp: ".+/closure/goog/testing/"  # global assert methods, etc
  allowlist_regexp: ".+/closure/goog/tweak/testhelpers.js"  # global values
  allowlist_regexp: "^Post-"  # injected '_ModuleManager_initialize'

  # Allowlist for global names
  value: "CLOSURE_DEFINES"  # Closure Compiler requires this to be a global var
  value: "CLOSURE_UNCOMPILED_DEFINES"  # Closure Compiler requires this to be a global var
  value: "CLOSURE_NO_DEPS"  # Closure Compiler requires this to be a global var
}

requirement: {
  rule_id: "closure:unknownThis"
  type: CUSTOM
  java_class: "com.google.javascript.jscomp.ConformanceRules$BanUnknownThis"
  error_message: "References to \"this\" that are typed as \"unknown\" are not allowed. See https://google.github.io/closure-library/develop/conformance_rules.html#unknownThis"

  allowlist_regexp: ".+/closure/goog/base.js"
  allowlist_regexp: ".+/closure/goog/debug/errorhandler.js"
  allowlist_regexp: ".+/closure/goog/editor/plugins/linkbubble.js"
  allowlist_regexp: ".+/closure/goog/editor/plugins/linkdialogplugin.js"
  allowlist_regexp: ".+/closure/goog/functions/functions.js"
  allowlist_regexp: ".+/closure/goog/memoize/memoize.js"
  allowlist_regexp: ".+/closure/goog/pubsub/pubsub.js"
  allowlist_regexp: ".+/closure/goog/testing/"
  allowlist_regexp: ".+/closure/goog/ui/editor/bubble.js"
  allowlist_regexp: ".+/closure/goog/ui/editor/toolbarcontroller.js"
  # TODO(user): Violation occurs in code generated by Emscripten.
  allowlist_regexp: ".+_wasm_js_library_generated.js"
}

### Browser tech requirements ###

# This requirement is somewhat Google-specific: open-source Closure users that
# don't use GAPI could reasonably ignore it depending on how they do messaging
# in their app.
requirement: {
  rule_id: "closure:postMessage"
  type: BANNED_PROPERTY_CALL
  error_message: "Window.prototype.postMessage is not allowed. See https://google.github.io/closure-library/develop/conformance_rules.html#postMessage"

  value: "Window.prototype.postMessage"

  # Known-safe common infrastructure.
  allowlist_regexp: ".+/closure/goog/async/nexttick.js"
  allowlist_regexp: ".+/closure/goog/net/xpc/nativemessagingtransport.js"
  # TODO(user): make sure this gets security reviewed (b/29333525).
  allowlist_regexp: ".+/closure/goog/messaging/portchannel.js"
}

### Security: forbid DOM properties and functions which can cause XSS ###

# These are properties and functions which might have safe wrappers under
# goog.dom.safe. Two groups: properties and functions which accept
# HTML/CSS/script-as-string, properties and function which accept URLs.

#### DOM properties and functions which accept HTML/CSS/script-as-string #####

requirement: {
  rule_id: 'closure:eval'
  # TODO(jakubvrana): Change to BANNED_NAME_CALL after cl/154708486 lands.
  type: BANNED_NAME
  error_message: 'eval is not allowed. See https://google.github.io/closure-library/develop/conformance_rules.html#eval'

  value: 'eval'
  value: 'execScript'
  value: 'goog.globalEval'

  allowlist_regexp: '.+/closure/goog/base.js' # goog.module loading in uncompiled code.
  allowlist_regexp: '.+/closure/goog/goog.js' # Forwards goog.globalEval
  allowlist_regexp: '.+/closure/goog/debug/errorhandler.js' # wraps setTimeout and similar functions
  allowlist_regexp: '.+/closure/goog/json/json.js' # used in goog.json.parse
  allowlist_regexp: '.+/closure/goog/module/loader.js'
  allowlist_regexp: '.+/closure/goog/module/moduleloader.js'
}

requirement: {
  rule_id: 'closure:windowEval'
  type: BANNED_PROPERTY_CALL
  error_message: 'window.eval is not allowed. See https://google.github.io/closure-library/develop/conformance_rules.html#eval'

  value: 'Window.prototype.eval'
  value: 'Window.prototype.execScript'

  allowlist_regexp: '.+/closure/goog/base.js'
  # TODO(jakubvrana): To be investigated.
  allowlist_regexp: '.+/closure/goog/net/xpc/nixtransport.js'
}

requirement: {
  rule_id: 'closure:stringFunctionDefinition'
  type: RESTRICTED_NAME_CALL
  error_message: 'Function, setTimeout, setInterval and requestAnimationFrame are not allowed with string argument. See https://google.github.io/closure-library/develop/conformance_rules.html#eval'

  value: 'Function:function()'
  value: 'setTimeout:function(Function, ...?)'
  value: 'setInterval:function(Function, ...?)'
  value: 'requestAnimationFrame:function(Function, ...?)'
}

requirement: {
  rule_id: 'closure:windowStringFunctionDefinition'
  type: RESTRICTED_METHOD_CALL
  error_message: 'window.setTimeout, setInterval and requestAnimationFrame are not allowed with string argument. See https://google.github.io/closure-library/develop/conformance_rules.html#eval'

  value: 'Window.prototype.setTimeout:function(Function, ...?)'
  value: 'Window.prototype.setInterval:function(Function, ...?)'
  value: 'Window.prototype.requestAnimationFrame:function(Function, ...?)'
}

requirement: {
  rule_id: 'closure:innerHtml'
  type: BANNED_PROPERTY_NON_CONSTANT_WRITE
  error_message: 'Assignment to Element.prototype.innerHTML is not allowed. See https://google.github.io/closure-library/develop/conformance_rules.html#innerHtml'

  value: 'Element.prototype.innerHTML'

  # Safe wrapper for this property.
  allowlist_regexp: '.+/closure/goog/dom/safe.js'

  # Safe DOM Tree Processor and HTML sanitizer, which use it safely in order to
  # have the browser parse an HTML string using an inert DOM.
  allowlist_regexp: '.+/closure/goog/html/sanitizer/htmlsanitizer.js'
  allowlist_regexp: '.+/closure/goog/html/sanitizer/safedomtreeprocessor.js'
  # Safely used in goog.string.unescapeEntitiesUsingDom_; the string assigned to
  # innerHTML is a single HTML entity.
  allowlist_regexp: '.+/closure/goog/string/string.js'
  # goog.soy.renderElement and renderAsElement.  Safe if used with Strict Soy
  # templates.
  allowlist_regexp: '.+/closure/goog/soy/soy.js'
  allowlist_regexp: '.+/closure/goog/dom/browserrange/ierange.js'
  allowlist_regexp: '.+/closure/goog/editor/'
  allowlist_regexp: '.+/closure/goog/style/style.js'
  allowlist_regexp: '.+/closure/goog/testing/'
}

requirement: {
  rule_id: 'closure:outerHtml'
  type: BANNED_PROPERTY_NON_CONSTANT_WRITE
  error_message: 'Assignment to Element.prototype.outerHTML is not allowed. See https://google.github.io/closure-library/develop/conformance_rules.html#innerHtml'

  value: 'Element.prototype.outerHTML'

  # Safe wrapper for this property.
  allowlist_regexp: '.+/closure/goog/dom/safe.js'
  allowlist_regexp: '.+/closure/goog/editor/'
}

requirement: {
  rule_id: 'closure:documentWrite'
  type: BANNED_PROPERTY
  error_message: 'Using Document.prototype.write is not allowed. Use goog.dom.safe.documentWrite instead. See https://google.github.io/closure-library/develop/conformance_rules.html#documentWrite.'

  value: 'Document.prototype.write'
  value: 'Document.prototype.writeln'

  # These are safe.
  allowlist_regexp: '.+/closure/goog/async/nexttick.js'
  allowlist_regexp: '.+/closure/goog/base.js'
  allowlist_regexp: '.+/closure/goog/dom/safe.js'
  # TODO(jakubvrana): These need to be refactored.
  allowlist_regexp: '.+/closure/goog/editor/icontent.js'
  allowlist_regexp: '.+/closure/goog/testing/'
}

requirement: {
  rule_id: "closure:untypedScript"
  type: CUSTOM
  java_class: "com.google.javascript.jscomp.ConformanceRules$BanCreateElement"
  error_message: "Use goog.dom functions with goog.dom.TagName.SCRIPT to create <script> elements. See https://google.github.io/closure-library/develop/conformance_rules.html#untypedElements"

  value: "script"

  allowlist_regexp: ".+/closure/goog/base.js"
}

requirement: {
  rule_id: "closure:untypedIframe"
  type: CUSTOM
  java_class: "com.google.javascript.jscomp.ConformanceRules$BanCreateElement"
  error_message: "Use goog.dom functions with goog.dom.TagName.IFRAME to create <iframe> elements. See https://google.github.io/closure-library/develop/conformance_rules.html#untypedElements"

  value: "iframe"

  allowlist_regexp: ".+/closure/goog/async/nexttick.js"
}

requirement: {
  rule_id: "closure:untypedFrame"
  type: CUSTOM
  java_class: "com.google.javascript.jscomp.ConformanceRules$BanCreateElement"
  error_message: "Use goog.dom functions with goog.dom.TagName.FRAME to create <frame> elements. See https://google.github.io/closure-library/develop/conformance_rules.html#untypedElements"

  value: "frame"
}

requirement: {
  rule_id: "closure:untypedObject"
  type: CUSTOM
  java_class: "com.google.javascript.jscomp.ConformanceRules$BanCreateElement"
  error_message: "Use goog.dom functions with goog.dom.TagName.OBJECT to create <object> elements. See https://google.github.io/closure-library/develop/conformance_rules.html#untypedElements"

  value: "object"
}

requirement: {
  rule_id: "closure:untypedEmbed"
  type: CUSTOM
  java_class: "com.google.javascript.jscomp.ConformanceRules$BanCreateElement"
  error_message: "Use goog.dom functions with goog.dom.TagName.EMBED to create <embed> elements. See https://google.github.io/closure-library/develop/conformance_rules.html#untypedElements"

  value: "embed"
}

requirement: {
  rule_id: 'closure:scriptContentProperty'
  type: BANNED_PROPERTY_WRITE
  error_message: 'Setting content of <script> and then appending it to the document has the same effect as calling eval(). See https://google.github.io/closure-library/develop/conformance_rules.html#scriptContent'
  # We ban untyped script creation by closure:untypedScript.
  report_loose_type_violations: false

  value: 'HTMLScriptElement.prototype.innerHTML'
  value: 'HTMLScriptElement.prototype.text'
  value: 'HTMLScriptElement.prototype.textContent'

  allowlist_regexp: '.+/closure/goog/base.js'
  allowlist_regexp: '.+/closure/goog/dom/safe.js'
}

requirement: {
  rule_id: 'closure:scriptContentMethod'
  type: BANNED_PROPERTY
  error_message: 'Setting content of <script> and then appending it to the document has the same effect as calling eval(). See https://google.github.io/closure-library/develop/conformance_rules.html#scriptContent'
  # We ban untyped script creation by closure:untypedScript.
  report_loose_type_violations: false

  value: 'HTMLScriptElement.prototype.appendChild'

  allowlist_regexp: '.+/closure/goog/base.js'
}

#### DOM properties and functions which accept URLs ####

# One rule per property name that exists for several types (e.g. href).
# Property names that exist for a single type (e.g. manifest) all
# share a single rule.
# Types with several dangerous properties and functions have their own rule
# (e.g. Location). This rule does not include any of its properties which are
# shared with other types (e.g. Location.prototype.href).
#
# For property names that exist on several types (e.g. href), the matching
# is done for their shared super type, even if the super type itself does not
# have the property. For example, Element does not have the href property, but
# many of its subtypes have. It's also necessary to match on Element for
# properties that exist on Element's subtypes because document.createElement()
# returns Element; matching on its subtypes only would miss many writes to the
# property.

# TODO(mlourenco): Create locationType rule banning protocol, assign()
# and replace() of Location.

# TODO(mlourenco): Move to "hrefProperty".
requirement: {
  rule_id: 'closure:locationHref'
  type: BANNED_PROPERTY_NON_CONSTANT_WRITE
  error_message: 'Assignment to Location.prototype.href is not allowed. See https://google.github.io/closure-library/develop/conformance_rules.html#location'

  value: 'Location.prototype.href'

  allowlist_regexp: '.+/closure/goog/dom/safe.js'

  # The following allowlist entries are due to usages of .href that still
  # need to be refactored or reviewed. See http://b/12014412.
  allowlist_regexp: '.+/closure/goog/history/history.js'
}

# TODO(mlourenco): Rename to "locationProperty". Add Document.location to it.
requirement: {
  rule_id: 'closure:location'
  type: BANNED_PROPERTY_NON_CONSTANT_WRITE
  error_message: 'Assignment to Window.prototype.location is not allowed. See https://google.github.io/closure-library/develop/conformance_rules.html#location'

  value: 'Window.prototype.location'
}

# TODO(user): Rename hrefProperty.
requirement: {
  rule_id: 'closure:href'
  type: BANNED_PROPERTY_NON_CONSTANT_WRITE
  error_message: 'Assignment to .href property of Anchor, Link, etc elements, is not allowed. See https://google.github.io/closure-library/develop/conformance_rules.html#href'

  # Many subtypes of Element have an href property.
  value: 'Element.prototype.href'
  # These are not subtypes of Element.
  value: 'StyleSheet.prototype.href'
  value: 'CSSImportRule.prototype.href'

  # Safe wrapper for this property.
  allowlist_regexp: '.+/closure/goog/dom/safe.js'
  # The following allowlist entries are due to usages of .href that still
  # need to be refactored or reviewed. See http://b/12014412.
  allowlist_regexp: '.+/closure/goog/editor/plugins/linkdialogplugin.js'
  allowlist_regexp: '.+/closure/goog/testing/testrunner.js'
  # This use has previously been refactored away, but had to be rolled
  # back due to breakages in gmail, see http://b/13727806.
  # This use may actually be safe because it only assigns to .href in
  # the context of a contenteditable. To be further reviewed.
  allowlist_regexp: '.+/closure/goog/editor/link.js'
}

# TODO(mlourenco): Move src to "srcProperty", others to "otherProperties". Ban
# "src" and other properties at "Element", so that elements returned by
# document.createElement() are captured.
requirement: {
  rule_id: "closure:trustedResourceUrlProperties"
  type: BANNED_PROPERTY_NON_CONSTANT_WRITE
  error_message: "Assignment to property requires a TrustedResourceUrl via goog.dom.safe. See https://google.github.io/closure-library/develop/conformance_rules.html#trustedResourceUrl"
  report_loose_type_violations: false

  # Properties which can only be assigned to from a TrustedResourceUrl.
  value: "HTMLElement.prototype.manifest"
  value: 'HTMLEmbedElement.prototype.src'
  value: 'HTMLFrameElement.prototype.src'
  value: 'HTMLIFrameElement.prototype.src'
  # For HTMLLinkElement both href and rel have to be assigned at the same time.
  value: "HTMLLinkElement.prototype.rel"
  # TODO(mlourenco): We probably want an "objectType" rule instead since
  # there are a bunch of dangerous properties.
  value: "HTMLObjectElement.prototype.data"
  value: 'HTMLScriptElement.prototype.src'
  # TODO(mlourenco): Ban other dangerous properties (archive, classid, etc).

  # Closure's debug loader.
  allowlist_regexp: '.+/closure/goog/base.js'
  # Safe wrapper for this property.
  allowlist_regexp: ".+/closure/goog/dom/safe.js"
  # The following allowlist entries are due to assignments from string that
  # still need to be refactored or reviewed. See http://b/12014412.
  allowlist_regexp: '.+/closure/goog/net/crossdomainrpc.js'
  allowlist_regexp: '.+/closure/goog/net/xpc/'
  allowlist_regexp: '.+/closure/goog/testing/multitestrunner.js'
  allowlist_regexp: '.+/closure/goog/ui/dragdropdetector.js'
}

requirement: {
  rule_id: "closure:createDom"
  type: CUSTOM
  java_class: "com.google.javascript.jscomp.ConformanceRules$BanCreateDom"
  error_message: "Assigning a string to a dangerous property via createDom is forbidden. See https://google.github.io/closure-library/develop/conformance_rules.html#createDom"

  value: "embed.src"
  value: "frame.src"
  value: "html.manifest"
  value: "iframe.src"
  value: "object.data"
  value: "script.src"
  value: "script.text"
  value: "script.textContent"
  value: "track.src"
  value: '*.href'
  value: '*.innerHTML'
  value: '*.outerHTML'

  allowlist_regexp: ".+/closure/tweak/tweakui.js"  # False positive - missing type on containerNodeName. MOE:strip_line
  allowlist_regexp: '.+/closure/goog/tweak/tweakui.js' # False positive - missing type on containerNodeName.

  # TODO(jakubvrana): Ban this.
  allowlist_regexp: '.+/closure/goog/ui/abstractspellchecker.js'
}

#### Closure functions which use goog.html.legacyconversions ####

# These are functions which accept a string and then use
# goog.html.legacyconversions to convert the string into SafeHtml. They
# are not XSS-safe.
#
# These rules allow projects to have compile-time errors for legacyconversions
# functions and to progressively move away from them by using the allowlist.