Skip to content

Commit 12330c5

Browse files
authored
Merge branch 'master' into irve/refactor
2 parents 0606f36 + dd55656 commit 12330c5

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

apps/transport/test/transport_web/plugs/rate_limiter_test.exs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ defmodule TransportWeb.Plugs.RateLimiterTest do
2727
allow_user_agents: ""
2828
)
2929

30-
assert [allow_user_agents: ["bar", "baz"], block_user_agent_keywords: ["foo", "bar"], log_user_agent: false] =
30+
assert [
31+
allow_user_agents: ["bar", "baz"],
32+
block_user_agent_keywords: ["foo", "bar"],
33+
log_user_agent: false
34+
] =
3135
RateLimiter.init(
3236
log_user_agent: "",
3337
block_user_agent_keywords: "foo|bar",
@@ -36,7 +40,11 @@ defmodule TransportWeb.Plugs.RateLimiterTest do
3640
end
3741

3842
test "with keywords" do
39-
assert [allow_user_agents: [], log_user_agent: false, block_user_agent_keywords: ["foo", "bar"]] ==
43+
assert [
44+
allow_user_agents: [],
45+
log_user_agent: false,
46+
block_user_agent_keywords: ["foo", "bar"]
47+
] ==
4048
RateLimiter.init(
4149
block_user_agent_keywords: ["foo", "bar"],
4250
log_user_agent: false,

config/config.exs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -223,21 +223,6 @@ config :appsignal, :config,
223223
"Unlock.Controller#fetch"
224224
]
225225

226-
# `phoenix_ddos` is called in our own Plug `TransportWeb.Plugs.RateLimiter`
227-
config :phoenix_ddos,
228-
safelist_ips: "PHOENIX_DDOS_SAFELIST_IPS" |> System.get_env("") |> String.split("|") |> Enum.reject(&(&1 == "")),
229-
blocklist_ips: "PHOENIX_DDOS_BLOCKLIST_IPS" |> System.get_env("") |> String.split("|") |> Enum.reject(&(&1 == "")),
230-
protections: [
231-
# ip rate limit
232-
{PhoenixDDoS.IpRateLimit,
233-
allowed: "PHOENIX_DDOS_MAX_2MIN_REQUESTS" |> System.get_env("500") |> Integer.parse() |> elem(0),
234-
period: {2, :minutes}},
235-
{PhoenixDDoS.IpRateLimit,
236-
allowed: "PHOENIX_DDOS_MAX_1HOUR_REQUESTS" |> System.get_env("10000") |> Integer.parse() |> elem(0),
237-
period: {1, :hour}}
238-
# ip rate limit on specific request_path
239-
]
240-
241226
# Import environment specific config. This must remain at the bottom
242227
# of this file so it overrides the configuration defined above.
243228
import_config "datagouvfr.exs"

config/prod.exs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,22 @@ config :sentry,
1919
dsn: System.get_env("SENTRY_DSN"),
2020
csp_url: System.get_env("SENTRY_CSP_URL")
2121

22+
# `phoenix_ddos` is called in our own Plug `TransportWeb.Plugs.RateLimiter`
23+
config :phoenix_ddos,
24+
safelist_ips: "PHOENIX_DDOS_SAFELIST_IPS" |> System.get_env("") |> String.split("|") |> Enum.reject(&(&1 == "")),
25+
blocklist_ips: "PHOENIX_DDOS_BLOCKLIST_IPS" |> System.get_env("") |> String.split("|") |> Enum.reject(&(&1 == "")),
26+
protections: [
27+
# ip rate limit
28+
{PhoenixDDoS.IpRateLimit,
29+
allowed: "PHOENIX_DDOS_MAX_2MIN_REQUESTS" |> System.get_env("500") |> Integer.parse() |> elem(0),
30+
period: {2, :minutes}},
31+
{PhoenixDDoS.IpRateLimit,
32+
allowed: "PHOENIX_DDOS_MAX_1HOUR_REQUESTS" |> System.get_env("10000") |> Integer.parse() |> elem(0),
33+
period: {1, :hour}},
34+
# ip rate limit on specific request_path
35+
{PhoenixDDoS.IpRateLimitPerRequestPath, request_paths: [{:get, "/login"}], allowed: 5, period: {30, :seconds}},
36+
{PhoenixDDoS.IpRateLimitPerRequestPath, request_paths: [{:post, "/send_mail"}], allowed: 1, period: {30, :seconds}}
37+
]
38+
2239
# Do not print debug messages in production
2340
config :logger, level: :info

0 commit comments

Comments
 (0)