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

Side by Side Diff: Source/core/html/parser/XSSAuditor.cpp

Issue 23464095: WTF::notFound looks too much like a local variable. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Adam Barth. All Rights Reserved. 2 * Copyright (C) 2011 Adam Barth. All Rights Reserved.
3 * Copyright (C) 2011 Daniel Bates (dbates@intudata.com). 3 * Copyright (C) 2011 Daniel Bates (dbates@intudata.com).
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 254
255 if (m_documentURL.protocolIsData()) { 255 if (m_documentURL.protocolIsData()) {
256 m_isEnabled = false; 256 m_isEnabled = false;
257 return; 257 return;
258 } 258 }
259 259
260 if (document->encoding().isValid()) 260 if (document->encoding().isValid())
261 m_encoding = document->encoding(); 261 m_encoding = document->encoding();
262 262
263 m_decodedURL = fullyDecodeString(m_documentURL.string(), m_encoding); 263 m_decodedURL = fullyDecodeString(m_documentURL.string(), m_encoding);
264 if (m_decodedURL.find(isRequiredForInjection) == notFound) 264 if (m_decodedURL.find(isRequiredForInjection) == kNotFound)
265 m_decodedURL = String(); 265 m_decodedURL = String();
266 266
267 String httpBodyAsString; 267 String httpBodyAsString;
268 if (DocumentLoader* documentLoader = document->frame()->loader()->documentLo ader()) { 268 if (DocumentLoader* documentLoader = document->frame()->loader()->documentLo ader()) {
269 DEFINE_STATIC_LOCAL(String, XSSProtectionHeader, ("X-XSS-Protection")); 269 DEFINE_STATIC_LOCAL(String, XSSProtectionHeader, ("X-XSS-Protection"));
270 String headerValue = documentLoader->response().httpHeaderField(XSSProte ctionHeader); 270 String headerValue = documentLoader->response().httpHeaderField(XSSProte ctionHeader);
271 String errorDetails; 271 String errorDetails;
272 unsigned errorPosition = 0; 272 unsigned errorPosition = 0;
273 String reportURL; 273 String reportURL;
274 KURL xssProtectionReportURL; 274 KURL xssProtectionReportURL;
(...skipping 17 matching lines...) Expand all
292 292
293 m_xssProtection = combineXSSProtectionHeaderAndCSP(xssProtectionHeader, cspHeader); 293 m_xssProtection = combineXSSProtectionHeaderAndCSP(xssProtectionHeader, cspHeader);
294 // FIXME: Combine the two report URLs in some reasonable way. 294 // FIXME: Combine the two report URLs in some reasonable way.
295 if (auditorDelegate) 295 if (auditorDelegate)
296 auditorDelegate->setReportURL(xssProtectionReportURL.copy()); 296 auditorDelegate->setReportURL(xssProtectionReportURL.copy());
297 FormData* httpBody = documentLoader->originalRequest().httpBody(); 297 FormData* httpBody = documentLoader->originalRequest().httpBody();
298 if (httpBody && !httpBody->isEmpty()) { 298 if (httpBody && !httpBody->isEmpty()) {
299 httpBodyAsString = httpBody->flattenToString(); 299 httpBodyAsString = httpBody->flattenToString();
300 if (!httpBodyAsString.isEmpty()) { 300 if (!httpBodyAsString.isEmpty()) {
301 m_decodedHTTPBody = fullyDecodeString(httpBodyAsString, m_encodi ng); 301 m_decodedHTTPBody = fullyDecodeString(httpBodyAsString, m_encodi ng);
302 if (m_decodedHTTPBody.find(isRequiredForInjection) == notFound) 302 if (m_decodedHTTPBody.find(isRequiredForInjection) == kNotFound)
303 m_decodedHTTPBody = String(); 303 m_decodedHTTPBody = String();
304 if (m_decodedHTTPBody.length() >= miniumLengthForSuffixTree) 304 if (m_decodedHTTPBody.length() >= miniumLengthForSuffixTree)
305 m_decodedHTTPBodySuffixTree = adoptPtr(new SuffixTree<ASCIIC odebook>(m_decodedHTTPBody, suffixTreeDepth)); 305 m_decodedHTTPBodySuffixTree = adoptPtr(new SuffixTree<ASCIIC odebook>(m_decodedHTTPBody, suffixTreeDepth));
306 } 306 }
307 } 307 }
308 } 308 }
309 309
310 if (m_decodedURL.isEmpty() && m_decodedHTTPBody.isEmpty()) { 310 if (m_decodedURL.isEmpty() && m_decodedHTTPBody.isEmpty()) {
311 m_isEnabled = false; 311 m_isEnabled = false;
312 return; 312 return;
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 // closing punctuation. Since the snippet has not been parsed, the vecto r 604 // closing punctuation. Since the snippet has not been parsed, the vecto r
605 // may also try to introduce these via entities. As a result, we'd like to 605 // may also try to introduce these via entities. As a result, we'd like to
606 // stop before the first "//", the first <!--, the first entity, or the first 606 // stop before the first "//", the first <!--, the first entity, or the first
607 // quote not immediately following the first equals sign (taking whitesp ace 607 // quote not immediately following the first equals sign (taking whitesp ace
608 // into consideration). To keep things simpler, we don't try to distingu ish 608 // into consideration). To keep things simpler, we don't try to distingu ish
609 // between entity-introducing amperands vs. other uses, nor do we bother to 609 // between entity-introducing amperands vs. other uses, nor do we bother to
610 // check for a second slash for a comment, nor do we bother to check for 610 // check for a second slash for a comment, nor do we bother to check for
611 // !-- following a less-than sign. We stop instead on any ampersand 611 // !-- following a less-than sign. We stop instead on any ampersand
612 // slash, or less-than sign. 612 // slash, or less-than sign.
613 size_t position = 0; 613 size_t position = 0;
614 if ((position = decodedSnippet.find("=")) != notFound 614 if ((position = decodedSnippet.find("=")) != kNotFound
615 && (position = decodedSnippet.find(isNotHTMLSpace, position + 1)) != notFound 615 && (position = decodedSnippet.find(isNotHTMLSpace, position + 1)) != kNotFound
616 && (position = decodedSnippet.find(isTerminatingCharacter, isHTMLQuo te(decodedSnippet[position]) ? position + 1 : position)) != notFound) { 616 && (position = decodedSnippet.find(isTerminatingCharacter, isHTMLQuo te(decodedSnippet[position]) ? position + 1 : position)) != kNotFound) {
617 decodedSnippet.truncate(position); 617 decodedSnippet.truncate(position);
618 } 618 }
619 } 619 }
620 return decodedSnippet; 620 return decodedSnippet;
621 } 621 }
622 622
623 String XSSAuditor::decodedSnippetForJavaScript(const FilterTokenRequest& request ) 623 String XSSAuditor::decodedSnippetForJavaScript(const FilterTokenRequest& request )
624 { 624 {
625 String string = request.sourceTracker.sourceForToken(request.token); 625 String string = request.sourceTracker.sourceForToken(request.token);
626 size_t startPosition = 0; 626 size_t startPosition = 0;
627 size_t endPosition = string.length(); 627 size_t endPosition = string.length();
628 size_t foundPosition = notFound; 628 size_t foundPosition = kNotFound;
629 629
630 // Skip over initial comments to find start of code. 630 // Skip over initial comments to find start of code.
631 while (startPosition < endPosition) { 631 while (startPosition < endPosition) {
632 while (startPosition < endPosition && isHTMLSpace(string[startPosition]) ) 632 while (startPosition < endPosition && isHTMLSpace(string[startPosition]) )
633 startPosition++; 633 startPosition++;
634 634
635 // Under SVG/XML rules, only HTML comment syntax matters and the parser returns 635 // Under SVG/XML rules, only HTML comment syntax matters and the parser returns
636 // these as a separate comment tokens. Having consumed whitespace, we ne ed not look 636 // these as a separate comment tokens. Having consumed whitespace, we ne ed not look
637 // further for these. 637 // further for these.
638 if (request.shouldAllowCDATA) 638 if (request.shouldAllowCDATA)
639 break; 639 break;
640 640
641 // Under HTML rules, both the HTML and JS comment synatx matters, and th e HTML 641 // Under HTML rules, both the HTML and JS comment synatx matters, and th e HTML
642 // comment ends at the end of the line, not with -->. 642 // comment ends at the end of the line, not with -->.
643 if (startsHTMLCommentAt(string, startPosition) || startsSingleLineCommen tAt(string, startPosition)) { 643 if (startsHTMLCommentAt(string, startPosition) || startsSingleLineCommen tAt(string, startPosition)) {
644 while (startPosition < endPosition && !isJSNewline(string[startPosit ion])) 644 while (startPosition < endPosition && !isJSNewline(string[startPosit ion]))
645 startPosition++; 645 startPosition++;
646 } else if (startsMultiLineCommentAt(string, startPosition)) { 646 } else if (startsMultiLineCommentAt(string, startPosition)) {
647 if (startPosition + 2 < endPosition && (foundPosition = string.find( "*/", startPosition + 2)) != notFound) 647 if (startPosition + 2 < endPosition && (foundPosition = string.find( "*/", startPosition + 2)) != kNotFound)
648 startPosition = foundPosition + 2; 648 startPosition = foundPosition + 2;
649 else 649 else
650 startPosition = endPosition; 650 startPosition = endPosition;
651 } else 651 } else
652 break; 652 break;
653 } 653 }
654 654
655 String result; 655 String result;
656 while (startPosition < endPosition && !result.length()) { 656 while (startPosition < endPosition && !result.length()) {
657 // Stop at next comment (using the same rules as above for SVG/XML vs HT ML), when we 657 // Stop at next comment (using the same rules as above for SVG/XML vs HT ML), when we
(...skipping 22 matching lines...) Expand all
680 result = fullyDecodeString(string.substring(startPosition, foundPosition - startPosition), m_encoding); 680 result = fullyDecodeString(string.substring(startPosition, foundPosition - startPosition), m_encoding);
681 startPosition = foundPosition + 1; 681 startPosition = foundPosition + 1;
682 } 682 }
683 return result; 683 return result;
684 } 684 }
685 685
686 bool XSSAuditor::isContainedInRequest(const String& decodedSnippet) 686 bool XSSAuditor::isContainedInRequest(const String& decodedSnippet)
687 { 687 {
688 if (decodedSnippet.isEmpty()) 688 if (decodedSnippet.isEmpty())
689 return false; 689 return false;
690 if (m_decodedURL.find(decodedSnippet, 0, false) != notFound) 690 if (m_decodedURL.find(decodedSnippet, 0, false) != kNotFound)
691 return true; 691 return true;
692 if (m_decodedHTTPBodySuffixTree && !m_decodedHTTPBodySuffixTree->mightContai n(decodedSnippet)) 692 if (m_decodedHTTPBodySuffixTree && !m_decodedHTTPBodySuffixTree->mightContai n(decodedSnippet))
693 return false; 693 return false;
694 return m_decodedHTTPBody.find(decodedSnippet, 0, false) != notFound; 694 return m_decodedHTTPBody.find(decodedSnippet, 0, false) != kNotFound;
695 } 695 }
696 696
697 bool XSSAuditor::isLikelySafeResource(const String& url) 697 bool XSSAuditor::isLikelySafeResource(const String& url)
698 { 698 {
699 // Give empty URLs and about:blank a pass. Making a resourceURL from an 699 // Give empty URLs and about:blank a pass. Making a resourceURL from an
700 // empty string below will likely later fail the "no query args test" as 700 // empty string below will likely later fail the "no query args test" as
701 // it inherits the document's query args. 701 // it inherits the document's query args.
702 if (url.isEmpty() || url == blankURL().string()) 702 if (url.isEmpty() || url == blankURL().string())
703 return true; 703 return true;
704 704
(...skipping 11 matching lines...) Expand all
716 } 716 }
717 717
718 bool XSSAuditor::isSafeToSendToAnotherThread() const 718 bool XSSAuditor::isSafeToSendToAnotherThread() const
719 { 719 {
720 return m_documentURL.isSafeToSendToAnotherThread() 720 return m_documentURL.isSafeToSendToAnotherThread()
721 && m_decodedURL.isSafeToSendToAnotherThread() 721 && m_decodedURL.isSafeToSendToAnotherThread()
722 && m_decodedHTTPBody.isSafeToSendToAnotherThread(); 722 && m_decodedHTTPBody.isSafeToSendToAnotherThread();
723 } 723 }
724 724
725 } // namespace WebCore 725 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/html/parser/HTMLMetaCharsetParser.cpp ('k') | Source/core/html/track/TextTrackCue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698