<commit_before>const getPropertyValue = require('./utility').getPropertyValue;
const Client           = require('../app/base/client');
const BinarySocket     = require('../app/base/socket');
const Dialog           = require('../app/common/attach_dom/dialog');

const ThirdPartyLinks = (() => {
    const init = () => {
        if (Client.isLoggedIn()) {
            BinarySocket.wait('landing_company').then((response) => {
                if (getPropertyValue(response, ['landing_company', 'financial_company', 'shortcode'])) {
                    document.body.addEventListener('click', clickHandler);
                }
            });
        }
    };

    const clickHandler = (e) => {
        if (!e.target) return;
        const el_link = e.target.closest('a');
        if (!el_link) return;

        const dialog = document.querySelector('#third_party_redirect_dialog');
        if (dialog && dialog.contains(el_link)) return;

        if (isThirdPartyLink(el_link.href)) {
            e.preventDefault();
            Dialog.confirm({
                id     : 'third_party_redirect_dialog',
                message: ['You will be redirected to a third-party website which is not owned by Binary.com.', 'Click OK to proceed.'],
            }).then((should_proceed) => {
                if (should_proceed) window.open(el_link.href, '_blank');
            });
        }
    };

    const isThirdPartyLink = (href) => {
        const destination = new URL(href);
        return !!destination.host
            && !/^.*\.binary\.com$/.test(destination.host) // destination host is not binary subdomain
            && window.location.host !== destination.host;
    };

    return {
        init,
        isThirdPartyLink,
    };
})();

module.exports = ThirdPartyLinks;<commit_msg>eliminate _blank opener vulnerability<commit_after>const getPropertyValue = require('./utility').getPropertyValue;
const Client           = require('../app/base/client');
const BinarySocket     = require('../app/base/socket');
const Dialog           = require('../app/common/attach_dom/dialog');

const ThirdPartyLinks = (() => {
    const init = () => {
        if (Client.isLoggedIn()) {
            BinarySocket.wait('landing_company').then((response) => {
                if (getPropertyValue(response, ['landing_company', 'financial_company', 'shortcode'])) {
                    document.body.addEventListener('click', clickHandler);
                }
            });
        }
    };

    const clickHandler = (e) => {
        if (!e.target) return;
        const el_link = e.target.closest('a');
        if (!el_link) return;

        const dialog = document.querySelector('#third_party_redirect_dialog');
        if (dialog && dialog.contains(el_link)) return;

        if (isThirdPartyLink(el_link.href)) {
            e.preventDefault();
            Dialog.confirm({
                id     : 'third_party_redirect_dialog',
                message: ['You will be redirected to a third-party website which is not owned by Binary.com.', 'Click OK to proceed.'],
            }).then((should_proceed) => {
                if (should_proceed) {
                    const link = window.open();
                    link.opener = null;
                    link.location = el_link.href;
                }
            });
        }
    };

    const isThirdPartyLink = (href) => {
        const destination = new URL(href);
        return !!destination.host
            && !/^.*\.binary\.com$/.test(destination.host) // destination host is not binary subdomain
            && window.location.host !== destination.host;
    };

    return {
        init,
        isThirdPartyLink,
    };
})();

module.exports = ThirdPartyLinks;
{'fraction_non_alphanumeric': 0.14073874359665678, 'fraction_numerical': 0.0, 'mean_word_length': 2.0360065466448445, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, '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': '6603327', 'n_tokens_mistral': 1020, 'n_tokens_neox': 972, 'n_words': 203}