| 307 | } |
| 308 | |
| 309 | void HTTPReqHandler::SanitizeHTTPRequest(i2p::http::HTTPReq& req) |
| 310 | { |
| 311 | /* drop common headers */ |
| 312 | req.RemoveHeader("Via"); |
| 313 | req.RemoveHeader("From"); |
| 314 | req.RemoveHeader("Forwarded"); |
| 315 | req.RemoveHeader("DNT"); // Useless DoNotTrack flag |
| 316 | req.RemoveHeader("Accept", "Accept-Encoding"); // Accept*, but Accept-Encoding |
| 317 | /* drop proxy-disclosing headers */ |
| 318 | req.RemoveHeader("X-Forwarded"); |
| 319 | req.RemoveHeader("Proxy-"); // Proxy-* |
| 320 | /* replace headers */ |
| 321 | if (!m_SendUserAgent) |
| 322 | req.UpdateHeader("User-Agent", "MYOB/6.66 (AN/ON)"); |
| 323 | |
| 324 | /** |
| 325 | * i2pd PR #1816: |
| 326 | * Android Webview send this with the value set to the application ID, so we drop it, |
| 327 | * but only if it does not belong to an AJAX request (*HttpRequest, like XMLHttpRequest). |
| 328 | */ |
| 329 | if(req.GetHeader("X-Requested-With") != "") { |
| 330 | auto h = req.GetHeader ("X-Requested-With"); |
| 331 | auto x = h.find("HttpRequest"); |
| 332 | if (x == std::string::npos) // not found |
| 333 | req.RemoveHeader("X-Requested-With"); |
| 334 | } |
| 335 | |
| 336 | /** |
| 337 | * according to i2p ticket #1862: |
| 338 | * leave Referer if requested URL with same schema, host and port, |
| 339 | * otherwise, drop it. |
| 340 | */ |
| 341 | if(req.GetHeader("Referer") != "") { |
| 342 | i2p::http::URL reqURL; reqURL.parse(req.uri); |
| 343 | i2p::http::URL refURL; refURL.parse(req.GetHeader("Referer")); |
| 344 | if(!boost::iequals(reqURL.schema, refURL.schema) || !boost::iequals(reqURL.host, refURL.host) || reqURL.port != refURL.port) |
| 345 | req.RemoveHeader("Referer"); |
| 346 | } |
| 347 | |
| 348 | /* add headers */ |
| 349 | /* close connection, if not Connection: (U|u)pgrade (for websocket) */ |
| 350 | auto h = req.GetHeader ("Connection"); |
| 351 | auto x = h.find("pgrade"); |
| 352 | if (!(x != std::string::npos && std::tolower(h[x - 1]) == 'u')) |
| 353 | req.UpdateHeader("Connection", "close"); |
| 354 | } |
| 355 | |
| 356 | /** |
| 357 | * @brief Try to parse request from @a m_recv_buf |
nothing calls this directly
no test coverage detected