OLD | NEW |
---|---|
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 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
703 int start = attribute.nameRange.start - request.token.startIndex(); | 703 int start = attribute.nameRange.start - request.token.startIndex(); |
704 int end = attribute.valueRange.end - request.token.startIndex(); | 704 int end = attribute.valueRange.end - request.token.startIndex(); |
705 return request.sourceTracker.sourceForToken(request.token).substring(start, end - start); | 705 return request.sourceTracker.sourceForToken(request.token).substring(start, end - start); |
706 } | 706 } |
707 | 707 |
708 String XSSAuditor::canonicalize(String snippet, TruncationKind treatment) | 708 String XSSAuditor::canonicalize(String snippet, TruncationKind treatment) |
709 { | 709 { |
710 String decodedSnippet = fullyDecodeString(snippet, m_encoding); | 710 String decodedSnippet = fullyDecodeString(snippet, m_encoding); |
711 | 711 |
712 if (treatment != NoTruncation) { | 712 if (treatment != NoTruncation) { |
713 decodedSnippet.truncate(kMaximumFragmentLengthTarget); | 713 if (decodedSnippet.length() > kMaximumFragmentLengthTarget) { |
714 // Let the page influence the stopping point to avoid disclosing lea ding fragments. | |
715 // Stop when we hit whitespace, since that is unlikely to be part a leading fragment. | |
716 size_t position = kMaximumFragmentLengthTarget; | |
717 while (position < decodedSnippet.length() && !isHTMLSpace(decodedSni ppet[position])) { | |
Mike West
2015/06/11 06:01:26
Nit: No {} for single-line clauses.
| |
718 ++position; | |
719 } | |
720 decodedSnippet.truncate(position); | |
721 } | |
714 if (treatment == SrcLikeAttributeTruncation) | 722 if (treatment == SrcLikeAttributeTruncation) |
715 truncateForSrcLikeAttribute(decodedSnippet); | 723 truncateForSrcLikeAttribute(decodedSnippet); |
716 else if (treatment == ScriptLikeAttributeTruncation) | 724 else if (treatment == ScriptLikeAttributeTruncation) |
717 truncateForScriptLikeAttribute(decodedSnippet); | 725 truncateForScriptLikeAttribute(decodedSnippet); |
718 } | 726 } |
719 | 727 |
720 return decodedSnippet.removeCharacters(&isNonCanonicalCharacter); | 728 return decodedSnippet.removeCharacters(&isNonCanonicalCharacter); |
721 } | 729 } |
722 | 730 |
723 String XSSAuditor::canonicalizedSnippetForJavaScript(const FilterTokenRequest& r equest) | 731 String XSSAuditor::canonicalizedSnippetForJavaScript(const FilterTokenRequest& r equest) |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
827 | 835 |
828 bool XSSAuditor::isSafeToSendToAnotherThread() const | 836 bool XSSAuditor::isSafeToSendToAnotherThread() const |
829 { | 837 { |
830 return m_documentURL.isSafeToSendToAnotherThread() | 838 return m_documentURL.isSafeToSendToAnotherThread() |
831 && m_decodedURL.isSafeToSendToAnotherThread() | 839 && m_decodedURL.isSafeToSendToAnotherThread() |
832 && m_decodedHTTPBody.isSafeToSendToAnotherThread() | 840 && m_decodedHTTPBody.isSafeToSendToAnotherThread() |
833 && m_httpBodyAsString.isSafeToSendToAnotherThread(); | 841 && m_httpBodyAsString.isSafeToSendToAnotherThread(); |
834 } | 842 } |
835 | 843 |
836 } // namespace blink | 844 } // namespace blink |
OLD | NEW |