sec_header_helpers.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef SERVICES_NETWORK_SEC_HEADER_HELPERS_H_
  5. #define SERVICES_NETWORK_SEC_HEADER_HELPERS_H_
  6. #include "base/component_export.h"
  7. #include "services/network/public/mojom/fetch_api.mojom-forward.h"
  8. #include "url/gurl.h"
  9. namespace net {
  10. class URLRequest;
  11. } // namespace net
  12. namespace network {
  13. namespace cors {
  14. class OriginAccessList;
  15. } // namespace cors
  16. namespace mojom {
  17. class URLLoaderFactoryParams;
  18. } // namespace mojom
  19. // Sets the right Sec-Fetch-Site request header on |request|, comparing the
  20. // origins of |request.url_chain()| and |pending_redirect_url| against
  21. // |request.initiator()|.
  22. //
  23. // Note that |pending_redirect_url| is optional - it should be set only when
  24. // calling this method from net::URLRequest::Delegate::OnReceivedRedirect (in
  25. // this case |request.url_chain()| won't yet contain the URL being redirected
  26. // to).
  27. //
  28. // Spec: https://w3c.github.io/webappsec-fetch-metadata/
  29. COMPONENT_EXPORT(NETWORK_SERVICE)
  30. void SetFetchMetadataHeaders(
  31. net::URLRequest* request,
  32. network::mojom::RequestMode mode,
  33. bool has_user_activation,
  34. network::mojom::RequestDestination dest,
  35. const GURL* pending_redirect_url,
  36. const mojom::URLLoaderFactoryParams& factory_params,
  37. const cors::OriginAccessList& origin_access_list);
  38. // Removes any sec-ch- or sec-fetch- prefixed request headers on the |request|
  39. // if the |pending_redirect_url| is not trustworthy and the current url is.
  40. COMPONENT_EXPORT(NETWORK_SERVICE)
  41. void MaybeRemoveSecHeaders(net::URLRequest* request,
  42. const GURL& pending_redirect_url);
  43. } // namespace network
  44. #endif // SERVICES_NETWORK_SEC_HEADER_HELPERS_H_