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

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

Issue 124973004: Use data:, rather than about:blank as a substitute form action so the resulting blank page will hav… (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 11 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
« no previous file with comments | « LayoutTests/http/tests/security/xssAuditor/formaction-on-input-expected.txt ('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 /* 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 27 matching lines...) Expand all
38 #include "core/html/parser/HTMLDocumentParser.h" 38 #include "core/html/parser/HTMLDocumentParser.h"
39 #include "core/html/parser/HTMLParserIdioms.h" 39 #include "core/html/parser/HTMLParserIdioms.h"
40 #include "core/html/parser/XSSAuditorDelegate.h" 40 #include "core/html/parser/XSSAuditorDelegate.h"
41 #include "core/loader/DocumentLoader.h" 41 #include "core/loader/DocumentLoader.h"
42 #include "core/frame/Settings.h" 42 #include "core/frame/Settings.h"
43 #include "platform/JSONValues.h" 43 #include "platform/JSONValues.h"
44 #include "platform/network/FormData.h" 44 #include "platform/network/FormData.h"
45 #include "platform/text/DecodeEscapeSequences.h" 45 #include "platform/text/DecodeEscapeSequences.h"
46 #include "wtf/MainThread.h" 46 #include "wtf/MainThread.h"
47 47
48 namespace {
49
50 // SecurityOrigin::urlWithUniqueSecurityOrigin() can't be used cross-thread, or we'd use it instead.
51 const char kURLWithUniqueOrigin[] = "data:,";
52
53 } // namespace
54
48 namespace WebCore { 55 namespace WebCore {
49 56
50 using namespace HTMLNames; 57 using namespace HTMLNames;
51 58
52 static bool isNonCanonicalCharacter(UChar c) 59 static bool isNonCanonicalCharacter(UChar c)
53 { 60 {
54 // We remove all non-ASCII characters, including non-printable ASCII charact ers. 61 // We remove all non-ASCII characters, including non-printable ASCII charact ers.
55 // 62 //
56 // Note, we don't remove backslashes like PHP stripslashes(), which among ot her things converts "\\0" to the \0 character. 63 // Note, we don't remove backslashes like PHP stripslashes(), which among ot her things converts "\\0" to the \0 character.
57 // Instead, we remove backslashes and zeros (since the string "\\0" =(remove backslashes)=> "0"). However, this has the 64 // Instead, we remove backslashes and zeros (since the string "\\0" =(remove backslashes)=> "0"). However, this has the
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 ASSERT(hasName(request.token, baseTag)); 500 ASSERT(hasName(request.token, baseTag));
494 501
495 return eraseAttributeIfInjected(request, hrefAttr); 502 return eraseAttributeIfInjected(request, hrefAttr);
496 } 503 }
497 504
498 bool XSSAuditor::filterFormToken(const FilterTokenRequest& request) 505 bool XSSAuditor::filterFormToken(const FilterTokenRequest& request)
499 { 506 {
500 ASSERT(request.token.type() == HTMLToken::StartTag); 507 ASSERT(request.token.type() == HTMLToken::StartTag);
501 ASSERT(hasName(request.token, formTag)); 508 ASSERT(hasName(request.token, formTag));
502 509
503 return eraseAttributeIfInjected(request, actionAttr, blankURL().string()); 510 return eraseAttributeIfInjected(request, actionAttr, kURLWithUniqueOrigin);
504 } 511 }
505 512
506 bool XSSAuditor::filterInputToken(const FilterTokenRequest& request) 513 bool XSSAuditor::filterInputToken(const FilterTokenRequest& request)
507 { 514 {
508 ASSERT(request.token.type() == HTMLToken::StartTag); 515 ASSERT(request.token.type() == HTMLToken::StartTag);
509 ASSERT(hasName(request.token, inputTag)); 516 ASSERT(hasName(request.token, inputTag));
510 517
511 return eraseAttributeIfInjected(request, formactionAttr, blankURL().string() , SrcLikeAttribute); 518 return eraseAttributeIfInjected(request, formactionAttr, kURLWithUniqueOrigi n, SrcLikeAttribute);
512 } 519 }
513 520
514 bool XSSAuditor::filterButtonToken(const FilterTokenRequest& request) 521 bool XSSAuditor::filterButtonToken(const FilterTokenRequest& request)
515 { 522 {
516 ASSERT(request.token.type() == HTMLToken::StartTag); 523 ASSERT(request.token.type() == HTMLToken::StartTag);
517 ASSERT(hasName(request.token, buttonTag)); 524 ASSERT(hasName(request.token, buttonTag));
518 525
519 return eraseAttributeIfInjected(request, formactionAttr, blankURL().string() , SrcLikeAttribute); 526 return eraseAttributeIfInjected(request, formactionAttr, kURLWithUniqueOrigi n, SrcLikeAttribute);
520 } 527 }
521 528
522 bool XSSAuditor::eraseDangerousAttributesIfInjected(const FilterTokenRequest& re quest) 529 bool XSSAuditor::eraseDangerousAttributesIfInjected(const FilterTokenRequest& re quest)
523 { 530 {
524 DEFINE_STATIC_LOCAL(String, safeJavaScriptURL, ("javascript:void(0)")); 531 DEFINE_STATIC_LOCAL(String, safeJavaScriptURL, ("javascript:void(0)"));
525 532
526 bool didBlockScript = false; 533 bool didBlockScript = false;
527 for (size_t i = 0; i < request.token.attributes().size(); ++i) { 534 for (size_t i = 0; i < request.token.attributes().size(); ++i) {
528 const HTMLToken::Attribute& attribute = request.token.attributes().at(i) ; 535 const HTMLToken::Attribute& attribute = request.token.attributes().at(i) ;
529 bool isInlineEventHandler = isNameOfInlineEventHandler(attribute.name); 536 bool isInlineEventHandler = isNameOfInlineEventHandler(attribute.name);
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 } 729 }
723 730
724 bool XSSAuditor::isSafeToSendToAnotherThread() const 731 bool XSSAuditor::isSafeToSendToAnotherThread() const
725 { 732 {
726 return m_documentURL.isSafeToSendToAnotherThread() 733 return m_documentURL.isSafeToSendToAnotherThread()
727 && m_decodedURL.isSafeToSendToAnotherThread() 734 && m_decodedURL.isSafeToSendToAnotherThread()
728 && m_decodedHTTPBody.isSafeToSendToAnotherThread(); 735 && m_decodedHTTPBody.isSafeToSendToAnotherThread();
729 } 736 }
730 737
731 } // namespace WebCore 738 } // namespace WebCore
OLDNEW
« no previous file with comments | « LayoutTests/http/tests/security/xssAuditor/formaction-on-input-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698