-
Notifications
You must be signed in to change notification settings - Fork 1
fix: change rate limit key #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ | |
"type": "ratelimit", | ||
"namespace_id": "1006", | ||
"simple": { | ||
"limit": 100, | ||
"limit": 10, | ||
"period": 60, | ||
}, | ||
Comment on lines
+27
to
29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainCLAIM_DB limit also tightened to 10 req/min — align expectations Ensure clients and tests reflect the new ceiling to avoid false alarms. Consider staggered rollout or per-env overrides if needed. 🏁 Script executed: #!/bin/bash
# Show the wrangler.jsonc around the rate limit config
echo "---- claim-db-worker/wrangler.jsonc (lines 1-100) ----"
sed -n '1,100p' claim-db-worker/wrangler.jsonc || true
echo -e "\n---- All occurrences of 'limit' in JSON/JSONC files ----"
rg --type-add 'jsonc:*.jsonc' --type-add 'json:*.json' -tjson -tjsonc '"limit"' -C 3
echo -e "\n---- References to rate limiting in code/tests ----"
rg -n "limit" -e "claim" -e "db" || true
rg -n "rate" -e "limit" || true
echo -e "\n---- Test files mentioning 10 or 60 ----"
rg -n "10" --glob '*test*' || true
rg -n "60" --glob '*test*' || true Length of output: 2323 CLAIM_DB rate limit lowered to 10 req/min—update clients & tests We’ve tightened • tests/test-rate-limits.sh: lower the default 🤖 Prompt for AI Agents
|
||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
#!/bin/bash | ||
|
||
# Test Rate Limits Script | ||
# Usage: ./tests/test-rate-limits.sh [test_count] [create_db_url] [claim_db_url] | ||
# Usage: ./tests/test-rate-limits.sh [test_count] [create_db_url] [claim_db_url] [agent_id] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Add strict mode and safer loop quoting Improve robustness and satisfy shellcheck. # Test Rate Limits Script
-# Usage: ./tests/test-rate-limits.sh [test_count] [create_db_url] [claim_db_url] [agent_id]
+# Usage: ./tests/test-rate-limits.sh [test_count] [create_db_url] [claim_db_url] [agent_id]
+set -Eeuo pipefail Also change the loop and seq usage: - for i in $(seq 1 $TEST_COUNT); do
+ for i in $(seq 1 "${TEST_COUNT}"); do 🤖 Prompt for AI Agents
|
||
|
||
# Default values | ||
TEST_COUNT=${1:-110} | ||
CREATE_DB_URL=${2:-"http://127.0.0.1:8787"} | ||
CLAIM_DB_URL=${3:-"http://127.0.0.1:9999"} | ||
CREATE_DB_URL=${2:-"https://create-db-temp.prisma.io"} | ||
CLAIM_DB_URL=${3:-"https://create-db.prisma.io"} | ||
AGENT_ID=${4:-"meow"} | ||
|
||
echo "🧪 Testing Rate Limits" | ||
echo "======================" | ||
echo "Test Count: $TEST_COUNT" | ||
echo "Create DB URL: $CREATE_DB_URL" | ||
echo "Claim DB URL: $CLAIM_DB_URL" | ||
echo "Agent Header: X-Agent: $AGENT_ID" | ||
echo "User-Agent: prisma-rate-limit-test/$AGENT_ID" | ||
echo "" | ||
|
||
# Function to test a worker | ||
|
@@ -32,8 +35,15 @@ test_worker() { | |
for i in $(seq 1 $TEST_COUNT); do | ||
echo -n "Request $i/$TEST_COUNT: " | ||
|
||
# Make the request and capture both response body and status code | ||
response=$(curl -s -w "%{http_code}" -o /tmp/response_$i.json "$endpoint" 2>/dev/null) | ||
# Make the request with unique agent headers and capture body + status code | ||
response=$(curl -s \ | ||
-H "x-agent: $AGENT_ID" \ | ||
-H "x-Agent: $AGENT_ID" \ | ||
-H "User-Agent: prisma-rate-limit-test/$AGENT_ID" \ | ||
-w "%{http_code}" \ | ||
-o /tmp/response_$i.json \ | ||
"$endpoint" 2>/dev/null) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Quote variables (SC2086), remove duplicate header, and safe temp files
- # Make the request with unique agent headers and capture body + status code
- response=$(curl -s \
- -H "x-agent: $AGENT_ID" \
- -H "x-Agent: $AGENT_ID" \
- -H "User-Agent: prisma-rate-limit-test/$AGENT_ID" \
- -w "%{http_code}" \
- -o /tmp/response_$i.json \
- "$endpoint" 2>/dev/null)
+ # Make the request with unique agent header and capture body + status code
+ tmp_dir="${TMP_DIR:-$(mktemp -d)}"
+ trap 'rm -rf "$tmp_dir"' EXIT
+ response="$(
+ curl -s \
+ -H "x-agent: ${AGENT_ID}" \
+ -H "User-Agent: prisma-rate-limit-test/${AGENT_ID}" \
+ -w "%{http_code}" \
+ -o "${tmp_dir}/response_${i}.json" \
+ "${endpoint}" 2>/dev/null
+ )" 🧰 Tools🪛 Shellcheck (0.10.0)[info] 44-44: Double quote to prevent globbing and word splitting. (SC2086) 🤖 Prompt for AI Agents
|
||
status_code=${response: -3} | ||
|
||
case $status_code in | ||
|
@@ -52,7 +62,7 @@ test_worker() { | |
esac | ||
|
||
# Small delay between requests | ||
sleep 0.1 | ||
#sleep 0.05 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Optional: throttle to reduce noisy bursts Consider re-introducing a small sleep (e.g., 20–50ms) to avoid overwhelming remote endpoints during ad-hoc runs. 🤖 Prompt for AI Agents
|
||
done | ||
|
||
echo "" | ||
|
@@ -76,4 +86,4 @@ echo "- Later requests should be rate limited (429)" | |
echo "- This confirms rate limiting is working correctly" | ||
echo "" | ||
echo "💡 To test with your actual deployed URLs, run:" | ||
echo " ./tests/test-rate-limits.sh 110 https://create-db-temp.prisma.io https://create-db.prisma.io" | ||
echo " ./tests/test-rate-limits.sh 110 https://create-db-temp.prisma.io https://create-db.prisma.io my-local-agent" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Example invocation: consider demonstrating local defaults Recommend showing a local/miniflare example first to prevent accidental production load. 🤖 Prompt for AI Agents
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Do not trust client header over CF IP; add fallbacks and avoid null keys
Using x-agent before cf-connecting-ip allows trivial rate-limit evasion by rotating x-agent. Also, clientIP can be null in some envs; the non-null assertion
!
only silences TS, not runtime.Refactor to prefer CF-provided IP, then standard proxy headers, then a dev/testing override, and finally a safe default.
📝 Committable suggestion
🤖 Prompt for AI Agents