Making WordPress.org

Ticket #265: 265.2.diff

File 265.2.diff, 3.8 KB (added by jorbin, 11 years ago)
  • trac-security.js

     
     1/* global wp */
     2window.wp = window.wp || {};
     3
    14(function($) {
    2         var badwords, intersect;
    3         badwords = [
    4                 'sql', 'trojan', 'rce', 'permissions', 'exploit', 'exploits', 'csrf', 'xss', 'sqli',
    5                 'scripting', 'vulnerability', 'vulnerabilities', 'capability', 'capabilities', 'intrusion',
    6                 'intrusions', 'cve', 'disclosure', 'hash', 'security', 'leakage', 'privilege', 'privileges',
    7                 'compromise', 'escalation', 'injection', 'forgery', 'password', 'passwords'
    8         ];
     5        var submit = $( 'input[type="submit"]' );
     6        wp.trac_security = {
     7                badwords : [
     8                        'sql', 'trojan', 'rce', 'permissions', 'exploit', 'exploits', 'csrf', 'xss', 'sqli',
     9                        'scripting', 'vulnerability', 'vulnerabilities', 'capability', 'capabilities', 'intrusion',
     10                        'intrusions', 'cve', 'disclosure', 'hash', 'security', 'leakage', 'privilege', 'privileges',
     11                        'compromise', 'escalation', 'injection', 'forgery', 'password', 'passwords'
     12                ],
    913
    10         intersect = function(a, b) {
    11                 return $.grep(a, function(i) {
    12                         return $.inArray(i, b) > -1;
    13                 });
     14                intersect : function(a, b) {
     15                        return $.grep(a, function(i) {
     16                                return $.inArray(i, b) > -1;
     17                        });
     18                },
     19
     20                has_overlap : function(str, arr){
     21                        var words = str.toLowerCase().replace(/[^a-z|\s]/g, '').split(' '),
     22                                overlap = this.intersect( words, arr);
     23
     24                        return ( overlap.length !== 0 );
     25                }
    1426        };
    1527
    16         $(document).ready( function() {
    17                 var submit = $( 'input[type="submit"]' );
    18                 $( '#field-summary, #field-description' ).on( 'keyup', function() {
    19                         var words, overlap;
    20                         words = $(this).val().toLowerCase().split( /[^a-z]/ );
    21                         overlap = intersect( badwords, words );
    22                  
    23                         if ( overlap.length === 0 ) {
    24                                 submit.prop( 'disabled', false );
    25                                 $( '#security-question' ).hide();
    26                                 return;
    27                         }
     28        function show_box(){
     29                // We have a potential problem here
     30                submit.prop( 'disabled', true );
     31                if ( $( '#security-question' ).length !== 0 ){
     32                        // We've already created the checkbox
     33                        $( '#security-question' ).show();
     34                } else {
     35                        // We need to add the checkbox
     36                        $( '.buttons' ).before( '<p id="security-question"><label><input type="checkbox" name="sec_question" />' +
     37                                '&nbsp;I am <strong>not</strong> reporting a security issue</label>' +
     38                                ' &mdash; <a href="http://make.wordpress.org/core/handbook/reporting-security-vulnerabilities/">report security issues to security@wordpress.org</a></p>' );
     39                }
    2840
    29                         // We have a potential problem here
    30                         submit.prop( 'disabled', true );
    31                         if ( $( '#security-question' ).length !== 0 ){
    32                                 // We've already created the checkbox
    33                                 $( '#security-question' ).show();
    34                         } else {
    35                                 // We need to add the checkbox
    36                                 $( '.buttons' ).before( '<p id="security-question"><label><input type="checkbox" name="sec_question" />' +
    37                                         '&nbsp;I am <strong>not</strong> reporting a security issue</label>' +
    38                                         ' &mdash; <a href="http://make.wordpress.org/core/handbook/reporting-security-vulnerabilities/">report security issues to security@wordpress.org</a></p>' );
    39                         }
    40                 });
    41                 $( '#propertyform' ).on( 'change', '#security-question input', function() {
    42                         submit.prop( 'disabled', ! $(this).is( ':checked' ) );
    43                 });
     41        }
     42
     43        function hide_box(){
     44                $('input[name="submit"]').prop('disabled', false);
     45                $('#sec_question').hide();
     46        }
     47
     48        jQuery('#field-summary, #field-description, #field-keywords').on('keyup', function(){
     49                var entry = $(this).val();
     50               
     51                if ( wp.trac_security.has_overlap( entry, wp.trac_security.badwords ) ) {
     52                        show_box();
     53                } else {
     54                        hide_box();
     55                }
    4456        });
    45 })(jQuery);
     57
     58        $( '#propertyform' ).on( 'change', '#security-question input', function() {
     59                submit.prop( 'disabled', ! $(this).is( ':checked' ) );
     60        });
     61
    4662       
     63}(jQuery));