immunio 1.2.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (291) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -5
  3. data/ext/immunio/Rakefile +14 -6
  4. data/lib/immunio/context.rb +2 -0
  5. data/lib/immunio/plugins/action_view.rb +7 -668
  6. data/lib/immunio/plugins/action_view/action_view.rb +22 -0
  7. data/lib/immunio/plugins/action_view/active_support_hash.rb +29 -0
  8. data/lib/immunio/plugins/action_view/cache_store.rb +24 -0
  9. data/lib/immunio/plugins/action_view/erubi.rb +38 -0
  10. data/lib/immunio/plugins/action_view/erubis.rb +39 -0
  11. data/lib/immunio/plugins/action_view/fragment_caching.rb +29 -0
  12. data/lib/immunio/plugins/action_view/haml.rb +46 -0
  13. data/lib/immunio/plugins/action_view/slim.rb +42 -0
  14. data/lib/immunio/plugins/action_view/template.rb +431 -0
  15. data/lib/immunio/plugins/action_view/template_rendering.rb +45 -0
  16. data/lib/immunio/plugins/http_tracker.rb +2 -0
  17. data/lib/immunio/plugins/io.rb +34 -0
  18. data/lib/immunio/version.rb +1 -1
  19. data/lua-hooks/Makefile +36 -9
  20. data/lua-hooks/ext/luajit/COPYRIGHT +1 -1
  21. data/lua-hooks/ext/luajit/Makefile +22 -15
  22. data/lua-hooks/ext/luajit/README +2 -2
  23. data/lua-hooks/ext/luajit/doc/bluequad-print.css +1 -1
  24. data/lua-hooks/ext/luajit/doc/bluequad.css +1 -1
  25. data/lua-hooks/ext/luajit/doc/changes.html +69 -3
  26. data/lua-hooks/ext/luajit/doc/contact.html +10 -3
  27. data/lua-hooks/ext/luajit/doc/ext_c_api.html +2 -2
  28. data/lua-hooks/ext/luajit/doc/ext_ffi.html +2 -2
  29. data/lua-hooks/ext/luajit/doc/ext_ffi_api.html +2 -2
  30. data/lua-hooks/ext/luajit/doc/ext_ffi_semantics.html +3 -4
  31. data/lua-hooks/ext/luajit/doc/ext_ffi_tutorial.html +2 -2
  32. data/lua-hooks/ext/luajit/doc/ext_jit.html +3 -3
  33. data/lua-hooks/ext/luajit/doc/ext_profiler.html +2 -2
  34. data/lua-hooks/ext/luajit/doc/extensions.html +47 -20
  35. data/lua-hooks/ext/luajit/doc/faq.html +2 -2
  36. data/lua-hooks/ext/luajit/doc/install.html +74 -45
  37. data/lua-hooks/ext/luajit/doc/luajit.html +5 -5
  38. data/lua-hooks/ext/luajit/doc/running.html +3 -3
  39. data/lua-hooks/ext/luajit/doc/status.html +13 -8
  40. data/lua-hooks/ext/luajit/dynasm/dasm_arm.h +1 -1
  41. data/lua-hooks/ext/luajit/dynasm/dasm_arm.lua +1 -1
  42. data/lua-hooks/ext/luajit/dynasm/dasm_arm64.h +1 -1
  43. data/lua-hooks/ext/luajit/dynasm/dasm_arm64.lua +1 -1
  44. data/lua-hooks/ext/luajit/dynasm/dasm_mips.h +8 -5
  45. data/lua-hooks/ext/luajit/dynasm/dasm_mips.lua +66 -11
  46. data/lua-hooks/ext/luajit/dynasm/dasm_mips64.lua +12 -0
  47. data/lua-hooks/ext/luajit/dynasm/dasm_ppc.h +1 -1
  48. data/lua-hooks/ext/luajit/dynasm/dasm_ppc.lua +1 -1
  49. data/lua-hooks/ext/luajit/dynasm/dasm_proto.h +1 -1
  50. data/lua-hooks/ext/luajit/dynasm/dasm_x64.lua +1 -1
  51. data/lua-hooks/ext/luajit/dynasm/dasm_x86.h +1 -1
  52. data/lua-hooks/ext/luajit/dynasm/dasm_x86.lua +5 -1
  53. data/lua-hooks/ext/luajit/dynasm/dynasm.lua +2 -2
  54. data/lua-hooks/ext/luajit/etc/luajit.1 +1 -1
  55. data/lua-hooks/ext/luajit/etc/luajit.pc +1 -1
  56. data/lua-hooks/ext/luajit/src/Makefile +15 -11
  57. data/lua-hooks/ext/luajit/src/Makefile.dep +16 -16
  58. data/lua-hooks/ext/luajit/src/host/buildvm.c +2 -2
  59. data/lua-hooks/ext/luajit/src/host/buildvm.h +1 -1
  60. data/lua-hooks/ext/luajit/src/host/buildvm_asm.c +9 -4
  61. data/lua-hooks/ext/luajit/src/host/buildvm_fold.c +2 -2
  62. data/lua-hooks/ext/luajit/src/host/buildvm_lib.c +1 -1
  63. data/lua-hooks/ext/luajit/src/host/buildvm_libbc.h +14 -3
  64. data/lua-hooks/ext/luajit/src/host/buildvm_peobj.c +27 -3
  65. data/lua-hooks/ext/luajit/src/host/genlibbc.lua +1 -1
  66. data/lua-hooks/ext/luajit/src/host/genminilua.lua +6 -5
  67. data/lua-hooks/ext/luajit/src/host/minilua.c +1 -1
  68. data/lua-hooks/ext/luajit/src/jit/bc.lua +1 -1
  69. data/lua-hooks/ext/luajit/src/jit/bcsave.lua +8 -8
  70. data/lua-hooks/ext/luajit/src/jit/dis_arm.lua +2 -2
  71. data/lua-hooks/ext/luajit/src/jit/dis_arm64.lua +1216 -0
  72. data/lua-hooks/ext/luajit/src/jit/dis_arm64be.lua +12 -0
  73. data/lua-hooks/ext/luajit/src/jit/dis_mips.lua +35 -20
  74. data/lua-hooks/ext/luajit/src/jit/dis_mips64.lua +17 -0
  75. data/lua-hooks/ext/luajit/src/jit/dis_mips64el.lua +17 -0
  76. data/lua-hooks/ext/luajit/src/jit/dis_mipsel.lua +1 -1
  77. data/lua-hooks/ext/luajit/src/jit/dis_ppc.lua +2 -2
  78. data/lua-hooks/ext/luajit/src/jit/dis_x64.lua +1 -1
  79. data/lua-hooks/ext/luajit/src/jit/dis_x86.lua +7 -4
  80. data/lua-hooks/ext/luajit/src/jit/dump.lua +17 -12
  81. data/lua-hooks/ext/luajit/src/jit/p.lua +3 -2
  82. data/lua-hooks/ext/luajit/src/jit/v.lua +2 -2
  83. data/lua-hooks/ext/luajit/src/jit/zone.lua +1 -1
  84. data/lua-hooks/ext/luajit/src/lauxlib.h +14 -20
  85. data/lua-hooks/ext/luajit/src/lib_aux.c +38 -27
  86. data/lua-hooks/ext/luajit/src/lib_base.c +12 -5
  87. data/lua-hooks/ext/luajit/src/lib_bit.c +1 -1
  88. data/lua-hooks/ext/luajit/src/lib_debug.c +5 -5
  89. data/lua-hooks/ext/luajit/src/lib_ffi.c +2 -2
  90. data/lua-hooks/ext/luajit/src/lib_init.c +16 -16
  91. data/lua-hooks/ext/luajit/src/lib_io.c +6 -7
  92. data/lua-hooks/ext/luajit/src/lib_jit.c +14 -4
  93. data/lua-hooks/ext/luajit/src/lib_math.c +1 -5
  94. data/lua-hooks/ext/luajit/src/lib_os.c +1 -1
  95. data/lua-hooks/ext/luajit/src/lib_package.c +14 -23
  96. data/lua-hooks/ext/luajit/src/lib_string.c +1 -5
  97. data/lua-hooks/ext/luajit/src/lib_table.c +21 -1
  98. data/lua-hooks/ext/luajit/src/lj.supp +3 -3
  99. data/lua-hooks/ext/luajit/src/lj_alloc.c +174 -83
  100. data/lua-hooks/ext/luajit/src/lj_api.c +97 -18
  101. data/lua-hooks/ext/luajit/src/lj_arch.h +54 -22
  102. data/lua-hooks/ext/luajit/src/lj_asm.c +172 -53
  103. data/lua-hooks/ext/luajit/src/lj_asm.h +1 -1
  104. data/lua-hooks/ext/luajit/src/lj_asm_arm.h +19 -16
  105. data/lua-hooks/ext/luajit/src/lj_asm_arm64.h +2022 -0
  106. data/lua-hooks/ext/luajit/src/lj_asm_mips.h +564 -158
  107. data/lua-hooks/ext/luajit/src/lj_asm_ppc.h +19 -18
  108. data/lua-hooks/ext/luajit/src/lj_asm_x86.h +578 -92
  109. data/lua-hooks/ext/luajit/src/lj_bc.c +1 -1
  110. data/lua-hooks/ext/luajit/src/lj_bc.h +1 -1
  111. data/lua-hooks/ext/luajit/src/lj_bcdump.h +1 -1
  112. data/lua-hooks/ext/luajit/src/lj_bcread.c +1 -1
  113. data/lua-hooks/ext/luajit/src/lj_bcwrite.c +1 -1
  114. data/lua-hooks/ext/luajit/src/lj_buf.c +1 -1
  115. data/lua-hooks/ext/luajit/src/lj_buf.h +1 -1
  116. data/lua-hooks/ext/luajit/src/lj_carith.c +1 -1
  117. data/lua-hooks/ext/luajit/src/lj_carith.h +1 -1
  118. data/lua-hooks/ext/luajit/src/lj_ccall.c +172 -7
  119. data/lua-hooks/ext/luajit/src/lj_ccall.h +21 -5
  120. data/lua-hooks/ext/luajit/src/lj_ccallback.c +71 -17
  121. data/lua-hooks/ext/luajit/src/lj_ccallback.h +1 -1
  122. data/lua-hooks/ext/luajit/src/lj_cconv.c +4 -2
  123. data/lua-hooks/ext/luajit/src/lj_cconv.h +1 -1
  124. data/lua-hooks/ext/luajit/src/lj_cdata.c +7 -5
  125. data/lua-hooks/ext/luajit/src/lj_cdata.h +1 -1
  126. data/lua-hooks/ext/luajit/src/lj_clib.c +5 -5
  127. data/lua-hooks/ext/luajit/src/lj_clib.h +1 -1
  128. data/lua-hooks/ext/luajit/src/lj_cparse.c +11 -6
  129. data/lua-hooks/ext/luajit/src/lj_cparse.h +1 -1
  130. data/lua-hooks/ext/luajit/src/lj_crecord.c +70 -14
  131. data/lua-hooks/ext/luajit/src/lj_crecord.h +1 -1
  132. data/lua-hooks/ext/luajit/src/lj_ctype.c +1 -1
  133. data/lua-hooks/ext/luajit/src/lj_ctype.h +8 -8
  134. data/lua-hooks/ext/luajit/src/lj_debug.c +1 -1
  135. data/lua-hooks/ext/luajit/src/lj_debug.h +1 -1
  136. data/lua-hooks/ext/luajit/src/lj_def.h +6 -9
  137. data/lua-hooks/ext/luajit/src/lj_dispatch.c +3 -3
  138. data/lua-hooks/ext/luajit/src/lj_dispatch.h +2 -1
  139. data/lua-hooks/ext/luajit/src/lj_emit_arm.h +5 -4
  140. data/lua-hooks/ext/luajit/src/lj_emit_arm64.h +419 -0
  141. data/lua-hooks/ext/luajit/src/lj_emit_mips.h +100 -20
  142. data/lua-hooks/ext/luajit/src/lj_emit_ppc.h +4 -4
  143. data/lua-hooks/ext/luajit/src/lj_emit_x86.h +116 -25
  144. data/lua-hooks/ext/luajit/src/lj_err.c +34 -13
  145. data/lua-hooks/ext/luajit/src/lj_err.h +1 -1
  146. data/lua-hooks/ext/luajit/src/lj_errmsg.h +1 -1
  147. data/lua-hooks/ext/luajit/src/lj_ff.h +1 -1
  148. data/lua-hooks/ext/luajit/src/lj_ffrecord.c +58 -49
  149. data/lua-hooks/ext/luajit/src/lj_ffrecord.h +1 -1
  150. data/lua-hooks/ext/luajit/src/lj_frame.h +33 -6
  151. data/lua-hooks/ext/luajit/src/lj_func.c +4 -2
  152. data/lua-hooks/ext/luajit/src/lj_func.h +1 -1
  153. data/lua-hooks/ext/luajit/src/lj_gc.c +16 -7
  154. data/lua-hooks/ext/luajit/src/lj_gc.h +1 -1
  155. data/lua-hooks/ext/luajit/src/lj_gdbjit.c +31 -1
  156. data/lua-hooks/ext/luajit/src/lj_gdbjit.h +1 -1
  157. data/lua-hooks/ext/luajit/src/lj_ir.c +69 -96
  158. data/lua-hooks/ext/luajit/src/lj_ir.h +29 -18
  159. data/lua-hooks/ext/luajit/src/lj_ircall.h +24 -30
  160. data/lua-hooks/ext/luajit/src/lj_iropt.h +9 -9
  161. data/lua-hooks/ext/luajit/src/lj_jit.h +67 -9
  162. data/lua-hooks/ext/luajit/src/lj_lex.c +1 -1
  163. data/lua-hooks/ext/luajit/src/lj_lex.h +1 -1
  164. data/lua-hooks/ext/luajit/src/lj_lib.c +1 -1
  165. data/lua-hooks/ext/luajit/src/lj_lib.h +1 -1
  166. data/lua-hooks/ext/luajit/src/lj_load.c +1 -1
  167. data/lua-hooks/ext/luajit/src/lj_mcode.c +11 -10
  168. data/lua-hooks/ext/luajit/src/lj_mcode.h +1 -1
  169. data/lua-hooks/ext/luajit/src/lj_meta.c +1 -1
  170. data/lua-hooks/ext/luajit/src/lj_meta.h +1 -1
  171. data/lua-hooks/ext/luajit/src/lj_obj.c +1 -1
  172. data/lua-hooks/ext/luajit/src/lj_obj.h +7 -3
  173. data/lua-hooks/ext/luajit/src/lj_opt_dce.c +1 -1
  174. data/lua-hooks/ext/luajit/src/lj_opt_fold.c +84 -17
  175. data/lua-hooks/ext/luajit/src/lj_opt_loop.c +1 -1
  176. data/lua-hooks/ext/luajit/src/lj_opt_mem.c +3 -3
  177. data/lua-hooks/ext/luajit/src/lj_opt_narrow.c +24 -22
  178. data/lua-hooks/ext/luajit/src/lj_opt_sink.c +11 -6
  179. data/lua-hooks/ext/luajit/src/lj_opt_split.c +11 -2
  180. data/lua-hooks/ext/luajit/src/lj_parse.c +9 -7
  181. data/lua-hooks/ext/luajit/src/lj_parse.h +1 -1
  182. data/lua-hooks/ext/luajit/src/lj_profile.c +1 -1
  183. data/lua-hooks/ext/luajit/src/lj_profile.h +1 -1
  184. data/lua-hooks/ext/luajit/src/lj_record.c +201 -117
  185. data/lua-hooks/ext/luajit/src/lj_record.h +1 -1
  186. data/lua-hooks/ext/luajit/src/lj_snap.c +72 -26
  187. data/lua-hooks/ext/luajit/src/lj_snap.h +1 -1
  188. data/lua-hooks/ext/luajit/src/lj_state.c +6 -6
  189. data/lua-hooks/ext/luajit/src/lj_state.h +2 -2
  190. data/lua-hooks/ext/luajit/src/lj_str.c +1 -1
  191. data/lua-hooks/ext/luajit/src/lj_str.h +1 -1
  192. data/lua-hooks/ext/luajit/src/lj_strfmt.c +7 -3
  193. data/lua-hooks/ext/luajit/src/lj_strfmt.h +1 -1
  194. data/lua-hooks/ext/luajit/src/lj_strfmt_num.c +4 -3
  195. data/lua-hooks/ext/luajit/src/lj_strscan.c +1 -1
  196. data/lua-hooks/ext/luajit/src/lj_strscan.h +1 -1
  197. data/lua-hooks/ext/luajit/src/lj_tab.c +1 -2
  198. data/lua-hooks/ext/luajit/src/lj_tab.h +1 -1
  199. data/lua-hooks/ext/luajit/src/lj_target.h +3 -3
  200. data/lua-hooks/ext/luajit/src/lj_target_arm.h +1 -1
  201. data/lua-hooks/ext/luajit/src/lj_target_arm64.h +239 -7
  202. data/lua-hooks/ext/luajit/src/lj_target_mips.h +111 -22
  203. data/lua-hooks/ext/luajit/src/lj_target_ppc.h +1 -1
  204. data/lua-hooks/ext/luajit/src/lj_target_x86.h +21 -4
  205. data/lua-hooks/ext/luajit/src/lj_trace.c +63 -18
  206. data/lua-hooks/ext/luajit/src/lj_trace.h +2 -1
  207. data/lua-hooks/ext/luajit/src/lj_traceerr.h +1 -1
  208. data/lua-hooks/ext/luajit/src/lj_udata.c +1 -1
  209. data/lua-hooks/ext/luajit/src/lj_udata.h +1 -1
  210. data/lua-hooks/ext/luajit/src/lj_vm.h +5 -1
  211. data/lua-hooks/ext/luajit/src/lj_vmevent.c +1 -1
  212. data/lua-hooks/ext/luajit/src/lj_vmevent.h +1 -1
  213. data/lua-hooks/ext/luajit/src/lj_vmmath.c +1 -1
  214. data/lua-hooks/ext/luajit/src/ljamalg.c +1 -1
  215. data/lua-hooks/ext/luajit/src/lua.h +9 -1
  216. data/lua-hooks/ext/luajit/src/luaconf.h +3 -7
  217. data/lua-hooks/ext/luajit/src/luajit.c +69 -54
  218. data/lua-hooks/ext/luajit/src/luajit.h +4 -4
  219. data/lua-hooks/ext/luajit/src/lualib.h +1 -1
  220. data/lua-hooks/ext/luajit/src/msvcbuild.bat +12 -4
  221. data/lua-hooks/ext/luajit/src/vm_arm.dasc +1 -1
  222. data/lua-hooks/ext/luajit/src/vm_arm64.dasc +255 -32
  223. data/lua-hooks/ext/luajit/src/vm_mips.dasc +26 -23
  224. data/lua-hooks/ext/luajit/src/vm_mips64.dasc +5062 -0
  225. data/lua-hooks/ext/luajit/src/vm_ppc.dasc +1 -1
  226. data/lua-hooks/ext/luajit/src/vm_x64.dasc +24 -25
  227. data/lua-hooks/ext/luajit/src/vm_x86.dasc +77 -4
  228. data/lua-hooks/libluahooks.darwin.a +0 -0
  229. data/lua-hooks/libluahooks.linux.a +0 -0
  230. data/lua-hooks/options.mk +1 -1
  231. metadata +37 -77
  232. data/lua-hooks/ext/all.c +0 -69
  233. data/lua-hooks/ext/libinjection/COPYING +0 -37
  234. data/lua-hooks/ext/libinjection/libinjection.h +0 -65
  235. data/lua-hooks/ext/libinjection/libinjection_html5.c +0 -847
  236. data/lua-hooks/ext/libinjection/libinjection_html5.h +0 -54
  237. data/lua-hooks/ext/libinjection/libinjection_sqli.c +0 -2301
  238. data/lua-hooks/ext/libinjection/libinjection_sqli.h +0 -295
  239. data/lua-hooks/ext/libinjection/libinjection_sqli_data.h +0 -9349
  240. data/lua-hooks/ext/libinjection/libinjection_xss.c +0 -531
  241. data/lua-hooks/ext/libinjection/libinjection_xss.h +0 -21
  242. data/lua-hooks/ext/libinjection/lualib.c +0 -145
  243. data/lua-hooks/ext/libinjection/module.mk +0 -5
  244. data/lua-hooks/ext/lpeg/HISTORY +0 -96
  245. data/lua-hooks/ext/lpeg/lpcap.c +0 -537
  246. data/lua-hooks/ext/lpeg/lpcap.h +0 -56
  247. data/lua-hooks/ext/lpeg/lpcode.c +0 -1014
  248. data/lua-hooks/ext/lpeg/lpcode.h +0 -40
  249. data/lua-hooks/ext/lpeg/lpeg-128.gif +0 -0
  250. data/lua-hooks/ext/lpeg/lpeg.html +0 -1445
  251. data/lua-hooks/ext/lpeg/lpprint.c +0 -244
  252. data/lua-hooks/ext/lpeg/lpprint.h +0 -36
  253. data/lua-hooks/ext/lpeg/lptree.c +0 -1303
  254. data/lua-hooks/ext/lpeg/lptree.h +0 -82
  255. data/lua-hooks/ext/lpeg/lptypes.h +0 -149
  256. data/lua-hooks/ext/lpeg/lpvm.c +0 -364
  257. data/lua-hooks/ext/lpeg/lpvm.h +0 -58
  258. data/lua-hooks/ext/lpeg/makefile +0 -55
  259. data/lua-hooks/ext/lpeg/module.mk +0 -6
  260. data/lua-hooks/ext/lpeg/re.html +0 -498
  261. data/lua-hooks/ext/lua-cmsgpack/.gitignore +0 -13
  262. data/lua-hooks/ext/lua-cmsgpack/CMakeLists.txt +0 -45
  263. data/lua-hooks/ext/lua-cmsgpack/README.md +0 -115
  264. data/lua-hooks/ext/lua-cmsgpack/lua_cmsgpack.c +0 -970
  265. data/lua-hooks/ext/lua-cmsgpack/module.mk +0 -2
  266. data/lua-hooks/ext/lua-cmsgpack/test.lua +0 -570
  267. data/lua-hooks/ext/lua-snapshot/LICENSE +0 -7
  268. data/lua-hooks/ext/lua-snapshot/Makefile +0 -12
  269. data/lua-hooks/ext/lua-snapshot/README.md +0 -18
  270. data/lua-hooks/ext/lua-snapshot/dump.lua +0 -15
  271. data/lua-hooks/ext/lua-snapshot/module.mk +0 -2
  272. data/lua-hooks/ext/lua-snapshot/snapshot.c +0 -462
  273. data/lua-hooks/ext/luautf8/README.md +0 -152
  274. data/lua-hooks/ext/luautf8/lutf8lib.c +0 -1274
  275. data/lua-hooks/ext/luautf8/module.mk +0 -2
  276. data/lua-hooks/ext/luautf8/unidata.h +0 -3064
  277. data/lua-hooks/ext/module.mk +0 -15
  278. data/lua-hooks/ext/modules.h +0 -17
  279. data/lua-hooks/ext/perf/luacpu.c +0 -114
  280. data/lua-hooks/ext/perf/lualoadavg.c +0 -40
  281. data/lua-hooks/ext/perf/luameminfo.c +0 -38
  282. data/lua-hooks/ext/perf/luaoslib.c +0 -203
  283. data/lua-hooks/ext/perf/module.mk +0 -5
  284. data/lua-hooks/ext/sha1/luasha1.c +0 -74
  285. data/lua-hooks/ext/sha1/module.mk +0 -5
  286. data/lua-hooks/ext/sha1/sha1.c +0 -145
  287. data/lua-hooks/ext/sha2/luasha256.c +0 -77
  288. data/lua-hooks/ext/sha2/module.mk +0 -5
  289. data/lua-hooks/ext/sha2/sha256.c +0 -196
  290. data/lua-hooks/ext/sysutils/lua_utils.c +0 -56
  291. data/lua-hooks/ext/sysutils/module.mk +0 -2
