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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c287a47d42c9475ecbae55e00ff6c4e14cd45e4f
4
- data.tar.gz: 89925d6f6c506a1a42a3a64c9f6f290ab5e1fb46
3
+ metadata.gz: da07fbf1f7440e6caa434a0d95fcd8ca2e7fa4ad
4
+ data.tar.gz: ffee645f3187c4de239f8f7fce89bef8d694a470
5
5
  SHA512:
6
- metadata.gz: cac6affff43c65bccfcd448958b350a4690af6de096c6f43d5d240ad352bc62e4521d5f7c5a023ec68b9a5867be9d8a00ef3297d4460441be7a37dcc2f95f547
7
- data.tar.gz: 59d721edc0ed0d570574aa9e328b57744b76d42d89a1ba96966460739359b2bcc96254a21302b9f6c4880565e4830277aa024e78374b2a902da66e5a21e9c7a4
6
+ metadata.gz: f3501e1052eac74b3ee4fe9b5195c75aa3c66af4c52edacec1213ffd0571469ed57cc18a020bab19037ae2212229a727dc6fd8aa148c1487f66ed821ea7cdafd
7
+ data.tar.gz: 9cc18368c5e8474726307049e3ffdab11940ba328166e8e1a562d01e17bbb98d910f2e677eaa497d215c9bd8fcecd5b7f648d470f460e23754721fde957df3c7
data/README.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Immunio Ruby Agent
2
2
 
3
+ ## Support
4
+
5
+ - Ruby 1.9.3 and up
6
+ - Rails 3.2 to 4.2
7
+
8
+ ## Compilation
9
+
10
+ To compile the agent and its dependencies:
11
+
12
+ ```
13
+ bundle exec rake build
14
+ ```
15
+
3
16
  ## Installation
4
17
 
5
18
  Add the private Immunio gem to your Gemfile:
@@ -128,8 +141,3 @@ class SessionsController < ApplicationController
128
141
  end
129
142
  end
130
143
  ```
131
-
132
- ## Support
133
-
134
- - Ruby 1.9.3 and up
135
- - Rails 3.2 to 4.2
@@ -1,9 +1,17 @@
1
- LIB_DIR = File.expand_path("../../../lib/immunio", __FILE__)
2
- LUA_HOOKS_DIR = File.expand_path("../../../lua-hooks", __FILE__)
1
+ IMMUNIO_DIR = File.expand_path('../../../lib/immunio', __FILE__)
2
+ LUA_HOOKS_DIR = File.expand_path('../../../lua-hooks', __FILE__)
3
+ LUAJIT_SRC_DIR = File.join(LUA_HOOKS_DIR, 'ext/luajit/src')
4
+
5
+ LIBIMMUNIO_SO = File.join(IMMUNIO_DIR, 'libimmunio.so')
6
+ LIBLUAHOOKS_A = File.join(LUA_HOOKS_DIR, "libluahooks.#{Gem::Platform.local.os}.a")
7
+ LIBLUAJIT_A = File.join(LUAJIT_SRC_DIR, 'libluajit.a')
3
8
 
4
9
  task :default do
5
- cd LUA_HOOKS_DIR do
6
- sh "make libimmunio.so"
7
- cp "libimmunio.so", LIB_DIR
10
+ sh "make XCFLAGS='-fPIC -DLUAJIT_ENABLE_GC64' -C #{LUAJIT_SRC_DIR} #{File.basename(LIBLUAJIT_A)}"
11
+ os_type = %x{uname}.strip
12
+ if os_type == 'Darwin'
13
+ sh "cc -shared -o #{LIBIMMUNIO_SO} -Wl,-all_load #{LIBLUAJIT_A} #{LIBLUAHOOKS_A}"
14
+ else
15
+ sh "cc -shared -o #{LIBIMMUNIO_SO} -Wl,--whole-archive #{LIBLUAJIT_A} #{LIBLUAHOOKS_A} -Wl,--no-whole-archive"
8
16
  end
9
- end
17
+ end
@@ -1,3 +1,5 @@
1
+ require 'digest/sha1'
2
+
1
3
  module Immunio
2
4
  module Context
3
5
  RAILS_TEMPLATE_FILTER = /(.*(_erb|_haml))__+\d+_\d+(.*)/
@@ -1,668 +1,7 @@
1
- # Hook into ActionView rendering to inject Immunio's hooks.
2
- require 'securerandom'
3
- require 'ripper'
4
-
5
- module Immunio
6
- # Renders templates by filtering them through Immunio's hook handlers.
7
- class Template
8
- CHECKSUM_CACHE = Hash.new do |cache, template_id|
9
- template = ObjectSpace._id2ref(template_id)
10
-
11
- if template.respond_to?(:source) && !template.source.nil?
12
- finalizer = Immunio::Template.finalize_template(template_id)
13
- ObjectSpace.define_finalizer(template, finalizer)
14
- cache[template_id] = Digest::SHA1.hexdigest(template.source).freeze
15
- end
16
- end
17
-
18
- def self.finalize_template(id)
19
- proc { CHECKSUM_CACHE.delete(id) if CHECKSUM_CACHE.has_key?(id) }
20
- end
21
-
22
- attr_accessor :vars
23
-
24
- def initialize(template)
25
- @template = template
26
- @next_var_id = 0
27
- @next_template_id = 0
28
- @vars = {}
29
- @scheduled_fragments_writes = []
30
- end
31
-
32
- def id
33
- (@template.respond_to?(:virtual_path) && @template.virtual_path) ||
34
- (@template.respond_to?(:source) && @template.source)
35
- end
36
-
37
- def ==(other)
38
- self.class === other && id == other.id
39
- end
40
-
41
- def has_source?
42
- @template.respond_to?(:source) && !@template.source.nil?
43
- end
44
-
45
- def is_text?
46
- @template.formats.first == :text
47
- end
48
-
49
- def load_source(context)
50
- return if !@template.respond_to?(:source) || !@template.source.nil?
51
-
52
- # @template is a virtual template that doesn't contain the source. We need
53
- # to try to load the source. But, the virtual template doesn't know the
54
- # original format of the source template file.
55
- #
56
- # First, try to load it using the Rails defaults (usually "html" and
57
- # "txt"). If that doesn't work, try to use the original format from the
58
- # virtual template.
59
- #
60
- # Though one might think the format from the virtual template would always
61
- # work, unfortunately the format from the template refers to the "type" of
62
- # the template, which may or may not be the same as the format of the
63
- # lookup context, which specifies the file extension of the template. Ugh,
64
- # naming... For example, the lookup context format may be "txt" while the
65
- # template format is "text".
66
- #
67
- # Astute readers may note that there's the possibility the template
68
- # extension is not in the Rails default list of lookup formats, and also
69
- # does not match the template type. We are just going to leave that for
70
- # another day, and hope that day never comes...
71
- begin
72
- refreshed = Immunio::IOHooks.paused { @template.refresh(context) }
73
- rescue
74
- begin
75
- old_formats = context.lookup_context.formats
76
- context.lookup_context.formats = @template.formats
77
- refreshed = Immunio::IOHooks.paused { @template.refresh(context) }
78
- rescue
79
- Immunio.logger.warn { "Failed to refresh template source from #{@template} using contexts #{old_formats} and #{@template.formats}" }
80
- ensure
81
- context.lookup_context.formats = old_formats
82
- end
83
- end
84
-
85
- return if refreshed.nil?
86
-
87
- @template.instance_variable_set :@source, refreshed.source
88
- end
89
-
90
- def template_sha
91
- CHECKSUM_CACHE[@template.object_id]
92
- end
93
-
94
- def compiled?
95
- @template.instance_variable_get :@compiled
96
- end
97
-
98
- # Generate the next var unique ID to be used in a template.
99
- def next_var_id
100
- id = @next_var_id
101
- @next_var_id += 1
102
- id
103
- end
104
-
105
- def next_template_id
106
- id = @next_template_id
107
- @next_template_id += 1
108
- id
109
- end
110
-
111
- def get_nonce
112
- # Generate a two byte CSRNG nonce to make our substitutions unpreictable
113
- # Why only 2 bytes? The nonce is per render, so the odds of guessing it are very low
114
- # and entropy is finite so we don't want to drain the random pool unnecessarily
115
- @nonce ||= SecureRandom.hex(2)
116
- end
117
-
118
- def self.mark_var(content, code, template_id, template_sha, file, line, escape, is_text, handler)
119
- id = Template.next_var_id
120
- nonce = Template.get_nonce
121
-
122
- # NOTE: What happens here is pretty funky to preserve the html_safe SafeBuffer behaviour in ruby.
123
- # If escaped is true we directly concatenate the content between two SafeBuffers. This will cause
124
- # escaping if content is not itself a SafeBuffer.
125
- # Otherwise we explicitly convert to a string, and convert that to a SafeBuffer to ensure that
126
- # for instance no escaping is performed on the contents of a <%== %> Erubis interpolation.
127
- rendering = if escape && !is_text
128
-
129
- # explicitly convert (w/ escapes) and mark safe things that aren't String (SafeBuffer is_a String also)
130
- # `to_s` is used to render any object passed to a template.
131
- # It is called internally when appending to ActionView::OutputBuffer.
132
- # We force rendering to get the actual string.
133
- # This has no impact if `rendered` is already a string.
134
- content = content.to_s.html_safe unless content.is_a? String
135
-
136
- # As a failsafe, just return the content if it already contains our markers. This can occur when
137
- # a helper calls render partial to generate a component of a page. Both render calls are root level
138
- # templates from our perspective.
139
- if content =~ /\{immunio-var:\d+:#{nonce}\}/ then
140
- # don't add markers.
141
- Immunio.logger.debug {"WARNING: ActionView not marking interpolation which already contains markers: \"#{content}\""}
142
- return content
143
- end
144
-
145
- "{immunio-var:#{id}:#{nonce}}".html_safe + content + "{/immunio-var:#{id}:#{nonce}}".html_safe
146
- else
147
- content = "" if content.nil?
148
-
149
- # See comment above
150
- if (content.respond_to? :=~) &&
151
- (content =~ /\{immunio-var:\d+:#{nonce}\}/)
152
- # don't add markers.
153
- Immunio.logger.debug {"WARNING: ActionView not marking interpolation which already contains markers: \"#{content}\""}
154
- return content.html_safe
155
- end
156
-
157
- "{immunio-var:#{id}:#{nonce}}".html_safe + content.to_s.html_safe + "{/immunio-var:#{id}:#{nonce}}".html_safe
158
- end
159
-
160
- # If we got here, the interpolation has been wrapped in our markers and we
161
- # need to record send data about it to the hook
162
- Template.vars[id.to_s] = {
163
- template_sha: template_sha,
164
- template_id: template_id.to_s,
165
- nonce: nonce,
166
- code: wrap_code(code, handler, escape: escape),
167
- file: file,
168
- line: line
169
- }
170
-
171
- rendering
172
- end
173
-
174
- def mark_and_defer_fragment_write(key, content, options)
175
- id = @scheduled_fragments_writes.size
176
- nonce = Template.get_nonce
177
- @scheduled_fragments_writes << [key, content, options]
178
- "{immunio-fragment:#{id}:#{nonce}}#{content}{/immunio-fragment:#{id}:#{nonce}}"
179
- end
180
-
181
- def render(context)
182
- load_source context
183
- # Don't handle templates with no source (inline text templates).
184
- unless has_source?
185
- rendered = yield
186
- rendered.instance_variable_set("@__immunio_processed", true) unless rendered.frozen?
187
- return rendered
188
- end
189
-
190
- begin
191
- root = true if rendering_stack.length == 0
192
-
193
- rendering_stack.push self
194
- # Calculate SHA1 of this template.
195
- template_sha
196
- Immunio.logger.debug {"ActionView rendering template with sha #{@template_sha}, root: #{root}"}
197
- rendered = yield
198
- rendered.instance_variable_set("@__immunio_processed", true) unless rendered.frozen?
199
-
200
- if root
201
- # This is the root template. Let ActionView render it, and then look
202
- # for XSS.
203
-
204
- # If the rendered result isn't a string, or a string-like, then let's
205
- # skip it for safety sake.
206
- unless rendered.respond_to? :to_str
207
- unless $__immunio_av_rendered_non_string
208
- Immunio.logger.warn { "ActionView rendered #{@template.inspect} to a non-string-like value: #{rendered.inspect}. This rendering will not be analyzed for XSS. Further warnings will be suppressed." }
209
- $__immunio_av_rendered_non_string = true
210
- end
211
- return rendered
212
- end
213
-
214
- rendered = rendered.to_str
215
-
216
- result = run_hook!("template_render_done", {
217
- content_type: Mime::Type.lookup_by_extension(@template.formats.first).to_s,
218
- rendered: rendered,
219
- vars: @vars
220
- })
221
-
222
- # We use the return value from the hook handler if present.
223
- rendered = result["rendered"] || rendered.dup
224
-
225
- remove_var_markers! rendered
226
-
227
- # If some fragments were marked to be cached, commit their content to cache.
228
- write_and_remove_fragments! context, rendered
229
-
230
- rendered.html_safe
231
- else
232
- # This is a partial template. Just render it.
233
- rendered
234
- end
235
- ensure
236
- top_template = rendering_stack.pop
237
- unless top_template == self
238
- raise Error, "Unexpected Immunio::Template on rendering stack. Expected #{id}, got #{top_template.try :id}."
239
- end
240
- end
241
- end
242
-
243
- def self.remove_comment(code)
244
- *, last_line = code.rpartition("\n")
245
-
246
- comment = Ripper.slice(last_line, "comment")
247
-
248
- if comment
249
- code = code.sub(Regexp.new(Regexp.escape(comment) + "\\Z"), "")
250
- end
251
-
252
- code
253
- end
254
-
255
- # Generate code injected in templates to wrap everything inside `<%= ... %>`.
256
- def self.generate_render_var_code(code, escape)
257
- template = Template.current
258
- if template
259
- template_id = template.next_template_id
260
-
261
- handler = template.instance_variable_get(:@template).handler
262
- handler_name = if handler.is_a? Class
263
- handler.name
264
- else
265
- handler.class.name
266
- end
267
-
268
- "(__immunio_result = (#{remove_comment(code)}); Immunio::Template.render_var(#{code.strip.inspect}, __immunio_result, #{template_id}, '#{template.template_sha}', __FILE__, __LINE__, #{escape}, #{template.is_text?}, '#{handler_name}'))"
269
- else
270
- code
271
- end
272
- end
273
-
274
- ENCODED_IMMUNIO_TOKENS_RE = Regexp.compile(/(?:{|%7b)immunio-(var|fragment)(?::|%3a)(\d+)(?::|%3a)([0-9a-f]{1,4})(?:}|%7d)(.*?)(?:{|%7b)(?:\/|%2f)immunio-\1(?::|%3a)\2(?::|%3a)\3(?:}|%7d)/i)
275
- def self.decode_immunio_tokens(rendered)
276
- # Look for URI or JS encoded immunio tokens in the rendering and decode them
277
- # WebConsole incompatibility: `rendered` can be of type `Mime::Type` Which
278
- # doesn't respond to `gsub!`.
279
- if rendered.respond_to?(:gsub!)
280
- was_html_safe = rendered.html_safe?
281
- was_frozen = rendered.frozen?
282
-
283
- if was_frozen
284
- # This is not an airtight solution. Object#dup does not copy methods
285
- # defined on the instance, and may be overridden by subclasses to do
286
- # things that would cause problems for us. But most likely there is no
287
- # problem with using dup. We can't use Object#clone because the clone
288
- # retains the frozen status of the original, preventing us from
289
- # modifying the string contents.
290
- rendered = rendered.dup
291
- end
292
-
293
- rendered.gsub! ENCODED_IMMUNIO_TOKENS_RE, "{immunio-\\1:\\2:\\3}\\4{/immunio-\\1:\\2:\\3}"
294
-
295
- rendered.instance_variable_set(:@html_safe, true) if was_html_safe
296
- rendered.freeze if was_frozen
297
- end
298
-
299
- rendered
300
- end
301
-
302
- def self.render_var(code, rendered, template_id, template_sha, file, line, escape, is_text, handler)
303
- rendered = decode_immunio_tokens rendered
304
-
305
- if rendered.instance_variable_get("@__immunio_processed") then
306
- # Ignore buffers marked as __immunio_processed in render as these are full templates or partials
307
- return rendered
308
- elsif code =~ /yield( .*)?/
309
- # Ignore yielded blocks inside layouts
310
- return rendered
311
- end
312
- rendered = mark_var rendered, code, template_id, template_sha, file, line, escape, is_text, handler
313
- rendered.html_safe
314
- end
315
-
316
- def self.current
317
- rendering_stack.last
318
- end
319
-
320
- def self.next_var_id
321
- rendering_stack.first.next_var_id
322
- end
323
-
324
- def self.vars
325
- rendering_stack.first.vars
326
- end
327
-
328
- def self.get_nonce
329
- rendering_stack.first.get_nonce
330
- end
331
-
332
- # Save fragment info to the root template only
333
- def self.mark_and_defer_fragment_write(*args)
334
- rendering_stack.first.mark_and_defer_fragment_write(*args)
335
- end
336
-
337
- # Stack of the templates currently being rendered.
338
- def self.rendering_stack
339
- Thread.current["immunio.rendering_stack"] ||= []
340
- end
341
-
342
- def self.wrap_code(code, handler, options = {})
343
- case
344
- when handler == 'ActionView::Template::Handlers::ERB'
345
- modifier = options[:escape] ? '=' : '=='
346
- "<%#{modifier} #{code} %>"
347
- when handler == 'Haml::Plugin'
348
- modifier = options[:escape] ? '=' : '!='
349
- "#{modifier} #{code}"
350
- end
351
- end
352
-
353
- private
354
-
355
- def rendering_stack
356
- self.class.rendering_stack
357
- end
358
-
359
- def run_hook!(name, meta={})
360
- default_meta = {
361
- template_sha: template_sha,
362
- name: (@template.respond_to?(:virtual_path) && @template.virtual_path) || nil,
363
- origin: @template.identifier,
364
- nonce: Template.get_nonce
365
- }
366
- Immunio.run_hook! "action_view", name, default_meta.merge(meta)
367
- end
368
-
369
- def write_and_remove_fragments!(context, content)
370
- # Rails tests do use the context as the view context sometimes.
371
- if context.is_a? ActionController::Base
372
- controller = context
373
- elsif context.respond_to? :controller
374
- controller = context.controller
375
- else
376
- # Some rails unit tests don't have a controller...
377
- remove_all_markers! content
378
- return
379
- end
380
-
381
- # Iterate to handle nested fragments. Child fragments have lower ids than their parents.
382
- nonce = Template.get_nonce
383
- @scheduled_fragments_writes.each_with_index do |(key, _, options), id|
384
- # Remove the markers ...
385
- content.sub!(/\{immunio-fragment:#{id}:#{nonce}\}(.*)\{\/immunio-fragment:#{id}:#{nonce}\}/m) do
386
- # The escaped content inside the markers ($1), is written to cache.
387
- output = $1
388
- remove_all_markers! output
389
- controller.write_fragment_without_immunio key, output, options
390
- output
391
- end
392
- end
393
- # To be extra safe strip all markers from content
394
- remove_all_markers! content
395
- end
396
-
397
- def remove_var_markers!(input)
398
- nonce = Template.get_nonce
399
- # TODO is this the fastest way to remove the markers? Needs benchmarking ...
400
- input.gsub!(/\{\/?immunio-var:\d+:#{nonce}\}/, "")
401
- end
402
-
403
- def remove_all_markers!(input)
404
- self.class.remove_all_markers!(input)
405
- end
406
-
407
- class << self
408
- def remove_all_markers!(input)
409
- input.gsub!(/\{\/?immunio-(fragment|var):\d+:[a-zA-Z0-9]+\}/, "")
410
- end
411
- end
412
- end
413
-
414
- # Hooks for the ERB template engine.
415
- # (Default one used in Rails < 5).
416
- module ErubisHooks
417
- extend ActiveSupport::Concern
418
-
419
- included do
420
- Immunio::Utils.alias_method_chain self, :add_expr, :immunio
421
- end
422
-
423
- def add_expr_with_immunio(src, code, indicator)
424
- # Wrap expressions in the templates to track their rendered value.
425
- # Do not wrap expressions with blocks, eg.: <%= form_tag do %>
426
- # TODO should we support blocks?
427
- Request.time "plugin", "#{Module.nesting[0]}::#{__method__}" do
428
- unless code =~ ActionView::Template::Handlers::Erubis::BLOCK_EXPR
429
- # escape unless we see the == indicator
430
- escape = !(indicator == '==')
431
- code = Immunio::Template.generate_render_var_code(code, escape)
432
- end
433
- Request.pause "plugin", "#{Module.nesting[0]}::#{__method__}" do
434
- add_expr_without_immunio(src, code, indicator)
435
- end
436
- end
437
- end
438
- end
439
-
440
- module ErubiHooks
441
- extend ActiveSupport::Concern
442
-
443
- included do
444
- Immunio::Utils.alias_method_chain self, :add_expression, :immunio
445
- end
446
-
447
- def add_expression_with_immunio(indicator, code)
448
- # Wrap expressions in the templates to track their rendered value.
449
- # Do not wrap expressions with blocks, eg.: <%= form_tag do %>
450
- # TODO should we support blocks?
451
- Request.time "plugin", "#{Module.nesting[0]}::#{__method__}" do
452
- unless code =~ ActionView::Template::Handlers::ERB::Erubi::BLOCK_EXPR
453
- # escape unless we see the == indicator
454
- escape = !(indicator == '==')
455
- code = Immunio::Template.generate_render_var_code(code, escape)
456
- end
457
- Request.pause "plugin", "#{Module.nesting[0]}::#{__method__}" do
458
- add_expression_without_immunio(indicator, code)
459
- end
460
- end
461
- end
462
- end
463
-
464
- # Hooks for the HAML template engine.
465
- module HamlHooks
466
- extend ActiveSupport::Concern
467
-
468
- included do
469
- Immunio::Utils.alias_method_chain self, :push_script, :immunio
470
- end
471
-
472
- def push_script_with_immunio(code, opts = {}, &block)
473
- # Wrap expressions in the templates to track their rendered value.
474
- Request.time "plugin", "#{Module.nesting[0]}::#{__method__}" do
475
- block_expr = if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR > 0
476
- ActionView::Template::Handlers::ERB::Erubi::BLOCK_EXPR
477
- else
478
- ActionView::Template::Handlers::Erubis::BLOCK_EXPR
479
- end
480
-
481
- if code !~ block_expr
482
- # escape if we're told to by HAML
483
- code = Immunio::Template.generate_render_var_code(code, opts[:escape_html])
484
- end
485
- Request.pause "plugin", "#{Module.nesting[0]}::#{__method__}" do
486
- push_script_without_immunio(code, opts, &block)
487
- end
488
- end
489
- end
490
- end
491
-
492
- # Hook for the `ActionView::TemplateRenderer`. These are called for root
493
- # templates.
494
- module TemplateRendererHooks
495
- extend ActiveSupport::Concern
496
-
497
- included do
498
- Immunio::Utils.alias_method_chain self, :render_template, :immunio
499
- end
500
-
501
- def render_template_with_immunio(template, *args)
502
- Request.time "plugin", "#{Module.nesting[0]}::#{__method__}" do
503
- renderer = Template.new(template)
504
-
505
- renderer.render @view do
506
- Request.pause "plugin", "#{Module.nesting[0]}::#{__method__}" do
507
- render_template_without_immunio(template, *args)
508
- end
509
- end
510
- end
511
- end
512
- end
513
-
514
- # Hook for the `ActionView::Template`. These are called for non-root
515
- # templates.
516
- module TemplateHooks
517
- extend ActiveSupport::Concern
518
-
519
- included do
520
- Immunio::Utils.alias_method_chain self, :render, :immunio
521
- end
522
-
523
- def render_with_immunio(context, *args, &block)
524
- Request.time "plugin", "#{Module.nesting[0]}::#{__method__}" do
525
- renderer = Template.new(self)
526
-
527
- renderer.render context do
528
- Request.pause "plugin", "#{Module.nesting[0]}::#{__method__}" do
529
- render_without_immunio(context, *args, &block)
530
- end
531
- end
532
- end
533
- end
534
- end
535
-
536
- # Hook for `ActionController::Caching::Fragments` responsible for handling the `<% cache do %>...` in templates.
537
- module FragmentCachingHooks
538
- extend ActiveSupport::Concern
539
-
540
- included do
541
- Immunio::Utils.alias_method_chain self, :write_fragment, :immunio
542
- end
543
-
544
- def write_fragment_with_immunio(key, content, options = nil)
545
- return content unless cache_configured?
546
-
547
- template = Template.current
548
- if template
549
- # We're rendering a template. Defer caching 'till we get the escaped content from the hook handler.
550
- content = Template.mark_and_defer_fragment_write(key, content, options)
551
- else
552
- # Not rendering a template. Ignore.
553
- # Shouldn't happen. But, just to be safe in case fragment caching is used in the controller for something else.
554
- content = write_fragment_without_immunio(key, content, options)
555
- end
556
-
557
- content
558
- end
559
- end
560
-
561
- module CacheStoreHooks
562
- extend ActiveSupport::Concern
563
-
564
- included do
565
- Immunio::Utils.alias_method_chain self, :write, :immunio
566
- end
567
-
568
- # Rails 5 adds CollectionCaching. When used in the context of
569
- # rendering a collection of items with a partial template, we
570
- # need to remove our markers before writing to the cache store.
571
- # See this blog post for more:
572
- # http://blog.bigbinary.com/2016/03/09/rails-5-makes-partial-redering-from-cache-substantially-faster.html
573
- def write_with_immunio(name, value, options = nil)
574
- Request.time "plugin", "#{Module.nesting[0]}::#{__method__}" do
575
- Template.remove_all_markers! value if value.is_a? String
576
-
577
- Request.pause "plugin", "#{Module.nesting[0]}::#{__method__}" do
578
- write_without_immunio(name, value, options)
579
- end
580
- end
581
- end
582
- end
583
-
584
- # Hook for the `ActiveSupport::Hash#to_query`.
585
- # Use case: building a url within a decorator that renders a partial with an interpolation.
586
- module ActiveSupportHooks
587
- extend ActiveSupport::Concern
588
-
589
- included do
590
- Immunio::Utils.alias_method_chain self, :to_query, :immunio
591
- end
592
-
593
- def to_query_with_immunio(namespace = nil)
594
- escaped_string = to_query_without_immunio(namespace)
595
- Request.time "plugin", "#{Module.nesting[0]}::#{__method__}" do
596
- # Our markers got escaped, so un-unescaped them back.
597
- escaped_string.gsub!(
598
- Immunio::Template::ENCODED_IMMUNIO_TOKENS_RE,
599
- "{immunio-\\1:\\2:\\3}\\4{/immunio-\\1:\\2:\\3}")
600
- end
601
- escaped_string
602
- end
603
- end
604
-
605
- XSS_HOOKS = %w[template_render_done template_render_var]
606
- end
607
-
608
- # Load the plugins
609
-
610
- if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR > 0
611
- Immunio::Plugin.load(
612
- 'Erubi',
613
- feature: 'xss',
614
- hooks: Immunio::XSS_HOOKS) do |plugin|
615
-
616
- ActionView::Template::Handlers::ERB::Erubi.send :include, Immunio::ErubiHooks
617
-
618
- plugin.loaded! Rails.version
619
- end
620
- else
621
- Immunio::Plugin.load(
622
- 'Erubis',
623
- feature: 'xss',
624
- hooks: Immunio::XSS_HOOKS) do |plugin|
625
-
626
- ActionView::Template::Handlers::Erubis.send :include, Immunio::ErubisHooks
627
-
628
- plugin.loaded! Rails.version
629
- end
630
- end
631
-
632
- ActiveSupport.on_load(:after_initialize) do
633
- # Wait after Rails initialization to patch custom template engines.
634
- Immunio::Plugin.load(
635
- 'Haml',
636
- feature: 'xss',
637
- hooks: Immunio::XSS_HOOKS) do |plugin|
638
-
639
- if defined? Haml::Compiler
640
- Haml::Compiler.send :include, Immunio::HamlHooks
641
- plugin.loaded! Haml::VERSION
642
- end
643
- end
644
-
645
- # Wait for ActiveSupport core ext to load
646
- Hash.send :include, Immunio::ActiveSupportHooks
647
- end
648
-
649
- # Hook into rendering process of Rails.
650
- Immunio::Plugin.load(
651
- 'ActionView',
652
- feature: 'xss',
653
- hooks: Immunio::XSS_HOOKS) do |plugin|
654
-
655
- ActionView::TemplateRenderer.send :include, Immunio::TemplateRendererHooks
656
- ActionView::Template.send :include, Immunio::TemplateHooks
657
-
658
- if Rails::VERSION::MAJOR < 5
659
- ActionController::Caching::Fragments.send(
660
- :include,
661
- Immunio::FragmentCachingHooks)
662
- else
663
- AbstractController::Caching.send(:include, Immunio::FragmentCachingHooks)
664
- ActiveSupport::Cache::Store.send(:include, Immunio::CacheStoreHooks)
665
- end
666
-
667
- plugin.loaded! Rails.version
668
- end
1
+ require_relative 'action_view/template'
2
+ require_relative 'action_view/action_view'
3
+ require_relative 'action_view/active_support_hash'
4
+ require_relative 'action_view/erubi'
5
+ require_relative 'action_view/erubis'
6
+ require_relative 'action_view/haml'
7
+ require_relative 'action_view/slim'