Skip to content

Commit

Permalink
Use our own caddy build and add rate limiting and ja3 fp (#1500)
Browse files Browse the repository at this point in the history
  • Loading branch information
forgetso authored Nov 7, 2024
1 parent 59ddc88 commit 554951e
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 55 deletions.
6 changes: 1 addition & 5 deletions demos/client-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@
"clean": "tsc --build --clean"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"production": [">0.2%", "not dead", "not op_mini all"],
"development": [
"last 1 chrome version",
"last 1 firefox version",
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.provider.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ services:
profiles:
- production
- staging
image: caddy:2
image: prosopo/caddy:latest
env_file:
- ../.env.${NODE_ENV}
labels:
Expand Down
7 changes: 4 additions & 3 deletions docker/images/caddy.dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM caddy:2-builder AS builder

RUN xcaddy build \
RUN apk update && apk add gcc g++ make libpcap-dev libpcap
RUN CGO_ENABLED=1 xcaddy build \
--with github.com/mholt/caddy-ratelimit \
--with github.com/rushiiMachine/caddy-ja3

FROM caddy:2

RUN apk update && apk add libpcap
COPY --from=builder /usr/bin/caddy /usr/bin/caddy
37 changes: 35 additions & 2 deletions docker/provider.Caddyfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
# usage: `caddy run --config ./docker/provider.Caddyfile --envfile docker/env.development`
{
# debug
http_port {$CADDY_HTTP_PORT:80}
auto_https {$CADDY_AUTO_HTTPS:disable_redirects}
admin {$CADDY_ADMIN_API::2020} # set the admin api to run on localhost:2020 (default is 2019 which can conflict with caddy daemon)

# Caddy must be told custom rate_limit module its order
order rate_limit before basicauth
order ja3 before respond
servers {
listener_wrappers {
http_redirect
ja3
tls
}
timeouts {
read_body 15s
read_header 10s
Expand All @@ -24,12 +33,36 @@
# reverse proxy the metrics path to the metrics emitted by caddy on the admin api
# reverse_proxy /metrics {$CADDY_ADMIN_API}

rate_limit {
distributed

# Means that the rate limit is applied to all GET requests, with a limit of 100 requests per minute.
# zone get_rate_limit {
# match {
# method GET
# }
# key static
# events 100
# window 1m
# }

# The rate limit is applied to `remote_host` with a limit of 6 requests per 6 seconds (60 requests per minute).
zone dynamic_example {
key {remote_host}
events 6
window 6s
}
log_key
}

ja3 sort_ja3 true

# reverse proxy to the provider container
reverse_proxy {$CADDY_PROVIDER_CONTAINER_NAME:provider}:{$CADDY_PROVIDER_PORT:9229} {
# https://caddyserver.com/docs/caddyfile/concepts#placeholders
# https://caddyserver.com/docs/json/apps/http/#docs
header_up x-tls-version "{tls_version}"

header_up x-tls-version "{tls_version}"
header_up x-tls-version "^{tls_version}$" ""

header_up x-tls-client-subject "{tls_client_subject}"
Expand Down
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,7 @@
"node": "20",
"npm": ">=9"
},
"workspaces": [
"dev/*",
"packages/*",
"demos/*"
],
"workspaces": ["dev/*", "packages/*", "demos/*"],
"devDependencies": {
"@biomejs/biome": "1.9.1",
"@taplo/cli": "0.7.0",
Expand Down
12 changes: 3 additions & 9 deletions packages/contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"files": ["dist"],
"exports": {
".": {
"import": "./dist/index.js",
Expand All @@ -33,12 +31,8 @@
},
"typesVersions": {
"*": {
"types": [
"dist/types"
],
"captcha": [
"dist/captcha"
]
"types": ["dist/types"],
"captcha": ["dist/captcha"]
}
},
"dependencies": {
Expand Down
8 changes: 2 additions & 6 deletions packages/datasets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,8 @@
},
"typesVersions": {
"*": {
"types": [
"dist/types"
],
"captcha": [
"dist/captcha"
]
"types": ["dist/types"],
"captcha": ["dist/captcha"]
}
},
"dependencies": {
Expand Down
4 changes: 1 addition & 3 deletions packages/procaptcha-bundle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
"bundle": "NODE_ENV=${NODE_ENV:-production}; vite build --config vite.config.ts --mode $NODE_ENV --debug",
"bundle:webpack": "NODE_ENV=${NODE_ENV:-production}; webpack build --config webpack.config.cjs --mode $NODE_ENV"
},
"browserslist": [
"> 0.5%, last 2 versions, not dead"
],
"browserslist": ["> 0.5%, last 2 versions, not dead"],
"dependencies": {
"@prosopo/dotenv": "2.1.10",
"@prosopo/locale": "2.1.10",
Expand Down
4 changes: 1 addition & 3 deletions packages/procaptcha-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
"build": "tsc --build --verbose",
"build:cjs": "npx vite --config vite.cjs.config.ts build"
},
"browserslist": [
"> 0.5%, last 2 versions, not dead"
],
"browserslist": ["> 0.5%, last 2 versions, not dead"],
"dependencies": {
"@prosopo/common": "2.1.10",
"@prosopo/load-balancer": "2.1.10",
Expand Down
4 changes: 1 addition & 3 deletions packages/procaptcha-frictionless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
"build": "tsc --build --verbose",
"build:cjs": "npx vite --config vite.cjs.config.ts build"
},
"browserslist": [
"> 0.5%, last 2 versions, not dead"
],
"browserslist": ["> 0.5%, last 2 versions, not dead"],
"dependencies": {
"@prosopo/detector": "2.1.10",
"@prosopo/locale-browser": "2.1.10",
Expand Down
4 changes: 1 addition & 3 deletions packages/procaptcha-pow/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
"build": "tsc --build --verbose",
"build:cjs": "npx vite --config vite.cjs.config.ts build"
},
"browserslist": [
"> 0.5%, last 2 versions, not dead"
],
"browserslist": ["> 0.5%, last 2 versions, not dead"],
"dependencies": {
"@polkadot/util": "12.6.2",
"@prosopo/account": "2.1.10",
Expand Down
4 changes: 1 addition & 3 deletions packages/procaptcha-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
"build": "tsc --build --verbose",
"build:cjs": "npx vite --config vite.cjs.config.ts build"
},
"browserslist": [
"> 0.5%, last 2 versions, not dead"
],
"browserslist": ["> 0.5%, last 2 versions, not dead"],
"dependencies": {
"@prosopo/common": "2.1.10",
"@prosopo/locale-browser": "2.1.10",
Expand Down
12 changes: 3 additions & 9 deletions packages/tx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"files": ["dist"],
"exports": {
".": {
"import": "./dist/index.js",
Expand All @@ -27,12 +25,8 @@
},
"typesVersions": {
"*": {
"types": [
"dist/types"
],
"captcha": [
"dist/captcha"
]
"types": ["dist/types"],
"captcha": ["dist/captcha"]
}
},
"dependencies": {
Expand Down

0 comments on commit 554951e

Please sign in to comment.