contrast-agent 3.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.clang-format +5 -0
- data/.dockerignore +10 -0
- data/.gitignore +58 -0
- data/.gitmodules +6 -0
- data/.rspec +6 -0
- data/.simplecov +4 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +12 -0
- data/Rakefile +15 -0
- data/exe/contrast_service +29 -0
- data/ext/build_funchook.rb +48 -0
- data/ext/cs__assess_active_record_named/cs__active_record_named.c +47 -0
- data/ext/cs__assess_active_record_named/cs__active_record_named.h +10 -0
- data/ext/cs__assess_active_record_named/extconf.rb +2 -0
- data/ext/cs__assess_array/cs__assess_array.c +38 -0
- data/ext/cs__assess_array/cs__assess_array.h +9 -0
- data/ext/cs__assess_array/extconf.rb +2 -0
- data/ext/cs__assess_basic_object/cs__assess_basic_object.c +50 -0
- data/ext/cs__assess_basic_object/cs__assess_basic_object.h +17 -0
- data/ext/cs__assess_basic_object/extconf.rb +2 -0
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +86 -0
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.h +34 -0
- data/ext/cs__assess_fiber_track/extconf.rb +2 -0
- data/ext/cs__assess_hash/cs__assess_hash.c +64 -0
- data/ext/cs__assess_hash/cs__assess_hash.h +24 -0
- data/ext/cs__assess_hash/extconf.rb +2 -0
- data/ext/cs__assess_kernel/cs__assess_kernel.c +36 -0
- data/ext/cs__assess_kernel/cs__assess_kernel.h +10 -0
- data/ext/cs__assess_kernel/extconf.rb +2 -0
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +47 -0
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.h +18 -0
- data/ext/cs__assess_marshal_module/extconf.rb +2 -0
- data/ext/cs__assess_module/cs__assess_module.c +78 -0
- data/ext/cs__assess_module/cs__assess_module.h +25 -0
- data/ext/cs__assess_module/extconf.rb +2 -0
- data/ext/cs__assess_regexp/cs__assess_regexp.c +48 -0
- data/ext/cs__assess_regexp/cs__assess_regexp.h +22 -0
- data/ext/cs__assess_regexp/extconf.rb +2 -0
- data/ext/cs__assess_regexp_track/cs__assess_regexp_track.c +63 -0
- data/ext/cs__assess_regexp_track/cs__assess_regexp_track.h +29 -0
- data/ext/cs__assess_regexp_track/extconf.rb +2 -0
- data/ext/cs__assess_string/cs__assess_string.c +38 -0
- data/ext/cs__assess_string/cs__assess_string.h +19 -0
- data/ext/cs__assess_string/extconf.rb +2 -0
- data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +31 -0
- data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.h +13 -0
- data/ext/cs__assess_string_interpolation26/extconf.rb +2 -0
- data/ext/cs__common/cs__common.c +60 -0
- data/ext/cs__common/cs__common.h +28 -0
- data/ext/cs__common/extconf.rb +20 -0
- data/ext/cs__contrast_patch/cs__contrast_patch.c +445 -0
- data/ext/cs__contrast_patch/cs__contrast_patch.h +196 -0
- data/ext/cs__contrast_patch/extconf.rb +2 -0
- data/ext/cs__protect_kernel/cs__protect_kernel.c +37 -0
- data/ext/cs__protect_kernel/cs__protect_kernel.h +11 -0
- data/ext/cs__protect_kernel/extconf.rb +2 -0
- data/ext/cs__scope/cs__scope.c +96 -0
- data/ext/cs__scope/cs__scope.h +33 -0
- data/ext/cs__scope/extconf.rb +2 -0
- data/ext/extconf_common.rb +49 -0
- data/funchook/LICENSE +360 -0
- data/funchook/Makefile +29 -0
- data/funchook/Makefile.in +29 -0
- data/funchook/README.md +121 -0
- data/funchook/appveyor.yml +42 -0
- data/funchook/autogen.sh +3 -0
- data/funchook/autom4te.cache/output.0 +4976 -0
- data/funchook/autom4te.cache/requests +78 -0
- data/funchook/autom4te.cache/traces.0 +364 -0
- data/funchook/config.guess +1530 -0
- data/funchook/config.log +490 -0
- data/funchook/config.status +1016 -0
- data/funchook/config.sub +1773 -0
- data/funchook/configure +4976 -0
- data/funchook/configure.ac +59 -0
- data/funchook/distorm/COPYING +26 -0
- data/funchook/distorm/MANIFEST +25 -0
- data/funchook/distorm/MANIFEST.in +4 -0
- data/funchook/distorm/README.md +12 -0
- data/funchook/distorm/disOps/disOps.py +795 -0
- data/funchook/distorm/disOps/x86db.py +404 -0
- data/funchook/distorm/disOps/x86header.py +247 -0
- data/funchook/distorm/disOps/x86sets.py +1664 -0
- data/funchook/distorm/examples/cs/TestdiStorm/Program.cs +79 -0
- data/funchook/distorm/examples/cs/TestdiStorm/Properties/AssemblyInfo.cs +36 -0
- data/funchook/distorm/examples/cs/TestdiStorm/TestdiStorm.csproj +69 -0
- data/funchook/distorm/examples/cs/distorm-net.sln +26 -0
- data/funchook/distorm/examples/cs/distorm-net/CodeInfo.cs +23 -0
- data/funchook/distorm/examples/cs/distorm-net/DecodedInst.cs +15 -0
- data/funchook/distorm/examples/cs/distorm-net/DecodedResult.cs +14 -0
- data/funchook/distorm/examples/cs/distorm-net/DecomposedInst.cs +36 -0
- data/funchook/distorm/examples/cs/distorm-net/DecomposedResult.cs +14 -0
- data/funchook/distorm/examples/cs/distorm-net/Opcodes.cs +1268 -0
- data/funchook/distorm/examples/cs/distorm-net/Opcodes.tt +37 -0
- data/funchook/distorm/examples/cs/distorm-net/Operand.cs +25 -0
- data/funchook/distorm/examples/cs/distorm-net/Properties/AssemblyInfo.cs +36 -0
- data/funchook/distorm/examples/cs/distorm-net/diStorm3.cs +411 -0
- data/funchook/distorm/examples/cs/distorm-net/distorm-net.csproj +80 -0
- data/funchook/distorm/examples/cs/readme +3 -0
- data/funchook/distorm/examples/ddk/README +48 -0
- data/funchook/distorm/examples/ddk/distorm.ini +11 -0
- data/funchook/distorm/examples/ddk/dummy.c +15 -0
- data/funchook/distorm/examples/ddk/main.c +91 -0
- data/funchook/distorm/examples/ddk/makefile +1 -0
- data/funchook/distorm/examples/ddk/sources +10 -0
- data/funchook/distorm/examples/java/Makefile +23 -0
- data/funchook/distorm/examples/java/distorm/src/Main.java +43 -0
- data/funchook/distorm/examples/java/distorm/src/diStorm3/CodeInfo.java +27 -0
- data/funchook/distorm/examples/java/distorm/src/diStorm3/DecodedInst.java +32 -0
- data/funchook/distorm/examples/java/distorm/src/diStorm3/DecodedResult.java +11 -0
- data/funchook/distorm/examples/java/distorm/src/diStorm3/DecomposedInst.java +89 -0
- data/funchook/distorm/examples/java/distorm/src/diStorm3/DecomposedResult.java +11 -0
- data/funchook/distorm/examples/java/distorm/src/diStorm3/OpcodeEnum.java +131 -0
- data/funchook/distorm/examples/java/distorm/src/diStorm3/Opcodes.java +1123 -0
- data/funchook/distorm/examples/java/distorm/src/diStorm3/Operand.java +24 -0
- data/funchook/distorm/examples/java/distorm/src/diStorm3/distorm3.java +41 -0
- data/funchook/distorm/examples/java/jdistorm.c +405 -0
- data/funchook/distorm/examples/java/jdistorm.h +40 -0
- data/funchook/distorm/examples/java/jdistorm.sln +20 -0
- data/funchook/distorm/examples/java/jdistorm.vcproj +208 -0
- data/funchook/distorm/examples/linux/Makefile +15 -0
- data/funchook/distorm/examples/linux/main.c +181 -0
- data/funchook/distorm/examples/tests/Makefile +15 -0
- data/funchook/distorm/examples/tests/main.cpp +42 -0
- data/funchook/distorm/examples/tests/main.py +66 -0
- data/funchook/distorm/examples/tests/test_distorm3.py +1672 -0
- data/funchook/distorm/examples/tests/tests.sln +20 -0
- data/funchook/distorm/examples/tests/tests.vcxproj +82 -0
- data/funchook/distorm/examples/tests/tests.vcxproj.filters +22 -0
- data/funchook/distorm/examples/win32/disasm.sln +25 -0
- data/funchook/distorm/examples/win32/disasm.vcxproj +201 -0
- data/funchook/distorm/examples/win32/disasm.vcxproj.filters +14 -0
- data/funchook/distorm/examples/win32/main.cpp +163 -0
- data/funchook/distorm/include/distorm.h +482 -0
- data/funchook/distorm/include/mnemonics.h +301 -0
- data/funchook/distorm/make/linux/Makefile +28 -0
- data/funchook/distorm/make/mac/Makefile +24 -0
- data/funchook/distorm/make/win32/cdistorm.vcxproj +239 -0
- data/funchook/distorm/make/win32/cdistorm.vcxproj.filters +80 -0
- data/funchook/distorm/make/win32/distorm.sln +25 -0
- data/funchook/distorm/make/win32/resource.h +14 -0
- data/funchook/distorm/make/win32/resource.rc +99 -0
- data/funchook/distorm/python/distorm3/__init__.py +957 -0
- data/funchook/distorm/python/distorm3/sample.py +51 -0
- data/funchook/distorm/setup.cfg +10 -0
- data/funchook/distorm/setup.py +266 -0
- data/funchook/distorm/src/config.h +169 -0
- data/funchook/distorm/src/decoder.c +641 -0
- data/funchook/distorm/src/decoder.h +33 -0
- data/funchook/distorm/src/distorm.c +413 -0
- data/funchook/distorm/src/instructions.c +597 -0
- data/funchook/distorm/src/instructions.h +463 -0
- data/funchook/distorm/src/insts.c +7939 -0
- data/funchook/distorm/src/insts.h +64 -0
- data/funchook/distorm/src/mnemonics.c +284 -0
- data/funchook/distorm/src/operands.c +1290 -0
- data/funchook/distorm/src/operands.h +28 -0
- data/funchook/distorm/src/prefix.c +368 -0
- data/funchook/distorm/src/prefix.h +64 -0
- data/funchook/distorm/src/textdefs.c +172 -0
- data/funchook/distorm/src/textdefs.h +57 -0
- data/funchook/distorm/src/wstring.c +47 -0
- data/funchook/distorm/src/wstring.h +35 -0
- data/funchook/distorm/src/x86defs.h +82 -0
- data/funchook/include/funchook.h +123 -0
- data/funchook/install-sh +527 -0
- data/funchook/src/Makefile +70 -0
- data/funchook/src/Makefile.in +70 -0
- data/funchook/src/__strerror.h +109 -0
- data/funchook/src/config.h +101 -0
- data/funchook/src/config.h.in +100 -0
- data/funchook/src/decoder.o +0 -0
- data/funchook/src/distorm.o +0 -0
- data/funchook/src/funchook.c +440 -0
- data/funchook/src/funchook.o +0 -0
- data/funchook/src/funchook_internal.h +155 -0
- data/funchook/src/funchook_io.c +182 -0
- data/funchook/src/funchook_io.h +64 -0
- data/funchook/src/funchook_io.o +0 -0
- data/funchook/src/funchook_syscall.S +134 -0
- data/funchook/src/funchook_syscall.o +0 -0
- data/funchook/src/funchook_unix.c +480 -0
- data/funchook/src/funchook_unix.o +0 -0
- data/funchook/src/funchook_windows.c +397 -0
- data/funchook/src/funchook_x86.c +622 -0
- data/funchook/src/funchook_x86.o +0 -0
- data/funchook/src/instructions.o +0 -0
- data/funchook/src/insts.o +0 -0
- data/funchook/src/libfunchook.so +0 -0
- data/funchook/src/mnemonics.o +0 -0
- data/funchook/src/operands.o +0 -0
- data/funchook/src/os_func.c +115 -0
- data/funchook/src/os_func.h +75 -0
- data/funchook/src/os_func.o +0 -0
- data/funchook/src/os_func_unix.c +94 -0
- data/funchook/src/os_func_unix.o +0 -0
- data/funchook/src/os_func_windows.c +32 -0
- data/funchook/src/prefix.o +0 -0
- data/funchook/src/printf_base.c +1688 -0
- data/funchook/src/printf_base.h +46 -0
- data/funchook/src/printf_base.o +0 -0
- data/funchook/src/textdefs.o +0 -0
- data/funchook/src/wstring.o +0 -0
- data/funchook/test/Makefile +43 -0
- data/funchook/test/Makefile.in +43 -0
- data/funchook/test/funchook_test +0 -0
- data/funchook/test/libfunchook_test.c +25 -0
- data/funchook/test/libfunchook_test.so +0 -0
- data/funchook/test/libfunchook_test2.c +18 -0
- data/funchook/test/suffix.list +600 -0
- data/funchook/test/test_main.c +430 -0
- data/funchook/test/test_main.o +0 -0
- data/funchook/test/x86_64_test.S +10 -0
- data/funchook/test/x86_64_test.o +0 -0
- data/funchook/test/x86_test.S +339 -0
- data/funchook/win32/config.h +1 -0
- data/funchook/win32/funchook.sln +52 -0
- data/funchook/win32/funchook.vcxproj +188 -0
- data/funchook/win32/funchook.vcxproj.filters +84 -0
- data/funchook/win32/funchook_test.vcxproj +170 -0
- data/funchook/win32/funchook_test.vcxproj.filters +22 -0
- data/funchook/win32/funchook_test_dll.vcxproj +184 -0
- data/funchook/win32/funchook_test_dll.vcxproj.filters +30 -0
- data/funchook/win32/funchook_test_exe.def +3 -0
- data/lib/contrast-agent.rb +8 -0
- data/lib/contrast.rb +57 -0
- data/lib/contrast/agent.rb +80 -0
- data/lib/contrast/agent/assess.rb +45 -0
- data/lib/contrast/agent/assess/adjusted_span.rb +25 -0
- data/lib/contrast/agent/assess/class_reverter.rb +82 -0
- data/lib/contrast/agent/assess/contrast_event.rb +398 -0
- data/lib/contrast/agent/assess/frozen_properties.rb +41 -0
- data/lib/contrast/agent/assess/insulator.rb +53 -0
- data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +78 -0
- data/lib/contrast/agent/assess/policy/patcher.rb +85 -0
- data/lib/contrast/agent/assess/policy/policy.rb +116 -0
- data/lib/contrast/agent/assess/policy/policy_node.rb +289 -0
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +44 -0
- data/lib/contrast/agent/assess/policy/preshift.rb +94 -0
- data/lib/contrast/agent/assess/policy/propagation_method.rb +260 -0
- data/lib/contrast/agent/assess/policy/propagation_node.rb +127 -0
- data/lib/contrast/agent/assess/policy/propagator.rb +35 -0
- data/lib/contrast/agent/assess/policy/propagator/append.rb +54 -0
- data/lib/contrast/agent/assess/policy/propagator/base.rb +37 -0
- data/lib/contrast/agent/assess/policy/propagator/center.rb +73 -0
- data/lib/contrast/agent/assess/policy/propagator/custom.rb +36 -0
- data/lib/contrast/agent/assess/policy/propagator/database_write.rb +62 -0
- data/lib/contrast/agent/assess/policy/propagator/insert.rb +55 -0
- data/lib/contrast/agent/assess/policy/propagator/keep.rb +26 -0
- data/lib/contrast/agent/assess/policy/propagator/next.rb +42 -0
- data/lib/contrast/agent/assess/policy/propagator/prepend.rb +50 -0
- data/lib/contrast/agent/assess/policy/propagator/remove.rb +76 -0
- data/lib/contrast/agent/assess/policy/propagator/replace.rb +27 -0
- data/lib/contrast/agent/assess/policy/propagator/reverse.rb +38 -0
- data/lib/contrast/agent/assess/policy/propagator/select.rb +86 -0
- data/lib/contrast/agent/assess/policy/propagator/splat.rb +60 -0
- data/lib/contrast/agent/assess/policy/propagator/split.rb +49 -0
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +169 -0
- data/lib/contrast/agent/assess/policy/propagator/trim.rb +81 -0
- data/lib/contrast/agent/assess/policy/rewriter_patch.rb +79 -0
- data/lib/contrast/agent/assess/policy/source_method.rb +209 -0
- data/lib/contrast/agent/assess/policy/source_node.rb +62 -0
- data/lib/contrast/agent/assess/policy/trigger_method.rb +209 -0
- data/lib/contrast/agent/assess/policy/trigger_node.rb +198 -0
- data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +77 -0
- data/lib/contrast/agent/assess/policy/trigger_validation/trigger_validation.rb +31 -0
- data/lib/contrast/agent/assess/policy/trigger_validation/xss_validator.rb +40 -0
- data/lib/contrast/agent/assess/properties.rb +392 -0
- data/lib/contrast/agent/assess/rule.rb +18 -0
- data/lib/contrast/agent/assess/rule/base.rb +72 -0
- data/lib/contrast/agent/assess/rule/csrf.rb +66 -0
- data/lib/contrast/agent/assess/rule/csrf/csrf_action.rb +28 -0
- data/lib/contrast/agent/assess/rule/csrf/csrf_applicator.rb +69 -0
- data/lib/contrast/agent/assess/rule/csrf/csrf_watcher.rb +132 -0
- data/lib/contrast/agent/assess/rule/provider.rb +21 -0
- data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +62 -0
- data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +73 -0
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +121 -0
- data/lib/contrast/agent/assess/rule/redos.rb +68 -0
- data/lib/contrast/agent/assess/rule/response_scanning_rule.rb +47 -0
- data/lib/contrast/agent/assess/rule/response_watcher.rb +36 -0
- data/lib/contrast/agent/assess/rule/watcher.rb +36 -0
- data/lib/contrast/agent/assess/tag.rb +151 -0
- data/lib/contrast/agent/at_exit_hook.rb +33 -0
- data/lib/contrast/agent/class_reopener.rb +195 -0
- data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +26 -0
- data/lib/contrast/agent/deadzone/policy/policy.rb +57 -0
- data/lib/contrast/agent/disable_reaction.rb +24 -0
- data/lib/contrast/agent/exclusion_matcher.rb +190 -0
- data/lib/contrast/agent/feature_state.rb +379 -0
- data/lib/contrast/agent/inventory/policy/policy.rb +32 -0
- data/lib/contrast/agent/inventory/policy/trigger_node.rb +22 -0
- data/lib/contrast/agent/logger_manager.rb +116 -0
- data/lib/contrast/agent/middleware.rb +352 -0
- data/lib/contrast/agent/module_data.rb +16 -0
- data/lib/contrast/agent/patching/policy/after_load_patch.rb +37 -0
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +58 -0
- data/lib/contrast/agent/patching/policy/method_policy.rb +94 -0
- data/lib/contrast/agent/patching/policy/module_policy.rb +116 -0
- data/lib/contrast/agent/patching/policy/patch.rb +312 -0
- data/lib/contrast/agent/patching/policy/patch_status.rb +192 -0
- data/lib/contrast/agent/patching/policy/patcher.rb +310 -0
- data/lib/contrast/agent/patching/policy/policy.rb +138 -0
- data/lib/contrast/agent/patching/policy/policy_node.rb +80 -0
- data/lib/contrast/agent/patching/policy/policy_unpatcher.rb +28 -0
- data/lib/contrast/agent/patching/policy/trigger_node.rb +81 -0
- data/lib/contrast/agent/protect/policy/policy.rb +37 -0
- data/lib/contrast/agent/protect/policy/trigger_node.rb +23 -0
- data/lib/contrast/agent/protect/rule.rb +58 -0
- data/lib/contrast/agent/protect/rule/base.rb +300 -0
- data/lib/contrast/agent/protect/rule/base_service.rb +88 -0
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +156 -0
- data/lib/contrast/agent/protect/rule/csrf.rb +118 -0
- data/lib/contrast/agent/protect/rule/csrf/csrf_evaluator.rb +103 -0
- data/lib/contrast/agent/protect/rule/csrf/csrf_token_injector.rb +85 -0
- data/lib/contrast/agent/protect/rule/default_scanner.rb +300 -0
- data/lib/contrast/agent/protect/rule/deserialization.rb +193 -0
- data/lib/contrast/agent/protect/rule/http_method_tampering.rb +80 -0
- data/lib/contrast/agent/protect/rule/no_sqli.rb +101 -0
- data/lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb +40 -0
- data/lib/contrast/agent/protect/rule/path_traversal.rb +143 -0
- data/lib/contrast/agent/protect/rule/sqli.rb +101 -0
- data/lib/contrast/agent/protect/rule/sqli/default_sql_scanner.rb +16 -0
- data/lib/contrast/agent/protect/rule/sqli/mysql_sql_scanner.rb +38 -0
- data/lib/contrast/agent/protect/rule/sqli/postgres_sql_scanner.rb +22 -0
- data/lib/contrast/agent/protect/rule/sqli/sqlite_sql_scanner.rb +19 -0
- data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +20 -0
- data/lib/contrast/agent/protect/rule/xss.rb +24 -0
- data/lib/contrast/agent/protect/rule/xxe.rb +120 -0
- data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +82 -0
- data/lib/contrast/agent/railtie.rb +30 -0
- data/lib/contrast/agent/reaction_processor.rb +47 -0
- data/lib/contrast/agent/request.rb +493 -0
- data/lib/contrast/agent/request_context.rb +225 -0
- data/lib/contrast/agent/require_state.rb +61 -0
- data/lib/contrast/agent/response.rb +215 -0
- data/lib/contrast/agent/rewriter.rb +244 -0
- data/lib/contrast/agent/scope.rb +28 -0
- data/lib/contrast/agent/service_heartbeat.rb +37 -0
- data/lib/contrast/agent/settings_state.rb +148 -0
- data/lib/contrast/agent/socket_client.rb +125 -0
- data/lib/contrast/agent/thread.rb +26 -0
- data/lib/contrast/agent/tracepoint_hook.rb +51 -0
- data/lib/contrast/agent/version.rb +8 -0
- data/lib/contrast/api.rb +17 -0
- data/lib/contrast/api/.gitkeep +0 -0
- data/lib/contrast/api/connection_status.rb +49 -0
- data/lib/contrast/api/socket.rb +43 -0
- data/lib/contrast/api/speedracer.rb +206 -0
- data/lib/contrast/api/tcp_socket.rb +31 -0
- data/lib/contrast/api/unix_socket.rb +25 -0
- data/lib/contrast/common_agent_configuration.rb +86 -0
- data/lib/contrast/components/agent.rb +85 -0
- data/lib/contrast/components/app_context.rb +188 -0
- data/lib/contrast/components/assess.rb +67 -0
- data/lib/contrast/components/config.rb +135 -0
- data/lib/contrast/components/contrast_service.rb +113 -0
- data/lib/contrast/components/heap_dump.rb +34 -0
- data/lib/contrast/components/interface.rb +178 -0
- data/lib/contrast/components/inventory.rb +23 -0
- data/lib/contrast/components/logger.rb +92 -0
- data/lib/contrast/components/protect.rb +38 -0
- data/lib/contrast/components/sampling.rb +41 -0
- data/lib/contrast/components/scope.rb +106 -0
- data/lib/contrast/components/settings.rb +140 -0
- data/lib/contrast/config.rb +33 -0
- data/lib/contrast/config/agent_configuration.rb +24 -0
- data/lib/contrast/config/application_configuration.rb +27 -0
- data/lib/contrast/config/assess_configuration.rb +22 -0
- data/lib/contrast/config/assess_rules_configuration.rb +18 -0
- data/lib/contrast/config/base_configuration.rb +105 -0
- data/lib/contrast/config/default_value.rb +16 -0
- data/lib/contrast/config/exception_configuration.rb +21 -0
- data/lib/contrast/config/heap_dump_configuration.rb +23 -0
- data/lib/contrast/config/inventory_configuration.rb +20 -0
- data/lib/contrast/config/logger_configuration.rb +20 -0
- data/lib/contrast/config/protect_configuration.rb +20 -0
- data/lib/contrast/config/protect_rule_configuration.rb +37 -0
- data/lib/contrast/config/protect_rules_configuration.rb +30 -0
- data/lib/contrast/config/root_configuration.rb +26 -0
- data/lib/contrast/config/ruby_configuration.rb +39 -0
- data/lib/contrast/config/sampling_configuration.rb +22 -0
- data/lib/contrast/config/server_configuration.rb +23 -0
- data/lib/contrast/config/service_configuration.rb +22 -0
- data/lib/contrast/configuration.rb +214 -0
- data/lib/contrast/core_extensions/assess.rb +51 -0
- data/lib/contrast/core_extensions/assess/array.rb +58 -0
- data/lib/contrast/core_extensions/assess/assess_extension.rb +145 -0
- data/lib/contrast/core_extensions/assess/basic_object.rb +15 -0
- data/lib/contrast/core_extensions/assess/erb.rb +42 -0
- data/lib/contrast/core_extensions/assess/exec_trigger.rb +48 -0
- data/lib/contrast/core_extensions/assess/fiber.rb +125 -0
- data/lib/contrast/core_extensions/assess/hash.rb +22 -0
- data/lib/contrast/core_extensions/assess/kernel.rb +95 -0
- data/lib/contrast/core_extensions/assess/module.rb +14 -0
- data/lib/contrast/core_extensions/assess/regexp.rb +206 -0
- data/lib/contrast/core_extensions/assess/string.rb +75 -0
- data/lib/contrast/core_extensions/assess/tilt_template_trigger.rb +73 -0
- data/lib/contrast/core_extensions/delegator.rb +14 -0
- data/lib/contrast/core_extensions/eval_trigger.rb +52 -0
- data/lib/contrast/core_extensions/inventory.rb +22 -0
- data/lib/contrast/core_extensions/inventory/datastores.rb +37 -0
- data/lib/contrast/core_extensions/module.rb +42 -0
- data/lib/contrast/core_extensions/object.rb +27 -0
- data/lib/contrast/core_extensions/protect.rb +20 -0
- data/lib/contrast/core_extensions/protect/applies_command_injection_rule.rb +70 -0
- data/lib/contrast/core_extensions/protect/applies_deserialization_rule.rb +58 -0
- data/lib/contrast/core_extensions/protect/applies_no_sqli_rule.rb +81 -0
- data/lib/contrast/core_extensions/protect/applies_path_traversal_rule.rb +119 -0
- data/lib/contrast/core_extensions/protect/applies_sqli_rule.rb +63 -0
- data/lib/contrast/core_extensions/protect/applies_xxe_rule.rb +141 -0
- data/lib/contrast/core_extensions/protect/kernel.rb +30 -0
- data/lib/contrast/core_extensions/protect/psych.rb +7 -0
- data/lib/contrast/core_extensions/thread.rb +31 -0
- data/lib/contrast/internal_exception.rb +8 -0
- data/lib/contrast/rails_extensions/assess/action_controller_inheritance.rb +48 -0
- data/lib/contrast/rails_extensions/assess/active_record.rb +32 -0
- data/lib/contrast/rails_extensions/assess/active_record_named.rb +61 -0
- data/lib/contrast/rails_extensions/assess/configuration.rb +26 -0
- data/lib/contrast/rails_extensions/buffer.rb +30 -0
- data/lib/contrast/rails_extensions/rack.rb +45 -0
- data/lib/contrast/security_exception.rb +14 -0
- data/lib/contrast/sinatra_extensions/assess/cookie.rb +26 -0
- data/lib/contrast/sinatra_extensions/inventory/sinatra_base.rb +59 -0
- data/lib/contrast/tasks/service.rb +95 -0
- data/lib/contrast/utils/assess/sampling_util.rb +96 -0
- data/lib/contrast/utils/assess/tracking_util.rb +39 -0
- data/lib/contrast/utils/boolean_util.rb +33 -0
- data/lib/contrast/utils/cache.rb +69 -0
- data/lib/contrast/utils/class_util.rb +58 -0
- data/lib/contrast/utils/comment_range.rb +19 -0
- data/lib/contrast/utils/data_store_util.rb +23 -0
- data/lib/contrast/utils/duck_utils.rb +58 -0
- data/lib/contrast/utils/env_configuration_item.rb +52 -0
- data/lib/contrast/utils/environment_util.rb +152 -0
- data/lib/contrast/utils/freeze_util.rb +36 -0
- data/lib/contrast/utils/gemfile_reader.rb +191 -0
- data/lib/contrast/utils/hash_digest.rb +148 -0
- data/lib/contrast/utils/heap_dump_util.rb +113 -0
- data/lib/contrast/utils/invalid_configuration_util.rb +88 -0
- data/lib/contrast/utils/inventory_util.rb +126 -0
- data/lib/contrast/utils/io_util.rb +61 -0
- data/lib/contrast/utils/object_share.rb +117 -0
- data/lib/contrast/utils/operating_environment.rb +38 -0
- data/lib/contrast/utils/os.rb +49 -0
- data/lib/contrast/utils/path_util.rb +151 -0
- data/lib/contrast/utils/performs_logging.rb +152 -0
- data/lib/contrast/utils/preflight_util.rb +13 -0
- data/lib/contrast/utils/prevent_serialization.rb +52 -0
- data/lib/contrast/utils/rack_assess_session_cookie.rb +104 -0
- data/lib/contrast/utils/rails_assess_configuration.rb +95 -0
- data/lib/contrast/utils/random_util.rb +22 -0
- data/lib/contrast/utils/resource_loader.rb +23 -0
- data/lib/contrast/utils/ruby_ast_rewriter.rb +74 -0
- data/lib/contrast/utils/scope_util.rb +99 -0
- data/lib/contrast/utils/service_response_util.rb +116 -0
- data/lib/contrast/utils/service_sender_util.rb +98 -0
- data/lib/contrast/utils/sha256_builder.rb +69 -0
- data/lib/contrast/utils/sinatra_helper.rb +49 -0
- data/lib/contrast/utils/stack_trace_utils.rb +209 -0
- data/lib/contrast/utils/string_utils.rb +72 -0
- data/lib/contrast/utils/tag_util.rb +139 -0
- data/lib/contrast/utils/thread_tracker.rb +54 -0
- data/lib/contrast/utils/timer.rb +78 -0
- data/resources/assess/policy.json +1673 -0
- data/resources/csrf/inject.js +44 -0
- data/resources/deadzone/policy.json +55 -0
- data/resources/factory-bot-spec/spec_helper.rb +30 -0
- data/resources/inventory/policy.json +110 -0
- data/resources/protect/policy.json +417 -0
- data/resources/rubocops/kernel/catch_cop.rb +37 -0
- data/resources/rubocops/kernel/require_cop.rb +37 -0
- data/resources/rubocops/kernel/require_relative_cop.rb +33 -0
- data/resources/rubocops/module/autoload_cop.rb +37 -0
- data/resources/rubocops/module/const_defined_cop.rb +37 -0
- data/resources/rubocops/module/const_get_cop.rb +37 -0
- data/resources/rubocops/module/const_set_cop.rb +37 -0
- data/resources/rubocops/module/constants_cop.rb +37 -0
- data/resources/rubocops/module/name_cop.rb +37 -0
- data/resources/rubocops/object/class_cop.rb +37 -0
- data/resources/rubocops/object/freeze_cop.rb +37 -0
- data/resources/rubocops/object/frozen_cop.rb +37 -0
- data/resources/rubocops/object/is_a_cop.rb +37 -0
- data/resources/rubocops/object/method_cop.rb +37 -0
- data/resources/rubocops/object/respond_to_cop.rb +37 -0
- data/resources/rubocops/object/singleton_class_cop.rb +37 -0
- data/resources/rubocops/regexp/spelling_cop.rb +44 -0
- data/resources/rubocops/thread/new_cop.rb +39 -0
- data/resources/ruby-spec/ancestors_spec.rb +70 -0
- data/resources/ruby-spec/modulo_spec.rb +831 -0
- data/resources/ruby-spec/parameters_spec.rb +261 -0
- data/resources/ruby-spec/ruby_spec_spec_helper.rb +35 -0
- data/resources/test_marker.txt +1 -0
- data/ruby-agent.gemspec +129 -0
- data/service_executables/.gitkeep +0 -0
- data/service_executables/VERSION +1 -0
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +945 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Contrast
|
|
5
|
+
# Used to type a StandardError raised by Contrast code.
|
|
6
|
+
class InternalException < StandardError
|
|
7
|
+
end
|
|
8
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
if defined?(ActionController) &&
|
|
5
|
+
defined?(ActionController::Railties) &&
|
|
6
|
+
defined?(ActionController::Railties::Helpers)
|
|
7
|
+
module ActionController
|
|
8
|
+
module Railties
|
|
9
|
+
# Used to monkey patch all the inherited calls in action_pack
|
|
10
|
+
#
|
|
11
|
+
# This is the usual entry point for Rails inheritance work, so it should
|
|
12
|
+
# catch most of the calls to inherited.
|
|
13
|
+
module Helpers
|
|
14
|
+
alias_method :cs__patched_inherited, :inherited
|
|
15
|
+
def inherited klass
|
|
16
|
+
klass&.instance_variable_set(:@cs__defining_class, true)
|
|
17
|
+
cs__patched_inherited(klass)
|
|
18
|
+
ensure
|
|
19
|
+
klass&.instance_variable_set(:@cs__defining_class, false)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
if defined?(ActiveRecord) &&
|
|
27
|
+
defined?(ActiveRecord::AttributeMethods) &&
|
|
28
|
+
defined?(ActiveRecord::AttributeMethods::TimeZoneConversion) &&
|
|
29
|
+
defined?(ActiveRecord::AttributeMethods::TimeZoneConversion::ClassMethods)
|
|
30
|
+
module ActiveRecord
|
|
31
|
+
module AttributeMethods
|
|
32
|
+
# Used to monkey patch all the inherited calls in action_pack
|
|
33
|
+
module TimeZoneConversion
|
|
34
|
+
module ClassMethods #:nodoc:
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
alias_method :cs__patched_inherited, :inherited
|
|
38
|
+
def inherited klass
|
|
39
|
+
klass&.instance_variable_set(:@cs__defining_class, true)
|
|
40
|
+
cs__patched_inherited(klass)
|
|
41
|
+
ensure
|
|
42
|
+
klass&.instance_variable_set(:@cs__defining_class, false)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
if defined?(ActiveRecord) &&
|
|
5
|
+
defined?(ActiveRecord::AttributeMethods) &&
|
|
6
|
+
defined?(ActiveRecord::AttributeMethods::Read) &&
|
|
7
|
+
defined?(ActiveRecord::AttributeMethods::Read::ClassMethods)
|
|
8
|
+
|
|
9
|
+
module ActiveRecord
|
|
10
|
+
module AttributeMethods
|
|
11
|
+
module Read
|
|
12
|
+
# Rails / ActiveRecord are sneaky a.f. They define attributes of a
|
|
13
|
+
# class in one method, then monkey patch allocate in another and
|
|
14
|
+
# finally invoke module_eval in this method... but of course they use a
|
|
15
|
+
# '_tmp_' header for the method name and then alias it in this module
|
|
16
|
+
# to name it what we expect
|
|
17
|
+
module ClassMethods
|
|
18
|
+
alias_method :cs__patched_define_method_attribute, :define_method_attribute
|
|
19
|
+
|
|
20
|
+
def define_method_attribute *args, &block
|
|
21
|
+
ret = cs__patched_define_method_attribute(*args, &block)
|
|
22
|
+
method_name = args[0]
|
|
23
|
+
Contrast::Agent::Assess::Policy::Patcher.patch_assess_method(self, method_name)
|
|
24
|
+
ret
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
protected :cs__patched_define_method_attribute, :define_method_attribute
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
cs__scoped_require 'contrast/components/interface'
|
|
5
|
+
|
|
6
|
+
if defined?(ActiveRecord) &&
|
|
7
|
+
defined?(ActiveRecord::Scoping) &&
|
|
8
|
+
defined?(ActiveRecord::Scoping::Named) &&
|
|
9
|
+
defined?(ActiveRecord::Scoping::Named::ClassMethods) &&
|
|
10
|
+
ActiveRecord::Scoping::Named::ClassMethods.
|
|
11
|
+
instance_methods(false).
|
|
12
|
+
include?(:scope)
|
|
13
|
+
module ActiveRecord
|
|
14
|
+
module Scoping
|
|
15
|
+
module Named
|
|
16
|
+
# Our patch into the ActiveRecord::Scoping::Named::ClassMethods Module,
|
|
17
|
+
# allowing for the runtime rewrite of interpolation calls defined in
|
|
18
|
+
# methods defined dynamically during application execution.
|
|
19
|
+
#
|
|
20
|
+
# TODO: RUBY-534
|
|
21
|
+
module ClassMethods
|
|
22
|
+
include Contrast::Components::Interface
|
|
23
|
+
access_component :logging, :agent
|
|
24
|
+
|
|
25
|
+
def _cs__rewrite method_name, body
|
|
26
|
+
return body unless AGENT.rewrite_interpolation?
|
|
27
|
+
return body unless body.is_a?(Proc)
|
|
28
|
+
|
|
29
|
+
location = body.source_location
|
|
30
|
+
return body if location.nil?
|
|
31
|
+
|
|
32
|
+
# Good news, once we patch the body once, the source location
|
|
33
|
+
# becomes eval. We may need to fix this later though (so it may
|
|
34
|
+
# be bad news)
|
|
35
|
+
return body if location.empty? || location[0].empty? || location[0].include?('eval')
|
|
36
|
+
|
|
37
|
+
opener = Contrast::Agent::ClassReopener.new(Contrast::Agent::ModuleData.new(self))
|
|
38
|
+
original_source_code = opener.source_code(location, method_name)
|
|
39
|
+
return body unless original_source_code
|
|
40
|
+
return body if Contrast::Agent::Rewriter.send(:unrepeatable?, original_source_code)
|
|
41
|
+
return body unless Contrast::Agent::Rewriter.send(:interpolations?, original_source_code)
|
|
42
|
+
|
|
43
|
+
# the code looks like 'source :some_method_name, ->lambda_literal'
|
|
44
|
+
# we just need the lambda
|
|
45
|
+
body_start = original_source_code.index(',') + 1
|
|
46
|
+
original_source_code = original_source_code[body_start..-1]
|
|
47
|
+
|
|
48
|
+
new_method_source = Contrast::Agent::Rewriter.send(:rewrite_method, original_source_code)
|
|
49
|
+
return body unless Contrast::Agent::Rewriter.send(:valid_code?, new_method_source)
|
|
50
|
+
|
|
51
|
+
unbound_eval(cs__name, new_method_source)
|
|
52
|
+
rescue SyntaxError, StandardError => e
|
|
53
|
+
logger.debug(e, "Can't parse method source in scoped method #{ method_name }: #{ e.message }")
|
|
54
|
+
body
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
cs__scoped_require 'cs__assess_active_record_named/cs__assess_active_record_named'
|
|
61
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
|
2
|
+
# frozen_string_literal: false
|
|
3
|
+
|
|
4
|
+
if defined?(Rails) && defined?(Rails::Application) && defined?(Rails::Application::Configuration)
|
|
5
|
+
module Rails
|
|
6
|
+
class Application
|
|
7
|
+
# Our patch into the Rails::Application::Configuration Class, allowing
|
|
8
|
+
# for the runtime detection of insecure configurations on individual
|
|
9
|
+
# ActionDispatch::Session::AbstractStore instances within the
|
|
10
|
+
# application.
|
|
11
|
+
class Configuration
|
|
12
|
+
include Contrast::Utils::InvalidConfigurationUtil
|
|
13
|
+
include Contrast::Components::Interface
|
|
14
|
+
|
|
15
|
+
access_component :analysis, :scope
|
|
16
|
+
|
|
17
|
+
alias_method :cs__patched_session_store, :session_store
|
|
18
|
+
def session_store *args
|
|
19
|
+
ret = cs__patched_session_store(*args)
|
|
20
|
+
Contrast::Utils::RailsAssessConfiguration.analyze_session_store(*args)
|
|
21
|
+
ret
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
cs__scoped_require 'contrast/components/interface'
|
|
5
|
+
|
|
6
|
+
if defined?(ActionController) && defined?(ActionController::Live) && defined?(ActionController::Live::Buffer)
|
|
7
|
+
module ActionController
|
|
8
|
+
module Live
|
|
9
|
+
# This class acts as our patch into the ActionController::Live::Buffer
|
|
10
|
+
# class, allowing us to track the close event on streamed responses.
|
|
11
|
+
class Buffer
|
|
12
|
+
include Contrast::Components::Interface
|
|
13
|
+
access_component :contrast_service
|
|
14
|
+
|
|
15
|
+
# normally pre->in->post filters are applied however, in a streamed response
|
|
16
|
+
# we can run into a case where it's pre -> in -> post -> more infilters
|
|
17
|
+
# in order to submit anything found during the infilters after the response has been written we need to explicity send them
|
|
18
|
+
alias_method :cs__close, :close
|
|
19
|
+
def close
|
|
20
|
+
if (context = Contrast::Agent::REQUEST_TRACKER.current)
|
|
21
|
+
[context.server_activity, context.activity, context.observed_route].each do |msg|
|
|
22
|
+
CONTRAST_SERVICE.send_message msg
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
cs__close
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
if defined?(Rack)
|
|
5
|
+
# In earlier versions of rack < 2.0.0 the Rack::Response and Rack::Request do
|
|
6
|
+
# not have get_header or set_header methods. This is our way of working
|
|
7
|
+
# around that.
|
|
8
|
+
module Rack
|
|
9
|
+
if defined?(Rack::Request)
|
|
10
|
+
# Our patch into the Rack::Request class, allowing us to call set_header
|
|
11
|
+
# and get_header in our code without worrying about older versions of
|
|
12
|
+
# Rack not implementing these methods.
|
|
13
|
+
class Request
|
|
14
|
+
unless Rack::Request.instance_methods(true).include?(:set_header)
|
|
15
|
+
def set_header name, value
|
|
16
|
+
@env[name] = value
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
unless Rack::Request.instance_methods(true).include?(:get_header)
|
|
20
|
+
def get_header name
|
|
21
|
+
@env[name]
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
if defined?(Rack::Response)
|
|
28
|
+
# Our patch into the Rack::Response Class, allowing us to call set_header
|
|
29
|
+
# and get_header in our code without worrying about older versions of
|
|
30
|
+
# Rack not implementing these methods.
|
|
31
|
+
class Response
|
|
32
|
+
unless Rack::Response.instance_methods(true).include?(:set_header)
|
|
33
|
+
def set_header key, value
|
|
34
|
+
headers[key] = value
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
unless Rack::Response.instance_methods(true).include?(:get_header)
|
|
38
|
+
def get_header key
|
|
39
|
+
headers[key]
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Contrast
|
|
5
|
+
# A custom exception raised by our Protect rules in order to prevent
|
|
6
|
+
# malicious user input from completing an attack. This Exception purposefully
|
|
7
|
+
# extends StandardError and not SecurityError as StandardError is more likely
|
|
8
|
+
# to be handled by our customer's applications.
|
|
9
|
+
class SecurityException < StandardError
|
|
10
|
+
def initialize rule, message = nil
|
|
11
|
+
super(message || "Rule #{ rule.name } threw a security exception")
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
cs__scoped_require 'contrast/components/interface'
|
|
5
|
+
|
|
6
|
+
if defined?(Rack) && defined?(Rack::Session) && defined?(Rack::Session::Cookie)
|
|
7
|
+
module Rack
|
|
8
|
+
module Session
|
|
9
|
+
# Our patch into the Rack::Session::Cookie Class, allowing for the
|
|
10
|
+
# runtime detection of insecure configurations on individual cookies
|
|
11
|
+
# within the application
|
|
12
|
+
class Cookie
|
|
13
|
+
include Contrast::Utils::InvalidConfigurationUtil
|
|
14
|
+
include Contrast::Components::Interface
|
|
15
|
+
|
|
16
|
+
access_component :scope
|
|
17
|
+
|
|
18
|
+
alias_method :cs__patched_initialize, :initialize
|
|
19
|
+
def initialize app, options = {}
|
|
20
|
+
Contrast::Utils::RackAssessSessionCookie.analyze_cookie_initialization(options)
|
|
21
|
+
cs__patched_initialize(app, options)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
if defined?(Sinatra) && defined?(Sinatra::Base)
|
|
5
|
+
module Sinatra
|
|
6
|
+
# Our patch into the Sinatra::Base Class, allowing for the inventory of the
|
|
7
|
+
# routes called by the application
|
|
8
|
+
class Base
|
|
9
|
+
alias_method :cs__patched_call!, :call!
|
|
10
|
+
|
|
11
|
+
# publicly available method for Sinatra::Base things -- unfortunately,
|
|
12
|
+
# getting the routes appear to require a lookup every time
|
|
13
|
+
def call! *args
|
|
14
|
+
cs__patched_map_route(*args)
|
|
15
|
+
cs__patched_call!(*args)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
# Use logic copied from Sinatra::Base#process_route to determine which
|
|
21
|
+
# pattern matches the request being invoked by Sinatra::Base#call!
|
|
22
|
+
#
|
|
23
|
+
# @param args [Array<Object>] we rely on the @settings object in
|
|
24
|
+
# Sinatra::Base and the env variable passed in as args[0]
|
|
25
|
+
def cs__patched_map_route *args
|
|
26
|
+
context = Contrast::Agent::REQUEST_TRACKER.current
|
|
27
|
+
return unless context
|
|
28
|
+
|
|
29
|
+
env = args[0]
|
|
30
|
+
return unless env
|
|
31
|
+
|
|
32
|
+
# There isn't a Request object in the Sinatra::Base yet - it's made
|
|
33
|
+
# during the #call! method, which we're patching - so we need to
|
|
34
|
+
# access the env
|
|
35
|
+
method = env[Rack::REQUEST_METHOD]
|
|
36
|
+
route = env[Rack::PATH_INFO]
|
|
37
|
+
route = route.to_s
|
|
38
|
+
|
|
39
|
+
# get all potential routes for this request type
|
|
40
|
+
routes = settings.routes[method]
|
|
41
|
+
return unless routes
|
|
42
|
+
|
|
43
|
+
# Do some cleanup that matches Sinatra::Base#process_route
|
|
44
|
+
route = '/' if route.empty? && !settings.empty_path_info?
|
|
45
|
+
route = route[0..-2] if !settings.strict_paths? && route != '/' && route.end_with?('/')
|
|
46
|
+
|
|
47
|
+
# Find the route that matches this request. Since we're using
|
|
48
|
+
# settings, we should resolve in the same precedence as Sinatra
|
|
49
|
+
routes.each do |pattern, _, _| # Mustermann::Sinatra
|
|
50
|
+
next unless pattern.params(route)
|
|
51
|
+
|
|
52
|
+
dtm = Contrast::Utils::PathUtil.get_sinatra_route(cs__class, method, pattern)
|
|
53
|
+
context.append_route_coverage(dtm)
|
|
54
|
+
break
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
cs__scoped_require 'contrast/components/interface'
|
|
5
|
+
cs__scoped_require 'contrast/utils/os'
|
|
6
|
+
|
|
7
|
+
module Contrast
|
|
8
|
+
# A Rake task designed to allow control of the Contrast Service as a stand
|
|
9
|
+
# alone executable rather than one managed by the Agent running in a process
|
|
10
|
+
# forked from the application
|
|
11
|
+
module Service
|
|
12
|
+
extend Rake::DSL
|
|
13
|
+
include Contrast::Components::Interface
|
|
14
|
+
|
|
15
|
+
access_component :contrast_service
|
|
16
|
+
|
|
17
|
+
# Start the service if it is not already running
|
|
18
|
+
def self.start_service
|
|
19
|
+
puts 'Starting Contrast Service'
|
|
20
|
+
service_log = CONTRAST_SERVICE.logger_path
|
|
21
|
+
if File.writable?(service_log)
|
|
22
|
+
spawn('contrast_service', out: File::NULL, err: service_log)
|
|
23
|
+
else
|
|
24
|
+
spawn('contrast_service', %i[out err] => File::NULL)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
watcher = Contrast::Agent::Thread.new do
|
|
28
|
+
sleep(0.05) until Contrast::Utils::OS.running?
|
|
29
|
+
end
|
|
30
|
+
watcher.join(1)
|
|
31
|
+
puts Contrast::Utils::OS.running? ? 'Contrast Service started successfully.' : 'Contrast Service did not start.'
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Stop the service if it is running
|
|
35
|
+
def self.stop_service
|
|
36
|
+
if Contrast::Utils::OS.windows?
|
|
37
|
+
# https://stackoverflow.com/questions/13507902/how-to-extract-a-specific-field-from-output-of-tasklist-on-the-windows-command-l
|
|
38
|
+
pid = `for /f "tokens=2 delims=," %a in ('tasklist /nh /fi "imagename eq Contrast_Service.exe" /fo csv') do @echo %a`
|
|
39
|
+
`Taskkill /PID #{ pid } /F` if pid
|
|
40
|
+
else
|
|
41
|
+
pid = `ps aux | grep contrast-servic[e] | awk '{print $2}'`
|
|
42
|
+
`kill #{ pid }` if pid
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
namespace :contrast do
|
|
47
|
+
namespace :service do
|
|
48
|
+
desc 'Starts the Contrast Service'
|
|
49
|
+
task :start do
|
|
50
|
+
if Contrast::Utils::OS.running?
|
|
51
|
+
puts 'Contrast Service already running. No need to start'
|
|
52
|
+
elsif !CONTRAST_SERVICE.enabled?
|
|
53
|
+
puts 'Contrast Service disabled by configuration. Not starting.'
|
|
54
|
+
else
|
|
55
|
+
start_service
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
namespace :contrast do
|
|
62
|
+
namespace :service do
|
|
63
|
+
desc 'Prints the status of the Contrast Service'
|
|
64
|
+
task :status do
|
|
65
|
+
if Contrast::Utils::OS.running?
|
|
66
|
+
puts 'online'
|
|
67
|
+
elsif CONTRAST_SERVICE.enabled?
|
|
68
|
+
puts 'offline'
|
|
69
|
+
else
|
|
70
|
+
puts 'disabled'
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
namespace :contrast do
|
|
77
|
+
namespace :service do
|
|
78
|
+
desc 'Stops the Contrast Service'
|
|
79
|
+
task :stop do
|
|
80
|
+
if Contrast::Utils::OS.running?
|
|
81
|
+
puts 'Stopping Contrast Service'
|
|
82
|
+
stop_service
|
|
83
|
+
watcher = Contrast::Agent::Thread.new do
|
|
84
|
+
sleep(0.05) while Contrast::Utils::OS.running?
|
|
85
|
+
end
|
|
86
|
+
watcher.join(1)
|
|
87
|
+
puts Contrast::Utils::OS.running? ? 'Contrast Service did not stop.' : 'Contrast Service stopped successfully.'
|
|
88
|
+
else
|
|
89
|
+
puts 'Contrast Service is not already running. No need to stop.'
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|