Skip to content

Instantly share code, notes, and snippets.

@Vizonex
Last active August 30, 2023 00:36
Show Gist options
  • Select an option

  • Save Vizonex/49c010b7e0babd0484853e0e560a3645 to your computer and use it in GitHub Desktop.

Select an option

Save Vizonex/49c010b7e0babd0484853e0e560a3645 to your computer and use it in GitHub Desktop.
Used to Parse and Diagnose Cloudflare Errors coming from either "error code:" or "error:"
/*
The MIT License (MIT)
Copyright © 2023 Vizonex
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the “Software”), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall
be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdlib.h>
#include <string.h>
/*
This Libarary is Cross Compatable with C and C++ Applications
You could also Try to use this in Cython and Python if you really wanted.
Also I added CF_0__OK which is not in the error list
just to tell your program that it is safe to proceed
*/
/*
Made For helping Diagnose a lot of possible CloudFlare Problems Possible to the Web
Application Firewall This enum list was developed for webscrapers like you :)
Note that this only includes 1XXX and 5XX Error Types
*/
enum CloudFlare_Error_Flag
{
// Everything is Good , Proceed as normal
CF_0__OK = 0,
// 5XX
CF_500__Internal_Server_ERR = 500,
CF_502__Badgateway = 502,
CF_503__service_temporarily_unavailable,
CF_504__GatewayTimeout,
CF_520__unknown_error = 520,
CF_521__Server_Down,
CF_522__connection_timed_out,
CF_523__origin_is_unreachable,
CF_525__SSL_handshake_failed = 525,
CF_526__invalid_SSL_certificate,
CF_527__Railgun_Listener_to_origin_error,
// 1XXX
CF_1000__IP_PROHIBITED = 1000,
CF_1001__DNS_RES_ERR,
CF_1002__Restricted,
CF_1003__Direct_IP_Access_Not_Allowed,
CF_1004__Incorrect_Config,
CF_1005__Banned__Autonomous_System,
CF_1006__Banned__Zone_Lockdown,
CF_1007__IP_Banned,
CF_1008__IP_Banned,
CF_1009__Banned__Region_Blocked,
CF_1010__Banned__Owner_Says_Bad_Browser_Config,
CF_1011__Access_Denied___Hotlinking_Denied,
CF_1012__Access_Denied,
CF_1013__Hostname_Mismatch,
CF_1014__Banned__CNAME_Cross_User,
CF_1015__RATE_LIMIT,
CF_1016__Origin_DNS_ERR,
CF_1018__Couldnt_find_host = 1018,
CF_1019__Compute_Server_ERR,
CF_1020__Access_Denied,
CF_1023__Couldnt_Find_Host,
CF_1025__Please_Check_Back_Later = 1025,
CF_1033__Argo_Tunner_ERR = 1033,
CF_1034__Edge_IP_Restricted,
CF_1035__invalid_URI_path,
CF_1036__max_len_exceeded,
CF_1037__expression_eavl_Failure,
CF_1040__header_modification_not_allowed = 1040,
CF_1041__invalid_header_value,
CF_1101__Render_ERR = 1101,
CF_1102__Render_ERR,
CF_1104__Email_Taken = 1104,
CF_1200__Cache_Connection_Limit = 1200
};
typedef enum CloudFlare_Error_Flag CloudFlare_Error_Flag_t;
/* Added Special Map function like the ones seen in libuv and llhttp */
#define CloudFlare_Error_Flag_MAP(XX) \
XX(0, CF_0__OK, CF_0__OK) \
XX(500, CF_500__Internal_Server_ERR, CF_500__Internal_Server_ERR) \
XX(502, CF_502__Badgateway, CF_502__Badgateway) \
XX(503, CF_503__service_temporarily_unavailable, CF_503__service_temporarily_unavailable) \
XX(504, CF_504__GatewayTimeout, CF_504__GatewayTimeout) \
XX(520, CF_520__unknown_error, CF_520__unknown_error) \
XX(521, CF_521__Server_Down, CF_521__Server_Down) \
XX(522, CF_522__connection_timed_out, CF_522__connection_timed_out) \
XX(523, CF_523__origin_is_unreachable, CF_523__origin_is_unreachable) \
XX(525, CF_525__SSL_handshake_failed, CF_525__SSL_handshake_failed) \
XX(526, CF_526__invalid_SSL_certificate, CF_526__invalid_SSL_certificate) \
XX(527, CF_527__Railgun_Listener_to_origin_error, CF_527__Railgun_Listener_to_origin_error) \
XX(1000, CF_1000__IP_PROHIBITED, CF_1000__IP_PROHIBITED) \
XX(1001, CF_1001__DNS_RES_ERR, CF_1001__DNS_RES_ERR) \
XX(1002, CF_1002__Restricted, CF_1002__Restricted) \
XX(1003, CF_1003__Direct_IP_Access_Not_Allowed, CF_1003__Direct_IP_Access_Not_Allowed) \
XX(1004, CF_1004__Incorrect_Config, CF_1004__Incorrect_Config) \
XX(1005, CF_1005__Banned__Autonomous_System, CF_1005__Banned__Autonomous_System) \
XX(1006, CF_1006__Banned__Zone_Lockdown, CF_1006__Banned__Zone_Lockdown) \
XX(1007, CF_1007__IP_Banned, CF_1007__IP_Banned) \
XX(1008, CF_1008__IP_Banned, CF_1008__IP_Banned) \
XX(1009, CF_1009__Banned__Region_Blocked, CF_1009__Banned__Region_Blocked) \
XX(1010, CF_1010__Banned__Owner_Says_Bad_Browser_Config, CF_1010__Banned__Owner_Says_Bad_Browser_Config) \
XX(1011, CF_1011__Access_Denied___Hotlinking_Denied, CF_1011__Access_Denied___Hotlinking_Denied) \
XX(1012, CF_1012__Access_Denied, CF_1012__Access_Denied) \
XX(1013, CF_1013__Hostname_Mismatch, CF_1013__Hostname_Mismatch) \
XX(1014, CF_1014__Banned__CNAME_Cross_User, CF_1014__Banned__CNAME_Cross_User) \
XX(1015, CF_1015__RATE_LIMIT, CF_1015__RATE_LIMIT) \
XX(1016, CF_1016__Origin_DNS_ERR, CF_1016__Origin_DNS_ERR) \
XX(1018, CF_1018__Couldnt_find_host, CF_1018__Couldnt_find_host) \
XX(1019, CF_1019__Compute_Server_ERR, CF_1019__Compute_Server_ERR) \
XX(1020, CF_1020__Access_Denied, CF_1020__Access_Denied) \
XX(1021, CF_1023__Couldnt_Find_Host, CF_1023__Couldnt_Find_Host) \
XX(1025, CF_1025__Please_Check_Back_Later, CF_1025__Please_Check_Back_Later) \
XX(1033, CF_1033__Argo_Tunner_ERR, CF_1033__Argo_Tunner_ERR) \
XX(1035, CF_1035__invalid_URI_path, CF_1035__invalid_URI_path) \
XX(1036, CF_1036__max_len_exceeded, CF_1036__max_len_exceeded) \
XX(1037, CF_1037__expression_eavl_Failure, CF_1037__expression_eavl_Failure) \
XX(1040, CF_1040__header_modification_not_allowed, CF_1040__header_modification_not_allowed) \
XX(1041, CF_1041__invalid_header_value, CF_1041__invalid_header_value) \
XX(1101, CF_1101__Render_ERR, CF_1101__Render_ERR) \
XX(1102, CF_1102__Render_ERR, CF_1102__Render_ERR) \
XX(1104, CF_1104__Email_Taken, CF_1104__Email_Taken) \
XX(1200, CF_1200__Cache_Connection_Limit, CF_1200__Cache_Connection_Limit) \
/*
Used for attempting to verify if everything is safe to continue
Note that this may not catch everything but It will definately catch things
like ratelimits in an http response
*/
CloudFlare_Error_Flag_t Check_for_CloudFlare_Errors(const char* content, size_t content_length){
/* "error code:" or "error:" You cannot fool us cloudflare */
if (content_length > 16 || content[0] != 'e'){
return CF_0__OK;
}
else {
/* TODO (Vizonex) Implement a reverse atoi that checks for ':' before ending...*/
char* error_number = (char*)malloc((sizeof(char) * (content_length - 6) ) + 1);
memcpy(error_number,content + 6, content_length - 6);
return atoi((const char*)error_number);
}
};
/* Obtains the enum's name as a string */
const char* CloudFlare_Error_Flag_name(CloudFlare_Error_Flag_t error_num){
#define CloudFlare_Error_Flag_MAP_GEN(NUM, NAME, STRING) case NAME: return #STRING;
switch (error_num) {
CloudFlare_Error_Flag_MAP(CloudFlare_Error_Flag_MAP_GEN)
default: "CF_UNKNOWN";
}
#undef CloudFlare_Error_Flag_MAP_GEN
}
@Vizonex

Vizonex commented Jan 7, 2023 •

Copy link
Copy Markdown
Author

I thought this may have been useless at first but then I realized just how many websites use cloudflare as a firewall so I decided to upload this script anyways. Maybe It can be help for some of you. I definitely should make a better parser function in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment