char *file; /* file of the declaration */
};
+/* description of a check to be done in the HTTP stack:
+ * - rules = mask of the checks to apply (comes from the profile) ;
+ * - found = mask of checks met even if not blocked, preset to zero
+ * before the call and filled by the stack ;
+ * - fixed = mask of actions performed
+ */
+struct http_hdng_chk {
+ uint32_t rules; // rules to apply
+ uint32_t found; // what was found
+ uint32_t fixed; // mask of actions performed
+};
+
#endif /* _HAPROXY_HTTP_T_H */
/*
extern struct http_hdng_prf http_hardening_untrusted;
extern struct http_hdng_prf http_hardening_trusted;
+extern THREAD_LOCAL struct http_hdng_chk http_hdng_chk;
+
enum http_meth_t find_http_meth(const char *str, const int len);
int http_get_status_idx(unsigned int status);
const char *http_get_reason(unsigned int status);
return c == '&' || c == ';' || c == delim;
}
+/* reset an http hardening check after a call */
+static inline void http_reset_hardening_check(struct http_hdng_chk *chk)
+{
+ chk->rules = 0;
+ chk->found = 0;
+ chk->fixed = 0;
+}
+
+/* marks the global http_hdng_chk.found with the provided check, then checks if this
+ * test is enabled or not. If so, it will put it in the hardening fixed value
+ * and return true, otherwise it will return false. This allows to construct
+ * simple checks like this and have all fields properly filled:
+ *
+ * if (unlikely(smiley_in_header_name))
+ * if (http_harden(HTTP_HRD_SMILEY_HNAME))
+ * goto fail;
+ *
+ * Make sure to pass it single-bit options to keep found/fixed easy to grasp.
+ */
+static inline int http_harden(uint32_t flag)
+{
+ http_hdng_chk.found |= flag;
+ if (!(http_hdng_chk.rules & flag))
+ return 0;
+ http_hdng_chk.fixed |= flag;
+ return 1;
+}
+
/* Match language range with language tag. RFC2616 14.4:
*
* A language-range matches a language-tag if it exactly equals
long http_err_status_codes[512 / sizeof(long)] = { };
long http_fail_status_codes[512 / sizeof(long)] = { };
+/* hardening checks to be run through the HTTP stack, preset by the caller,
+ * must always be cleared by the one that sets or checks them after use.
+ */
+THREAD_LOCAL struct http_hdng_chk http_hdng_chk = { };
+
/*
* returns a known method among HTTP_METH_* or HTTP_METH_OTHER for all unknown
* ones.