datadome 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fd4a9c24ac83994e1334eaa2464593739f364382
4
- data.tar.gz: e3fa5a184303204530187e89ac09529950900ea2
2
+ SHA256:
3
+ metadata.gz: 0fc3263877e553fdfcca02f6d2b8d4fc843ab7a9eb4aedc9de21b1a33f392fdb
4
+ data.tar.gz: 180c669ca5185b7a4db133d3cf3b3d5f1b53a1c59779ec026dcb17dc0dea09a3
5
5
  SHA512:
6
- metadata.gz: 6a04aefc34becc8e081797effa886865b3962383d74a6f12aeab3b5cf1272b57ea6ffa648ef06f864859381675f7eca4feee3117ac0f42dfec3afb563ebfbde1
7
- data.tar.gz: e01baa33dd83ca39299d2c9e214a77d0b5ec050d0d8f65adbe514b0ea8a924bb481c422cdac32fad410170148413360daf0d3b837150ac78ae77f349e04bbb55
6
+ metadata.gz: 238ebb363b6402bec03093106d27ae33660adbe504b98e9ebbc38864a37d079ce4d745917905b56c7f8600087b02030be94b5ea6dfd47151d57451da61b0c80c
7
+ data.tar.gz: ad566d02d55bcdc8ac811df8c39b95df6736bb05b1ed6b2f40fafb16c92e5d8f5bcdcc33a9b53e0101c5b0efe8f07a61d6b940e3c0bceee205172ecb2ef22325
data/README.md CHANGED
@@ -38,6 +38,12 @@ Datadome.configure do |config|
38
38
  # Choose the closest Datadome API endpoint
39
39
  # More info at https://docs.datadome.co/docs/api-server
40
40
  config.api_server = "api-us-east-1.datadome.co"
41
+
42
+ # Add include matchers (optional)
43
+ config.include_matchers << ->(host, path) { host == "www.my-domain.com" }
44
+
45
+ # Add exclude matchers (optional)
46
+ config.exclude_matchers << ->(host, path) { path =~ /\.(jpg|jpeg|png|gif)/i }
41
47
  end
42
48
 
43
49
  Datadome.logger = Logger.new(STDOUT, level: :debug)
@@ -7,9 +7,11 @@ module Datadome
7
7
 
8
8
  def initialize
9
9
  @api_server = "api.datadome.co"
10
+ @exclude_matchers = []
11
+ @include_matchers = []
10
12
  end
11
13
 
12
- attr_accessor :api_key, :api_server
14
+ attr_accessor :api_key, :api_server, :exclude_matchers, :include_matchers
13
15
 
14
16
  end
15
17
  end
@@ -5,8 +5,11 @@ require "rack"
5
5
  module Datadome
6
6
  class Inquirer
7
7
 
8
- def initialize(env)
8
+ def initialize(env, exclude_matchers: nil, include_matchers: nil)
9
9
  @env = env
10
+
11
+ @exclude_matchers = exclude_matchers || Datadome.configuration.exclude_matchers
12
+ @include_matchers = include_matchers || Datadome.configuration.include_matchers
10
13
  end
11
14
 
12
15
  def build_response
@@ -30,6 +33,32 @@ module Datadome
30
33
  [status, headers, response]
31
34
  end
32
35
 
36
+ def ignore?
37
+ return false if include_matchers.empty? && exclude_matchers.empty?
38
+
39
+ request = ::Rack::Request.new(@env)
40
+
41
+ if include_matchers.any?
42
+ any_include_matches =
43
+ include_matchers.any? do |matcher|
44
+ matcher.call(request.host, request.path)
45
+ end
46
+
47
+ return true unless any_include_matches
48
+ end
49
+
50
+ if exclude_matchers.any?
51
+ any_exclude_matches =
52
+ exclude_matchers.any? do |matcher|
53
+ matcher.call(request.host, request.path)
54
+ end
55
+
56
+ return true if any_exclude_matches
57
+ end
58
+
59
+ false
60
+ end
61
+
33
62
  def intercept?
34
63
  @validation_response.pass == false || @validation_response.redirect
35
64
  end
@@ -40,6 +69,8 @@ module Datadome
40
69
 
41
70
  private
42
71
 
72
+ attr_reader :exclude_matchers, :include_matchers
73
+
43
74
  def validate_request
44
75
  validation_request = ValidationRequest.from_env(@env)
45
76
 
@@ -11,8 +11,9 @@ module Datadome
11
11
 
12
12
  def call(env)
13
13
  inquirer = Inquirer.new(env)
14
- inquired = inquirer.inquire
14
+ return @app.call(env) if inquirer.ignore?
15
15
 
16
+ inquired = inquirer.inquire
16
17
  return @app.call(env) unless inquired
17
18
 
18
19
  if inquirer.intercept?
@@ -85,15 +85,15 @@ module Datadome
85
85
  env["HTTP_ACCEPT_LANGUAGE"]
86
86
  end
87
87
 
88
- capture("CacheControl") do |env, _request|
88
+ capture("CacheControl", max_size: 128) do |env, _request|
89
89
  env["HTTP_CACHE_CONTROL"]
90
90
  end
91
91
 
92
- capture("Connection") do |env, _request|
92
+ capture("Connection", max_size: 128) do |env, _request|
93
93
  env["HTTP_CONNECTION"]
94
94
  end
95
95
 
96
- capture("Host") do |_env, request|
96
+ capture("Host", max_size: 512) do |_env, request|
97
97
  request.host
98
98
  end
99
99
 
@@ -101,7 +101,7 @@ module Datadome
101
101
  env["HTTP_ORIGIN"]
102
102
  end
103
103
 
104
- capture("Pragma") do |env, _request|
104
+ capture("Pragma", max_size: 128) do |env, _request|
105
105
  env["HTTP_PRAGMA"]
106
106
  end
107
107
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Datadome
4
4
 
5
- VERSION = "0.0.1"
5
+ VERSION = "0.0.2"
6
6
 
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datadome
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxime Garcia
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-09 00:00:00.000000000 Z
11
+ date: 2017-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  version: '0'
158
158
  requirements: []
159
159
  rubyforge_project:
160
- rubygems_version: 2.6.13
160
+ rubygems_version: 2.7.1
161
161
  signing_key:
162
162
  specification_version: 4
163
163
  summary: Rack middleware for Datadome.