Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: Source/devtools/scripts/check_injected_script_source.py

Issue 470543002: DevTools: Don't allow native global functions in injected script. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebased Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/inspector/InjectedScriptSource.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2014 Google Inc. All rights reserved. 2 # Copyright (c) 2014 Google Inc. All rights reserved.
3 # 3 #
4 # Redistribution and use in source and binary forms, with or without 4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are 5 # modification, are permitted provided that the following conditions are
6 # met: 6 # met:
7 # 7 #
8 # * Redistributions of source code must retain the above copyright 8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer. 9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above 10 # * Redistributions in binary form must reproduce the above
(...skipping 27 matching lines...) Expand all
38 f.close() 38 f.close()
39 39
40 proto_functions = "|".join([ 40 proto_functions = "|".join([
41 # Array.prototype.* 41 # Array.prototype.*
42 "concat", "every", "filter", "forEach", "indexOf", "join", "lastIndexOf" , "map", "pop", 42 "concat", "every", "filter", "forEach", "indexOf", "join", "lastIndexOf" , "map", "pop",
43 "push", "reduce", "reduceRight", "reverse", "shift", "slice", "some", "s ort", "splice", "toLocaleString", "toString", "unshift", 43 "push", "reduce", "reduceRight", "reverse", "shift", "slice", "some", "s ort", "splice", "toLocaleString", "toString", "unshift",
44 # Function.prototype.* 44 # Function.prototype.*
45 "apply", "bind", "call", "isGenerator", "toSource", 45 "apply", "bind", "call", "isGenerator", "toSource",
46 ]) 46 ])
47 47
48 global_functions = "|".join([
49 "eval", "uneval", "isFinite", "isNaN", "parseFloat", "parseInt", "decode URI", "decodeURIComponent",
50 "encodeURI", "encodeURIComponent", "escape", "unescape",
51 ])
52
48 # Black list: 53 # Black list:
49 # - Object.prototype.toString() 54 # - Object.prototype.toString()
50 # - Array.prototype.* 55 # - Array.prototype.*
51 # - Function.prototype.* 56 # - Function.prototype.*
52 # - Math.* 57 # - Math.*
53 black_list_call_regex = re.compile(r"\bMath\.\w+\(|\.(toString|" + proto_fun ctions + r")\(") 58 # - Global functions
59 black_list_call_regex = re.compile(r"\bMath\.\w+\(|\.(toString|" + proto_fun ctions + r")\(|[^\.]\b(" + global_functions + r")\(")
54 60
55 errors_found = False 61 errors_found = False
56 for i, line in enumerate(lines): 62 for i, line in enumerate(lines):
57 for match in re.finditer(black_list_call_regex, line): 63 for match in re.finditer(black_list_call_regex, line):
58 errors_found = True 64 errors_found = True
59 print "ERROR: Black list function call in %s at line %02d column %02 d: %s" % (os.path.basename(fileName), i + 1, match.start(), match.group(0)) 65 print "ERROR: Black list function call in %s at line %02d column %02 d: %s" % (os.path.basename(fileName), i + 1, match.start(), match.group(0))
60 66
61 if not errors_found: 67 if not errors_found:
62 print "OK" 68 print "OK"
63 69
64 70
65 def main(argv): 71 def main(argv):
66 if len(argv) < 2: 72 if len(argv) < 2:
67 print('ERROR: Usage: %s path/to/InjectedScriptSource.js' % argv[0]) 73 print('ERROR: Usage: %s path/to/InjectedScriptSource.js' % argv[0])
68 return 1 74 return 1
69 75
70 validate_injected_script(argv[1]) 76 validate_injected_script(argv[1])
71 77
72 if __name__ == '__main__': 78 if __name__ == '__main__':
73 sys.exit(main(sys.argv)) 79 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « Source/core/inspector/InjectedScriptSource.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698