+2011-02-03 Adam Barth <abarth@webkit.org>
+
+ Reviewed by Eric Seidel.
+
+ Make XSSFilter go fast by adding a SuffixTree
+ https://bugs.webkit.org/show_bug.cgi?id=53665
+
+ The SuffixTree lets us quickly reject snippets if the POST data is
+ large (because we can avoid a linear scan over the POST data).
+
+ * html/parser/XSSFilter.cpp:
+ (WebCore::XSSFilter::init):
+ (WebCore::XSSFilter::isContainedInRequest):
+ * html/parser/XSSFilter.h:
+
2011-02-03 Mihai Parparita <mihaip@chromium.org>
Reviewed by Alexey Proskuryakov.
void XSSFilter::init()
{
+ const size_t miniumLengthForSuffixTree = 512; // FIXME: Tune this parameter.
+ const int suffixTreeDepth = 5;
+
ASSERT(m_state == Uninitialized);
m_state = Initial;
m_decodedHTTPBody = decodeURL(httpBody->flattenToString(), encoding);
if (m_decodedHTTPBody.find(isRequiredForInjection, 0) == notFound)
m_decodedHTTPBody = String();
+ if (m_decodedHTTPBody.length() >= miniumLengthForSuffixTree)
+ m_decodedHTTPBodySuffixTree = adoptPtr(new SuffixTree<ASCIICodebook>(m_decodedHTTPBody, suffixTreeDepth));
}
}
ASSERT(!snippet.isEmpty());
String canonicalizedSnippet = canonicalize(snippet);
ASSERT(!canonicalizedSnippet.isEmpty());
- return m_decodedURL.find(canonicalizedSnippet, 0, false) != notFound
- || m_decodedHTTPBody.find(canonicalizedSnippet, 0, false) != notFound;
+ if (m_decodedURL.find(canonicalizedSnippet, 0, false) != notFound)
+ return true;
+ if (m_decodedHTTPBodySuffixTree && !m_decodedHTTPBodySuffixTree->mightContain(canonicalizedSnippet))
+ return false;
+ return m_decodedHTTPBody.find(canonicalizedSnippet, 0, false) != notFound;
}
bool XSSFilter::isSameOriginResource(const String& url)