Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(313)

Side by Side Diff: content/public/common/page_state.cc

Issue 948013002: When sanitizing serialized navigation entries also take iframes into account (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/sessions/content/content_serialized_navigation_driver.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/public/common/page_state.h" 5 #include "content/public/common/page_state.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "content/common/page_state_serialization.h" 9 #include "content/common/page_state_serialization.h"
10 #include "content/public/common/referrer.h"
10 11
11 namespace content { 12 namespace content {
12 namespace { 13 namespace {
13 14
14 base::NullableString16 ToNullableString16(const std::string& utf8) { 15 base::NullableString16 ToNullableString16(const std::string& utf8) {
15 return base::NullableString16(base::UTF8ToUTF16(utf8), false); 16 return base::NullableString16(base::UTF8ToUTF16(utf8), false);
16 } 17 }
17 18
18 base::FilePath ToFilePath(const base::NullableString16& s) { 19 base::FilePath ToFilePath(const base::NullableString16& s) {
19 return base::FilePath::FromUTF16Unsafe(s.string()); 20 return base::FilePath::FromUTF16Unsafe(s.string());
(...skipping 28 matching lines...) Expand all
48 void RecursivelyRemoveReferrer(ExplodedFrameState* state) { 49 void RecursivelyRemoveReferrer(ExplodedFrameState* state) {
49 state->referrer = base::NullableString16(); 50 state->referrer = base::NullableString16();
50 state->referrer_policy = blink::WebReferrerPolicyDefault; 51 state->referrer_policy = blink::WebReferrerPolicyDefault;
51 for (std::vector<ExplodedFrameState>::iterator it = state->children.begin(); 52 for (std::vector<ExplodedFrameState>::iterator it = state->children.begin();
52 it != state->children.end(); 53 it != state->children.end();
53 ++it) { 54 ++it) {
54 RecursivelyRemoveReferrer(&*it); 55 RecursivelyRemoveReferrer(&*it);
55 } 56 }
56 } 57 }
57 58
59 bool RecursivelyCheckReferrer(ExplodedFrameState* state) {
60 Referrer referrer(GURL(state->referrer.string()), state->referrer_policy);
61 GURL url(state->url_string.string());
62 if (url.SchemeIsHTTPOrHTTPS() &&
63 Referrer::SanitizeForRequest(url, referrer).url != referrer.url) {
64 LOG(ERROR) << "Referrer for request to " << url << " is " << referrer.url
65 << " but should be "
66 << Referrer::SanitizeForRequest(url, referrer).url;
67 return false;
68 }
69 for (std::vector<ExplodedFrameState>::iterator it = state->children.begin();
70 it != state->children.end();
71 ++it) {
72 if (!RecursivelyCheckReferrer(&*it))
73 return false;
74 }
75 return true;
76 }
77
58 } // namespace 78 } // namespace
59 79
60 // static 80 // static
61 PageState PageState::CreateFromEncodedData(const std::string& data) { 81 PageState PageState::CreateFromEncodedData(const std::string& data) {
62 return PageState(data); 82 return PageState(data);
63 } 83 }
64 84
65 // static 85 // static
66 PageState PageState::CreateFromURL(const GURL& url) { 86 PageState PageState::CreateFromURL(const GURL& url) {
67 ExplodedPageState state; 87 ExplodedPageState state;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 body_contains_password_data; 121 body_contains_password_data;
102 } 122 }
103 123
104 return ToPageState(state); 124 return ToPageState(state);
105 } 125 }
106 126
107 PageState::PageState() { 127 PageState::PageState() {
108 } 128 }
109 129
110 bool PageState::IsValid() const { 130 bool PageState::IsValid() const {
111 return !data_.empty(); 131 if (data_.empty())
132 return false;
133
134 ExplodedPageState state;
135 // This should return false, but tests create invalid page state.
136 if (!DecodePageState(data_, &state))
marja 2015/02/23 15:30:04 What happens to data_ here? Should this branch set
jochen (gone - plz use gerrit) 2015/02/23 16:20:45 IsValid() is not supposed to modify itself (it's c
137 return true;
138
139 // TODO(jochen): Remove referrer check once http://crbug.com/450589 is fixed.
140 return RecursivelyCheckReferrer(&state.top);
112 } 141 }
113 142
114 bool PageState::Equals(const PageState& other) const { 143 bool PageState::Equals(const PageState& other) const {
115 return data_ == other.data_; 144 return data_ == other.data_;
116 } 145 }
117 146
118 const std::string& PageState::ToEncodedData() const { 147 const std::string& PageState::ToEncodedData() const {
119 return data_; 148 return data_;
120 } 149 }
121 150
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 } 192 }
164 193
165 PageState::PageState(const std::string& data) 194 PageState::PageState(const std::string& data)
166 : data_(data) { 195 : data_(data) {
167 // TODO(darin): Enable this DCHECK once tests have been fixed up to not pass 196 // TODO(darin): Enable this DCHECK once tests have been fixed up to not pass
168 // bogus encoded data to CreateFromEncodedData. 197 // bogus encoded data to CreateFromEncodedData.
169 //DCHECK(IsValid()); 198 //DCHECK(IsValid());
170 } 199 }
171 200
172 } // namespace content 201 } // namespace content
OLDNEW
« no previous file with comments | « components/sessions/content/content_serialized_navigation_driver.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698