Advertisement
Omnipotent

Cloudflare's Unreleased Rate Limiting Documentation

Dec 20th, 2016
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 11.59 KB | None | 0 0
  1. {
  2.   "id": "/client/zone/rate_limits",
  3.   "title": "Rate Limits for a Zone",
  4.   "$schema": "http://json-schema.org/draft-04/schema#",
  5.   "description": "Documentation for Cloudflare Rate Limits",
  6.   "type": "object",
  7.   "allOf": [
  8.     {
  9.       "$ref": "#/definitions/ratelimit"
  10.     }
  11.   ],
  12.   "definitions": {
  13.     "zone_identifier": {
  14.       "$ref": "../../common/zone.json#/definitions/identifier"
  15.     },
  16.     "id": {
  17.       "description": "Ratelimit identifier",
  18.       "type": "string",
  19.       "maxLength": 32,
  20.       "readOnly": true,
  21.       "example": "372e67954025e0ba6aaa6d586b9e0b59"
  22.     },
  23.     "ratelimit": {
  24.       "properties": {
  25.         "id": {
  26.           "$ref": "#/definitions/id"
  27.         },
  28.         "disabled": {
  29.           "type": "boolean",
  30.           "description": "Whether this ratelimit is currently disabled",
  31.           "example": false
  32.         },
  33.         "description": {
  34.           "type": "string",
  35.           "description": "A note that you can use to describe the reason for a rate limit. This value is sanitized and all tags are removed",
  36.           "maxLength": 1024,
  37.           "example": "Prevent multiple login failures to mitigate brute force attacks"
  38.         },
  39.         "match": {
  40.           "type": "object",
  41.           "description": "Determines which traffic the rate limit counts towards the threshold",
  42.           "properties": {
  43.             "request": {
  44.               "type": "object",
  45.               "description": "Matches HTTP requests (from the client to Cloudflare)",
  46.               "properties": {
  47.                 "methods": {
  48.                   "type": "array",
  49.                   "description": "HTTP Methods, can be a subset ['POST','PUT'] or all ['_ALL_']",
  50.                   "items": {
  51.                     "type": "string",
  52.                     "description": "HTTP Method, or '_ALL_' to indicate all methods",
  53.                     "example": "GET"
  54.                   },
  55.                   "example": ["GET", "POST"]
  56.                 },
  57.                 "schemes": {
  58.                   "type": "array",
  59.                   "description": "HTTP Schemes, can be one ['HTTPS'], both ['HTTP','HTTPS'] or all ['_ALL_']",
  60.                   "items": {
  61.                     "type": "string",
  62.                     "description": "HTTP Scheme, or '_ALL_' to indicate all schemes",
  63.                     "example": "HTTPS"
  64.                   },
  65.                   "example": ["HTTP", "HTTPS"]
  66.                 },
  67.                 "url": {
  68.                   "type": "string",
  69.                   "description": "The URL pattern to match comprised of the host and path, i.e.example.org/path*. Wildcard * are expanded to match applicable traffic, query strings are not matched.",
  70.                   "maxLength": 1024,
  71.                   "example": "*.example.org/path*"
  72.                 }
  73.               }
  74.             },
  75.             "response": {
  76.               "type": "object",
  77.               "description": "Matches HTTP responses before they are returned to the client from Cloudflare. If this is defined, then the entire counting of traffic occurs at this stage.",
  78.               "properties": {
  79.                 "status": {
  80.                   "type": "array",
  81.                   "description": "HTTP Status codes, can be one [403], many [401,403] or indicate all by not providing this value",
  82.                   "items": {
  83.                     "type": "number",
  84.                     "minimum": 100,
  85.                     "maximum": 999,
  86.                     "description": "HTTP Status code",
  87.                     "example": 401
  88.                   },
  89.                   "example": [401, 403]
  90.                 },
  91.                 "origin_traffic": {
  92.                   "type": "boolean",
  93.                   "description": "Only count traffic that has come from your origin servers. If true, cached items that Cloudflare serve will not count towards rate limiting.",
  94.                   "example": true
  95.                 }
  96.               }
  97.             }
  98.           }
  99.         },
  100.         "threshold": {
  101.           "type": "number",
  102.           "description": "The threshold that triggers the rate limit mitigations, combine with sample_rate. i.e. thresold per sample_rate",
  103.           "minimum": 2,
  104.           "maximum": 1000000,
  105.           "example": 60
  106.         },
  107.         "sample_rate": {
  108.           "type": "number",
  109.           "description": "The time in seconds to count matching traffic. If the count exceeds thresold within this period the action will be performed",
  110.           "minimum": 1,
  111.           "maximum": 86400,
  112.           "example": 900
  113.         },
  114.         "action": {
  115.           "type": "object",
  116.           "description": "The action to be performed when the thresold of matched traffic within the sample_rate period is exceeded",
  117.           "properties": {
  118.             "mode": {
  119.               "type": "string",
  120.               "description": "The type of action to perform, i.e. simulate or ban",
  121.               "maxLength": 10,
  122.               "example": "simulate"
  123.             },
  124.             "timeout": {
  125.               "type": "number",
  126.               "description": "The time in seconds to perform the mitigation action. Must be the same or greater than the sample_rate",
  127.               "minimum": 1,
  128.               "maximum": 86400,
  129.               "example": 86400
  130.             },
  131.             "response": {
  132.               "type": "object",
  133.               "description": "Custom content-type and body to return, this overrides the custom error for the zone",
  134.               "properties": {
  135.                 "content_type": {
  136.                   "type": "string",
  137.                   "description": "The content-type of the body, must be one of: text/plain text/xml application/javascript",
  138.                   "maxLength": 50,
  139.                   "example": "text/xml"
  140.                 },
  141.                 "body": {
  142.                   "type": "string",
  143.                   "description": "The body to return, the content here should conform to the content_type",
  144.                   "maxLength": 10240,
  145.                   "example": "<error>This request has been rate-limited.</error>"
  146.                 }
  147.               }
  148.             }
  149.           }
  150.         }
  151.       },
  152.     },
  153.     "ratelimit_response_single": {
  154.       "allOf": [
  155.         {
  156.           "$ref": "../../common/api-response-single.json"
  157.         },
  158.         {
  159.           "type": "object",
  160.           "properties": {
  161.             "result": {
  162.               "type": "object",
  163.               "rel": "self"
  164.             }
  165.           }
  166.         }
  167.       ]
  168.     },
  169.     "ratelimit_response_collection": {
  170.       "allOf": [
  171.         {
  172.           "$ref": "../../common/api-response-collection.json"
  173.         },
  174.         {
  175.           "type": "object",
  176.           "properties": {
  177.             "result": {
  178.               "type": "array",
  179.               "items": {
  180.                 "rel": "self"
  181.               }
  182.             }
  183.           }
  184.         }
  185.       ]
  186.     }
  187.   },
  188.  
  189.  
  190.   "links": [
  191.     {
  192.       "title": "List rate limits",
  193.       "description": "List, a zones' rate limits.",
  194.       "href": "/zones/{#/definitions/zone_identifier}/rate_limits",
  195.       "method": "GET",
  196.       "plan_availability": {
  197.         "free": true,
  198.         "pro": true,
  199.         "business": true,
  200.         "enterprise": true
  201.       },
  202.       "rel": "search",
  203.       "schema": {
  204.         "type": "object",
  205.         "properties": {
  206.           "page": {
  207.             "type": "number",
  208.             "description": "Page number of paginated results",
  209.             "minimum": 1,
  210.             "default": 1
  211.           },
  212.           "per_page": {
  213.             "type": "number",
  214.             "description": "Number of DNS records per page",
  215.             "minimum": 5,
  216.             "maximum": 100,
  217.             "default": 20
  218.           }
  219.         }
  220.       },
  221.       "targetSchema": {
  222.         "$ref": "#/definitions/ratelimit_response_collection"
  223.       }
  224.     },
  225.     {
  226.       "title": "Create a ratelimit",
  227.       "description": "Create a new rate limit for a zone. See the record object definitions for required attributes for each record type",
  228.       "href": "/zones/{#/definitions/zone_identifier}/rate_limits",
  229.       "method": "POST",
  230.       "plan_availability": {
  231.         "free": true,
  232.         "pro": true,
  233.         "business": true,
  234.         "enterprise": true
  235.       },
  236.       "rel": "create",
  237.       "required": [
  238.         "match",
  239.         "thresold",
  240.         "sample_rate",
  241.         "action"
  242.       ],
  243.       "schema": {
  244.         "type": {
  245.           "$ref": "#/definitions/ratelimit"
  246.         }
  247.       },
  248.       "targetSchema": {
  249.         "$ref": "#/definitions/ratelimit_response_single"
  250.       }
  251.     },
  252.     {
  253.       "title": "Rate limit details",
  254.       "href": "/zones/{#/definitions/zone_identifier}/rate_limits/{#/definitions/id}",
  255.       "method": "GET",
  256.       "plan_availability": {
  257.         "free": true,
  258.         "pro": true,
  259.         "business": true,
  260.         "enterprise": true
  261.       },
  262.       "rel": "self",
  263.       "permissions_required": {
  264.         "enum": [
  265.           "#dns_records:read"
  266.         ]
  267.       },
  268.       "targetSchema": {
  269.         "$ref": "#/definitions/ratelimit_response_single"
  270.       }
  271.     },
  272.     {
  273.       "title": "Update rate limit",
  274.       "href": "/zones/{#/definitions/zone_identifier}/rate_limits/{#/definitions/id}",
  275.       "method": "PUT",
  276.       "plan_availability": {
  277.         "free": true,
  278.         "pro": true,
  279.         "business": true,
  280.         "enterprise": true
  281.       },
  282.       "rel": "update",
  283.       "required": [
  284.         "match",
  285.         "thresold",
  286.         "sample_rate",
  287.         "action"
  288.       ],
  289.       "schema": {
  290.         "type": {
  291.           "$ref": "#/definitions/ratelimit"
  292.         }
  293.       },
  294.       "targetSchema": {
  295.         "$ref": "#/definitions/ratelimit_response_single"
  296.       }
  297.     },
  298.     {
  299.       "title": "Delete rate limit",
  300.       "href": "/zones/{#/definitions/zone_identifier}/rate_limits/{#/definitions/id}",
  301.       "method": "DELETE",
  302.       "plan_availability": {
  303.         "free": true,
  304.         "pro": true,
  305.         "business": true,
  306.         "enterprise": true
  307.       },
  308.       "rel": "destroy",
  309.       "targetSchema": {
  310.         "allOf": [
  311.           {
  312.             "$ref": "#/definitions/ratelimit_response_single"
  313.           },
  314.           {
  315.             "type": "object",
  316.             "properties": {
  317.               "result": {
  318.                 "properties": {
  319.                   "ID": {
  320.                     "$ref": "#/definitions/identifier"
  321.                   }
  322.                 }
  323.               }
  324.             }
  325.           }
  326.         ]
  327.       }
  328.     }
  329.   ],
  330.   "link_errors": {
  331.     "10000": "Invalid user",
  332.     "10001": "Rate limit not found",
  333.     "10002": "Rate limit not unique (edit the existing rather than adding a new)",
  334.     "10004": "Invalid data submitted",
  335.     "10006": "Auth missing",
  336.     "10007": "Auth corrupt",
  337.     "10008": "Auth expired",
  338.     "10009": "Unauthorized",
  339.     "10010": "Time param not valid",
  340.     "10011": "Pagination results in empty page",
  341.     "10012": "URL Param incorrect format",
  342.     "10013": "Patch values not valid",
  343.     "10014": "Patch operation not valid",
  344.     "10015": "Patch value not valid for given context",
  345.     "10016": "Patch not valid",
  346.   }
  347. }
  348.  
  349. Example:
  350. curl -X POST "https://api.cloudflare.com/client/v4/zones/5207aada36fd2c12d971c05c4e353e5f/rate_limits" \
  351. -H "X-Auth-Email: [email protected]" \
  352. -H "X-Auth-Key: yourkeygoeshere" \
  353. -H "Content-Type: application/json" \
  354. -d '{
  355. "match": {
  356. "request": {
  357. "methods": [
  358. "_ALL_"
  359. ],
  360. "schemes": [
  361. "_ALL_"
  362. ],
  363. "url": "*kschwenkler.com/about*"
  364. }
  365. },
  366. "threshold": 50,
  367. "period": 300,
  368. "action": {
  369. "mode": "ban",
  370. "timeout": 600,
  371. "response": {
  372. "content_type": "text/html",
  373. "body": "Rate Limit Exceeded!"
  374. }
  375. }
  376. }'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement