Class: PxModule::PerimeterxCookieValidator
- Inherits:
-
Object
- Object
- PxModule::PerimeterxCookieValidator
- Defined in:
- lib/perimeterx/internal/validators/perimeter_x_cookie_validator.rb
Instance Attribute Summary collapse
-
#px_config ⇒ Object
Returns the value of attribute px_config.
Instance Method Summary collapse
-
#initialize(px_config) ⇒ PerimeterxCookieValidator
constructor
A new instance of PerimeterxCookieValidator.
- #verify(px_ctx) ⇒ Object
Constructor Details
#initialize(px_config) ⇒ PerimeterxCookieValidator
Returns a new instance of PerimeterxCookieValidator.
13 14 15 16 |
# File 'lib/perimeterx/internal/validators/perimeter_x_cookie_validator.rb', line 13 def initialize(px_config) @px_config = px_config @logger = px_config[:logger] end |
Instance Attribute Details
#px_config ⇒ Object
Returns the value of attribute px_config.
11 12 13 |
# File 'lib/perimeterx/internal/validators/perimeter_x_cookie_validator.rb', line 11 def px_config @px_config end |
Instance Method Details
#verify(px_ctx) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/perimeterx/internal/validators/perimeter_x_cookie_validator.rb', line 19 def verify(px_ctx) begin if px_ctx.context[:px_cookie].empty? @logger.warn("PerimeterxCookieValidator:[verify]: no cookie") px_ctx.context[:s2s_call_reason] = PxModule::NO_COOKIE return false, px_ctx end # Deserialize cookie start = PerimeterxPayload.(px_ctx, @px_config) if !.deserialize() @logger.warn("PerimeterxCookieValidator:[verify]: invalid cookie") px_ctx.context[:px_orig_cookie] = px_ctx. px_ctx.context[:s2s_call_reason] = PxModule::COOKIE_DECRYPTION_FAILED return false, px_ctx end px_ctx.context[:decoded_cookie] = . px_ctx.context[:score] = .() px_ctx.context[:uuid] = .[:u] px_ctx.context[:block_action] = px_ctx.set_block_action_type(.()) px_ctx.context[:cookie_hmac] = .() vid = .[:v] if vid.is_a?(String) && vid.match(PxModule::VID_REGEX) px_ctx.context[:vid_source] = "risk_cookie" px_ctx.context[:vid] = vid end if .expired? @logger.warn("PerimeterxCookieValidator:[verify]: cookie expired") px_ctx.context[:s2s_call_reason] = PxModule::EXPIRED_COOKIE return false, px_ctx end if .high_score? @logger.warn("PerimeterxCookieValidator:[verify]: cookie high score") px_ctx.context[:blocking_reason] = 'cookie_high_score' return true, px_ctx end if !.secured? @logger.warn("PerimeterxCookieValidator:[verify]: cookie invalid hmac") px_ctx.context[:s2s_call_reason] = PxModule:: COOKIE_VALIDATION_FAILED return false, px_ctx end if px_ctx.context[:sensitive_route] @logger.info("PerimeterxCookieValidator:[verify]: cookie was verified but route is sensitive") px_ctx.context[:s2s_call_reason] = PxModule::SENSITIVE_ROUTE return false, px_ctx end @logger.debug("PerimeterxCookieValidator:[verify]: cookie validation passed succesfully") px_ctx.context[:pass_reason] = 'cookie' return true, px_ctx rescue Exception => e @logger.error("PerimeterxCookieValidator:[verify]: exception while verifying cookie => #{e.}") px_ctx.context[:px_orig_cookie] = px_ctx.context[:px_cookie] px_ctx.context[:s2s_call_reason] = PxModule::COOKIE_DECRYPTION_FAILED return false, px_ctx end end |