| 3174 | } |
| 3175 | |
| 3176 | static bool request_passes_http_security(cbm_http_server_t *srv, cbm_http_conn_t *c, |
| 3177 | const cbm_http_req_t *req) { |
| 3178 | if (req->http_minor == 1 && req->host[0] == '\0') { |
| 3179 | cbm_http_replyf(c, 400, "", "%s", "{\"error\":\"Host header required\"}"); |
| 3180 | return false; |
| 3181 | } |
| 3182 | if (req->host[0] != '\0' && !host_is_this_server(req->host, srv->port)) { |
| 3183 | cbm_http_replyf(c, 403, "", "%s", "{\"error\":\"forbidden host\"}"); |
| 3184 | return false; |
| 3185 | } |
| 3186 | if (req->origin[0] != '\0' && |
| 3187 | (req->host[0] == '\0' || !origin_is_same_server(req->origin, srv->port) || |
| 3188 | !origin_matches_host(req->origin, req->host, srv->port))) { |
| 3189 | cbm_http_replyf(c, 403, "", "%s", "{\"error\":\"forbidden origin\"}"); |
| 3190 | return false; |
| 3191 | } |
| 3192 | update_cors(req, srv->port); |
| 3193 | bool is_post = strcmp(req->method, "POST") == 0; |
| 3194 | if (route_is_protected(req->path) && is_post && !content_type_is_json(req->content_type)) { |
| 3195 | cbm_http_replyf(c, 415, g_cors_json, "%s", "{\"error\":\"application/json required\"}"); |
| 3196 | return false; |
| 3197 | } |
| 3198 | return true; |
| 3199 | } |
| 3200 | |
| 3201 | static void dispatch_request(cbm_http_server_t *srv, cbm_http_conn_t *c, |
| 3202 | const cbm_http_req_t *req) { |
no test coverage detected