<commit_before>'use strict';

// add DOMPurify hook to sanitze attributes
DOMPurify.addHook('afterSanitizeAttributes', function(node) {
    // open all links in a new window
    if ('target' in node) {
        node.setAttribute('target', '_blank');
    }
});

// set listener for event from main window
window.onmessage = function(e) {
    var html = '';

    if (e.data.html) {
        // display html mail body
        html = e.data.html;
    } else if (e.data.text) {
        // diplay text mail body by with colored conversation nodes
        html = renderNodes(parseConversation(e.data.text));
    }

    // sanitize HTML content: https://github.com/cure53/DOMPurify
    if (e.data.removeImages) {
        // remove http leaks
        document.body.innerHTML = DOMPurify.sanitize(html, {
            FORBID_TAGS: ['style', 'svg', 'audio', 'video', 'math'],
            FORBID_ATTR: ['src']
        });
    } else {
        document.body.innerHTML = DOMPurify.sanitize(html);
    }

    attachClickHandlers();
};

/**
 * Send a message to the main window when email address is clicked
 */
function attachClickHandlers() {
    var elements = document.getElementsByTagName('a');
    for (var i = 0, len = elements.length; i < len; i++) {
        elements[i].onclick = handle;
    }<commit_msg>[WO-03-008] Fix no Origin Checks for postMessage Communication (High)<commit_after>'use strict';

// add DOMPurify hook to sanitze attributes
DOMPurify.addHook('afterSanitizeAttributes', function(node) {
    // open all links in a new window
    if ('target' in node) {
        node.setAttribute('target', '_blank');
    }
});

// set listener for event from main window
window.onmessage = function(e) {
    var html = '';

    // ignore messages from other origins to prevent XSS
    if (e.origin !== location.origin) {
        return;
    }

    if (e.data.html) {
        // display html mail body
        html = e.data.html;
    } else if (e.data.text) {
        // diplay text mail body by with colored conversation nodes
        html = renderNodes(parseConversation(e.data.text));
    }

    // sanitize HTML content: https://github.com/cure53/DOMPurify
    if (e.data.removeImages) {
        // remove http leaks
        document.body.innerHTML = DOMPurify.sanitize(html, {
            FORBID_TAGS: ['style', 'svg', 'audio', 'video', 'math'],
            FORBID_ATTR: ['src']
        });
    } else {
        document.body.innerHTML = DOMPurify.sanitize(html);
    }

    attachClickHandlers();
};

/**
 * Send a message to the main window when email address is clicked
 */
function attachClickHandlers() {
    var elements = document.getElementsByTagName('a');
    for (var i = 0, len = elements.length; i < len; i++) {
        elements[i].onclick = handle;
    }
{'fraction_non_alphanumeric': 0.13159797541576285, 'fraction_numerical': 0.0039768618944323935, 'mean_word_length': 2.5657216494845363, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7573416', 'n_tokens_mistral': 850, 'n_tokens_neox': 825, 'n_words': 234}