@@ -1,531 +0,0 @@
1
-
2
- #include "libinjection.h"
3
- #include "libinjection_xss.h"
4
- #include "libinjection_html5.h"
5
-
6
- #include <assert.h>
7
- #include <stdio.h>
8
-
9
- typedef enum attribute {
10
- TYPE_NONE
11
- , TYPE_BLACK /* ban always */
12
- , TYPE_ATTR_URL /* attribute value takes a URL-like object */
13
- , TYPE_STYLE
14
- , TYPE_ATTR_INDIRECT /* attribute *name* is given in *value* */
15
- } attribute_t;
16
-
17
-
18
- static attribute_t is_black_attr(const char* s, size_t len);
19
- static int is_black_tag(const char* s, size_t len);
20
- static int is_black_url(const char* s, size_t len);
21
- static int cstrcasecmp_with_null(const char *a, const char *b, size_t n);
22
- static int html_decode_char_at(const char* src, size_t len, size_t* consumed);
23
- static int htmlencode_startswith(const char* prefix, const char *src, size_t n);
24
-
25
-
26
- typedef struct stringtype {
27
- const char* name;
28
- attribute_t atype;
29
- } stringtype_t;
30
-
31
-
32
- static const int gsHexDecodeMap[256] = {
33
- 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
34
- 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
35
- 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
36
- 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
37
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 256, 256,
38
- 256, 256, 256, 256, 256, 10, 11, 12, 13, 14, 15, 256,
39
- 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
40
- 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
41
- 256, 10, 11, 12, 13, 14, 15, 256, 256, 256, 256, 256,
42
- 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
43
- 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
44
- 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
45
- 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
46
- 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
47
- 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
48
- 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
49
- 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
50
- 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
51
- 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
52
- 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
53
- 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
54
- 256, 256, 256, 256
55
- };
56
-
57
- static int html_decode_char_at(const char* src, size_t len, size_t* consumed)
58
- {
59
- int val = 0;
60
- size_t i;
61
- int ch;
62
-
63
- if (len == 0 || src == NULL) {
64
- *consumed = 0;
65
- return -1;
66
- }
67
-
68
- *consumed = 1;
69
- if (*src != '&' || len < 2) {
70
- return (unsigned char)(*src);
71
- }
72
-
73
-
74
- if (*(src+1) != '#') {
75
- /* normally this would be for named entities
76
- * but for this case we don't actually care
77
- */
78
- return '&';
79
- }
80
-
81
- if (*(src+2) == 'x' || *(src+2) == 'X') {
82
- ch = (unsigned char) (*(src+3));
83
- ch = gsHexDecodeMap[ch];
84
- if (ch == 256) {
85
- /* degenerate case '&#[?]' */
86
- return '&';
87
- }
88
- val = ch;
89
- i = 4;
90
- while (i < len) {
91
- ch = (unsigned char) src[i];
92
- if (ch == ';') {
93
- *consumed = i + 1;
94
- return val;
95
- }
96
- ch = gsHexDecodeMap[ch];
97
- if (ch == 256) {
98
- *consumed = i;
99
- return val;
100
- }
101
- val = (val * 16) + ch;
102
- if (val > 0x1000FF) {
103
- return '&';
104
- }
105
- ++i;
106
- }
107
- *consumed = i;
108
- return val;
109
- } else {
110
- i = 2;
111
- ch = (unsigned char) src[i];
112
- if (ch < '0' || ch > '9') {
113
- return '&';
114
- }
115
- val = ch - '0';
116
- i += 1;
117
- while (i < len) {
118
- ch = (unsigned char) src[i];
119
- if (ch == ';') {
120
- *consumed = i + 1;
121
- return val;
122
- }
123
- if (ch < '0' || ch > '9') {
124
- *consumed = i;
125
- return val;
126
- }
127
- val = (val * 10) + (ch - '0');
128
- if (val > 0x1000FF) {
129
- return '&';
130
- }
131
- ++i;
132
- }
133
- *consumed = i;
134
- return val;
135
- }
136
- }
137
-
138
-
139
- /*
140
- * view-source:
141
- * data:
142
- * javascript:
143
- */
144
- static stringtype_t BLACKATTR[] = {
145
- { "ACTION", TYPE_ATTR_URL } /* form */
146
- , { "ATTRIBUTENAME", TYPE_ATTR_INDIRECT } /* SVG allow indirection of attribute names */
147
- , { "BY", TYPE_ATTR_URL } /* SVG */
148
- , { "BACKGROUND", TYPE_ATTR_URL } /* IE6, O11 */
149
- , { "DATAFORMATAS", TYPE_BLACK } /* IE */
150
- , { "DATASRC", TYPE_BLACK } /* IE */
151
- , { "DYNSRC", TYPE_ATTR_URL } /* Obsolete img attribute */
152
- , { "FILTER", TYPE_STYLE } /* Opera, SVG inline style */
153
- , { "FORMACTION", TYPE_ATTR_URL } /* HTML5 */
154
- , { "FOLDER", TYPE_ATTR_URL } /* Only on A tags, IE-only */
155
- , { "FROM", TYPE_ATTR_URL } /* SVG */
156
- , { "HANDLER", TYPE_ATTR_URL } /* SVG Tiny, Opera */
157
- , { "HREF", TYPE_ATTR_URL }
158
- , { "LOWSRC", TYPE_ATTR_URL } /* Obsolete img attribute */
159
- , { "POSTER", TYPE_ATTR_URL } /* Opera 10,11 */
160
- , { "SRC", TYPE_ATTR_URL }
161
- , { "STYLE", TYPE_STYLE }
162
- , { "TO", TYPE_ATTR_URL } /* SVG */
163
- , { "VALUES", TYPE_ATTR_URL } /* SVG */
164
- , { "XLINK:HREF", TYPE_ATTR_URL }
165
- , { NULL, TYPE_NONE }
166
- };
167
-
168
- /* xmlns */
169
- /* xml-stylesheet > <eval>, <if expr=> */
170
-
171
- /*
172
- static const char* BLACKATTR[] = {
173
- "ATTRIBUTENAME",
174
- "BACKGROUND",
175
- "DATAFORMATAS",
176
- "HREF",
177
- "SCROLL",
178
- "SRC",
179
- "STYLE",
180
- "SRCDOC",
181
- NULL
182
- };
183
- */
184
-
185
- static const char* BLACKTAG[] = {
186
- "APPLET"
187
- /* , "AUDIO" */
188
- , "BASE"
189
- , "COMMENT" /* IE http://html5sec.org/#38 */
190
- , "EMBED"
191
- /* , "FORM" */
192
- , "FRAME"
193
- , "FRAMESET"
194
- , "HANDLER" /* Opera SVG, effectively a script tag */
195
- , "IFRAME"
196
- , "IMPORT"
197
- , "ISINDEX"
198
- , "LINK"
199
- , "LISTENER"
200
- /* , "MARQUEE" */
201
- , "META"
202
- , "NOSCRIPT"
203
- , "OBJECT"
204
- , "SCRIPT"
205
- , "STYLE"
206
- /* , "VIDEO" */
207
- , "VMLFRAME"
208
- , "XML"
209
- , "XSS"
210
- , NULL
211
- };
212
-
213
-
214
- static int cstrcasecmp_with_null(const char *a, const char *b, size_t n)
215
- {
216
- char ca;
217
- char cb;
218
- /* printf("Comparing to %s %.*s\n", a, (int)n, b); */
219
- while (n-- > 0) {
220
- cb = *b++;
221
- if (cb == '\0') continue;
222
-
223
- ca = *a++;
224
-
225
- if (cb >= 'a' && cb <= 'z') {
226
- cb -= 0x20;
227
- }
228
- /* printf("Comparing %c vs %c with %d left\n", ca, cb, (int)n); */
229
- if (ca != cb) {
230
- return 1;
231
- }
232
- }
233
-
234
- if (*a == 0) {
235
- /* printf(" MATCH \n"); */
236
- return 0;
237
- } else {
238
- return 1;
239
- }
240
- }
241
-
242
- /*
243
- * Does an HTML encoded binary string (const char*, lenght) start with
244
- * a all uppercase c-string (null terminated), case insenstive!
245
- *
246
- * also ignore any embedded nulls in the HTML string!
247
- *
248
- * return 1 if match / starts with
249
- * return 0 if not
250
- */
251
- static int htmlencode_startswith(const char *a, const char *b, size_t n)
252
- {
253
- size_t consumed;
254
- int cb;
255
- int first = 1;
256
- /* printf("Comparing %s with %.*s\n", a,(int)n,b); */
257
- while (n > 0) {
258
- if (*a == 0) {
259
- /* printf("Match EOL!\n"); */
260
- return 1;
261
- }
262
- cb = html_decode_char_at(b, n, &consumed);
263
- b += consumed;
264
- n -= consumed;
265
-
266
- if (first && cb <= 32) {
267
- /* ignore all leading whitespace and control characters */
268
- continue;
269
- }
270
- first = 0;
271
-
272
- if (cb == 0) {
273
- /* always ignore null characters in user input */
274
- continue;
275
- }
276
-
277
- if (cb == 10) {
278
- /* always ignore vtab characters in user input */
279
- /* who allows this?? */
280
- continue;
281
- }
282
-
283
- if (cb >= 'a' && cb <= 'z') {
284
- /* upcase */
285
- cb -= 0x20;
286
- }
287
-
288
- if (*a != (char) cb) {
289
- /* printf(" %c != %c\n", *a, cb); */
290
- /* mismatch */
291
- return 0;
292
- }
293
- a++;
294
- }
295
-
296
- return (*a == 0) ? 1 : 0;
297
- }
298
-
299
- static int is_black_tag(const char* s, size_t len)
300
- {
301
- const char** black;
302
-
303
- if (len < 3) {
304
- return 0;
305
- }
306
-
307
- black = BLACKTAG;
308
- while (*black != NULL) {
309
- if (cstrcasecmp_with_null(*black, s, len) == 0) {
310
- /* printf("Got black tag %s\n", *black); */
311
- return 1;
312
- }
313
- black += 1;
314
- }
315
-
316
- /* anything SVG related */
317
- if ((s[0] == 's' || s[0] == 'S') &&
318
- (s[1] == 'v' || s[1] == 'V') &&
319
- (s[2] == 'g' || s[2] == 'G')) {
320
- /* printf("Got SVG tag \n"); */
321
- return 1;
322
- }
323
-
324
- /* Anything XSL(t) related */
325
- if ((s[0] == 'x' || s[0] == 'X') &&
326
- (s[1] == 's' || s[1] == 'S') &&
327
- (s[2] == 'l' || s[2] == 'L')) {
328
- /* printf("Got XSL tag\n"); */
329
- return 1;
330
- }
331
-
332
- return 0;
333
- }
334
-
335
- static attribute_t is_black_attr(const char* s, size_t len)
336
- {
337
- stringtype_t* black;
338
-
339
- if (len < 2) {
340
- return TYPE_NONE;
341
- }
342
-
343
- /* javascript on.* */
344
- if ((s[0] == 'o' || s[0] == 'O') && (s[1] == 'n' || s[1] == 'N')) {
345
- /* printf("Got javascript on- attribute name\n"); */
346
- return TYPE_BLACK;
347
- }
348
-
349
-
350
- if (len >= 5) {
351
- /* XMLNS can be used to create arbitrary tags */
352
- if (cstrcasecmp_with_null("XMLNS", s, 5) == 0 || cstrcasecmp_with_null("XLINK", s, 5) == 0) {
353
- /* printf("Got XMLNS and XLINK tags\n"); */
354
- return TYPE_BLACK;
355
- }
356
- }
357
-
358
- black = BLACKATTR;
359
- while (black->name != NULL) {
360
- if (cstrcasecmp_with_null(black->name, s, len) == 0) {
361
- /* printf("Got banned attribute name %s\n", black->name); */
362
- return black->atype;
363
- }
364
- black += 1;
365
- }
366
-
367
- return TYPE_NONE;
368
- }
369
-
370
- static int is_black_url(const char* s, size_t len)
371
- {
372
-
373
- static const char* data_url = "DATA";
374
- static const char* viewsource_url = "VIEW-SOURCE";
375
-
376
- /* obsolete but interesting signal */
377
- static const char* vbscript_url = "VBSCRIPT";
378
-
379
- /* covers JAVA, JAVASCRIPT, + colon */
380
- static const char* javascript_url = "JAVA";
381
-
382
- /* skip whitespace */
383
- while (len > 0 && (*s <= 32 || *s >= 127)) {
384
- /*
385
- * HEY: this is a signed character.
386
- * We are intentionally skipping high-bit characters too
387
- * since they are not ascii, and Opera sometimes uses UTF8 whitespace.
388
- *
389
- * Also in EUC-JP some of the high bytes are just ignored.
390
- */
391
- ++s;
392
- --len;
393
- }
394
-
395
- if (htmlencode_startswith(data_url, s, len)) {
396
- return 1;
397
- }
398
-
399
- if (htmlencode_startswith(viewsource_url, s, len)) {
400
- return 1;
401
- }
402
-
403
- if (htmlencode_startswith(javascript_url, s, len)) {
404
- return 1;
405
- }
406
-
407
- if (htmlencode_startswith(vbscript_url, s, len)) {
408
- return 1;
409
- }
410
- return 0;
411
- }
412
-
413
- int libinjection_is_xss(const char* s, size_t len, int flags)
414
- {
415
- h5_state_t h5;
416
- attribute_t attr = TYPE_NONE;
417
-
418
- libinjection_h5_init(&h5, s, len, (enum html5_flags) flags);
419
- while (libinjection_h5_next(&h5)) {
420
- if (h5.token_type != ATTR_VALUE) {
421
- attr = TYPE_NONE;
422
- }
423
-
424
- if (h5.token_type == DOCTYPE) {
425
- return 1;
426
- } else if (h5.token_type == TAG_NAME_OPEN) {
427
- if (is_black_tag(h5.token_start, h5.token_len)) {
428
- return 1;
429
- }
430
- } else if (h5.token_type == ATTR_NAME) {
431
- attr = is_black_attr(h5.token_start, h5.token_len);
432
- } else if (h5.token_type == ATTR_VALUE) {
433
- /*
434
- * IE6,7,8 parsing works a bit differently so
435
- * a whole <script> or other black tag might be hiding
436
- * inside an attribute value under HTML5 parsing
437
- * See http://html5sec.org/#102
438
- * to avoid doing a full reparse of the value, just
439
- * look for "<". This probably need adjusting to
440
- * handle escaped characters
441
- */
442
- /*
443
- if (memchr(h5.token_start, '<', h5.token_len) != NULL) {
444
- return 1;
445
- }
446
- */
447
-
448
- switch (attr) {
449
- case TYPE_NONE:
450
- break;
451
- case TYPE_BLACK:
452
- return 1;
453
- case TYPE_ATTR_URL:
454
- if (is_black_url(h5.token_start, h5.token_len)) {
455
- return 1;
456
- }
457
- break;
458
- case TYPE_STYLE:
459
- return 1;
460
- case TYPE_ATTR_INDIRECT:
461
- /* an attribute name is specified in a _value_ */
462
- if (is_black_attr(h5.token_start, h5.token_len)) {
463
- return 1;
464
- }
465
- break;
466
- /*
467
- default:
468
- assert(0);
469
- */
470
- }
471
- attr = TYPE_NONE;
472
- } else if (h5.token_type == TAG_COMMENT) {
473
- /* IE uses a "`" as a tag ending char */
474
- if (memchr(h5.token_start, '`', h5.token_len) != NULL) {
475
- return 1;
476
- }
477
-
478
- /* IE conditional comment */
479
- if (h5.token_len > 3) {
480
- if (h5.token_start[0] == '[' &&
481
- (h5.token_start[1] == 'i' || h5.token_start[1] == 'I') &&
482
- (h5.token_start[2] == 'f' || h5.token_start[2] == 'F')) {
483
- return 1;
484
- }
485
- if ((h5.token_start[0] == 'x' || h5.token_start[1] == 'X') &&
486
- (h5.token_start[1] == 'm' || h5.token_start[1] == 'M') &&
487
- (h5.token_start[2] == 'l' || h5.token_start[2] == 'L')) {
488
- return 1;
489
- }
490
- }
491
-
492
- if (h5.token_len > 5) {
493
- /* IE <?import pseudo-tag */
494
- if (cstrcasecmp_with_null("IMPORT", h5.token_start, 6) == 0) {
495
- return 1;
496
- }
497
-
498
- /* XML Entity definition */
499
- if (cstrcasecmp_with_null("ENTITY", h5.token_start, 6) == 0) {
500
- return 1;
501
- }
502
- }
503
- }
504
- }
505
- return 0;
506
- }
507
-
508
-
509
- /*
510
- * wrapper
511
- */
512
- int libinjection_xss(const char* s, size_t len)
513
- {
514
- if (libinjection_is_xss(s, len, DATA_STATE)) {
515
- return 1;
516
- }
517
- if (libinjection_is_xss(s, len, VALUE_NO_QUOTE)) {
518
- return 1;
519
- }
520
- if (libinjection_is_xss(s, len, VALUE_SINGLE_QUOTE)) {
521
- return 1;
522
- }
523
- if (libinjection_is_xss(s, len, VALUE_DOUBLE_QUOTE)) {
524
- return 1;
525
- }
526
- if (libinjection_is_xss(s, len, VALUE_BACK_QUOTE)) {
527
- return 1;
528
- }
529
-
530
- return 0;
531
- }