WebCore/ChangeLog

 12010-06-09 Adam Barth <abarth@webkit.org>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 Use allowRequestIfNoIllegalURICharacters instead of context for XSSAuditor::canLoadExternalScriptFromSrc
 6 https://bugs.webkit.org/show_bug.cgi?id=40404
 7
 8 We originally added the context parameter to
 9 canLoadExternalScriptFromSrc to work around some false positives caused
 10 by folks checking external script URLs on the server. Our thought was
 11 that we could tell these were not real XSS attacks because the
 12 surrounding context wouldn't match in the URL and the document.
 13
 14 Implementing this feature in the HTML5 parser is hard because it
 15 pierces a layer of abstraction (the token abstraction of the input
 16 stream). We could hack this into the new parser, but instead I think
 17 it's better to switch to using the allowRequestIfNoIllegalURICharacters
 18 heuristic.
 19
 20 We designed the allowRequestIfNoIllegalURICharacters after the context
 21 heuristic to deal with other cases where the server was validating
 22 input before echoing it. However, we never tried applying it to
 23 canLoadExternalScriptFromSrc.
 24
 25 It's possible that this will cause false positives and will need to be
 26 reverted, which is why I've left in some of the infrustructure for
 27 computing context. We don't have a good way to know if that will
 28 happen except to try. We do know, however, that this heuristic will
 29 work for the original false positives we saw.
 30
 31 * html/HTML5Tokenizer.cpp:
 32 (WebCore::HTML5Tokenizer::shouldLoadExternalScriptFromSrc):
 33 * html/HTMLTokenizer.cpp:
 34 (WebCore::HTMLTokenizer::parseTag):
 35 * page/XSSAuditor.cpp:
 36 (WebCore::XSSAuditor::canLoadExternalScriptFromSrc):
 37 * page/XSSAuditor.h:
 38
1392010-06-09 Tony Gentilcore <tonyg@chromium.org>
240
341 Reviewed by Adam Barth.
60940

WebCore/html/HTML5Tokenizer.cpp

@@bool HTML5Tokenizer::shouldLoadExternalS
227227 return true;
228228 // FIXME: We have no easy way to provide the XSSAuditor with the original
229229 // un-processed attribute source, so for now we pass nullAtom.
230  return m_XSSAuditor->canLoadExternalScriptFromSrc(nullAtom, srcValue);
 230 return m_XSSAuditor->canLoadExternalScriptFromSrc(srcValue);
231231}
232232
233233void HTML5Tokenizer::executeScript(const ScriptSourceCode& sourceCode)
60940

WebCore/html/HTMLTokenizer.cpp

@@HTMLTokenizer::State HTMLTokenizer::pars
13951395
13961396 if (m_currentToken.beginTag && m_currentToken.tagName == scriptTag && !inViewSourceMode() && !m_parser->skipMode() && m_attrName == srcAttr) {
13971397 String context(m_rawAttributeBeforeValue.data(), m_rawAttributeBeforeValue.size());
1398  if (m_XSSAuditor && !m_XSSAuditor->canLoadExternalScriptFromSrc(context, attributeValue))
 1398 if (m_XSSAuditor && !m_XSSAuditor->canLoadExternalScriptFromSrc(attributeValue))
13991399 attributeValue = blankURL().string();
14001400 }
14011401

@@HTMLTokenizer::State HTMLTokenizer::pars
14321432
14331433 if (m_currentToken.beginTag && m_currentToken.tagName == scriptTag && !inViewSourceMode() && !m_parser->skipMode() && m_attrName == srcAttr) {
14341434 String context(m_rawAttributeBeforeValue.data(), m_rawAttributeBeforeValue.size());
1435  if (m_XSSAuditor && !m_XSSAuditor->canLoadExternalScriptFromSrc(context, attributeValue))
 1435 if (m_XSSAuditor && !m_XSSAuditor->canLoadExternalScriptFromSrc(attributeValue))
14361436 attributeValue = blankURL().string();
14371437 }
14381438
60938

WebCore/page/XSSAuditor.cpp

@@bool XSSAuditor::canCreateInlineEventLis
170170 return true;
171171}
172172
173 bool XSSAuditor::canLoadExternalScriptFromSrc(const String& context, const String& url) const
 173bool XSSAuditor::canLoadExternalScriptFromSrc(const String& url) const
174174{
175175 if (!isEnabled())
176176 return true;

@@bool XSSAuditor::canLoadExternalScriptFr
179179 return true;
180180
181181 FindTask task;
182  task.context = context;
183182 task.string = url;
 183 task.allowRequestIfNoIllegalURICharacters = true;
184184
185185 if (findInRequest(task)) {
186186 DEFINE_STATIC_LOCAL(String, consoleMessage, ("Refused to execute a JavaScript script. Source code of script found within request.\n"));
60938

WebCore/page/XSSAuditor.h

@@namespace WebCore {
9090
9191 // Determines whether the external script should be loaded based on the
9292 // content of any user-submitted data.
93  bool canLoadExternalScriptFromSrc(const String& context, const String& url) const;
 93 bool canLoadExternalScriptFromSrc(const String& url) const;
9494
9595 // Determines whether object should be loaded based on the content of
9696 // any user-submitted data.
60938