OLD | NEW |
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 Loading... |
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)) |
OLD | NEW |