Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

Commit

Permalink
convert-meta-tags: don't allow newlines when converting meta tags.
Browse files Browse the repository at this point in the history
This change makes ResponseHeaders::MergeContentType reject values
containing unprintable characters.

Fixes #1083

This is Otto's work from #1196
  • Loading branch information
jeffkaufman committed Dec 17, 2015
1 parent b0ed9e4 commit 08cbf90
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions net/instaweb/rewriter/meta_tag_filter_test.cc
Expand Up @@ -67,6 +67,21 @@ TEST_F(MetaTagFilterTest, TestTags) {
<< *values[0];
}

const char kMetaTagDocInvalidAttribute[] =
"<html><head>"
"<meta http-equiv=\"Content-Type\" content=\"text/html;"
" charset=U\r\nTF-8\">"
"</head><body></body></html>";

TEST_F(MetaTagFilterTest, TestRejectInvalidAttribute) {
headers()->RemoveAll(HttpAttributes::kContentType);
ValidateNoChanges("convert_tags_invalid_attribute",
kMetaTagDocInvalidAttribute);
ConstStringStarVector values;
EXPECT_FALSE(headers()->Lookup(HttpAttributes::kContentType, &values));
ASSERT_EQ(0, values.size());
}

const char kMetaTagDoubleDoc[] =
"<html><head>"
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">"
Expand Down
6 changes: 6 additions & 0 deletions pagespeed/kernel/http/response_headers.cc
Expand Up @@ -321,6 +321,12 @@ bool ResponseHeaders::CombineContentTypes(const StringPiece& orig,
}

bool ResponseHeaders::MergeContentType(const StringPiece& content_type) {
for (size_t i = 0; i < content_type.size(); i++) {
if (!IsNonControlAscii(content_type[i])) {
return false;
}
}

bool ret = false;
ConstStringStarVector old_values;
Lookup(HttpAttributes::kContentType, &old_values);
Expand Down
2 changes: 2 additions & 0 deletions pagespeed/kernel/http/response_headers.h
Expand Up @@ -75,6 +75,8 @@ class ResponseHeaders : public Headers<HttpResponseHeaders> {

// Merge the new content_type with what is already in the headers.
// Returns true if the existing content-type header was changed.
// If the new content_type contains non-printable characters, the
// change will be rejected silently (and false will be returned).
bool MergeContentType(const StringPiece& content_type);

// Merge headers. Replaces all headers specified both here and in
Expand Down

0 comments on commit 08cbf90

Please sign in to comment.