From 691f79b76b9d36cc75dfb3c6f44e153c5c706c75 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Thu, 20 Dec 2018 19:45:15 +0000 Subject: [PATCH] External Libraries: Update zxcvbn to 4.2.2. Version 4.2.2 of the zxcvbn password strength library has several bug fixes. A full list of changes can be seen here: https://github.com/dropbox/zxcvbn/compare/v4.4.1...v4.4.2. This commit also adds the library as a project dependency, making it easier to update in the future. Because the dictionary within the library contains non-PG language, a `rot13:zxcvbn` task has been added to Grunt to perform a ROT-13 cipher on the library. This task has been added to `grunt build` and `grunt build:js`. Props omarreiss, netweb, desrosj. Fixes #43749. git-svn-id: https://develop.svn.wordpress.org/trunk@44354 602fd350-edb4-49c9-b593-d223f7449a82 --- Gruntfile.js | 70 ++++++++++++++++++++++++++++++- package-lock.json | 105 +++++++++++++++++++++++++++++++++++++++++++--- package.json | 5 +++ 3 files changed, 173 insertions(+), 7 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 05f25ac56d..669e680e8a 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -5,6 +5,10 @@ var webpackConfig = require( './webpack.config' ); module.exports = function(grunt) { var path = require('path'), fs = require( 'fs' ), + rot = require( 'rot' ); + esprima = require( 'esprima' ); + estraverse = require( 'estraverse' ); + escodegen = require( 'escodegen' ); spawn = require( 'child_process' ).spawnSync, SOURCE_DIR = 'src/', BUILD_DIR = 'build/', @@ -680,7 +684,10 @@ module.exports = function(grunt) { '!wp-admin/js/custom-header.js', // Why? We should minify this. '!wp-admin/js/farbtastic.js', '!wp-includes/js/swfobject.js', - '!wp-includes/js/wp-embed.js' // We have extra options for this, see uglify:embed + '!wp-includes/js/wp-embed.js', // We have extra options for this, see uglify:embed + + // .min files that still need to be minified. + 'wp-includes/js/zxcvbn.min.js' ] }, embed: { @@ -1068,6 +1075,12 @@ module.exports = function(grunt) { ] } }, + rot13: { + zxcvbn: { + src: './node_modules/zxcvbn/dist/zxcvbn.js', + dest: 'build/wp-includes/js/zxcvbn.min.js' + }, + }, _watch: { options: { interval: 2000 @@ -1346,6 +1359,7 @@ module.exports = function(grunt) { 'clean:js', 'webpack:dev', 'copy:js', + 'rot13:zxcvbn', 'file_append', 'uglify:all', 'build:tinymce', @@ -1364,6 +1378,7 @@ module.exports = function(grunt) { grunt.registerTask( 'build', [ 'clean:all', 'copy:all', + 'rot13:zxcvbn', 'file_append', 'cssmin:core', 'colors', @@ -1436,6 +1451,59 @@ module.exports = function(grunt) { // Default task. grunt.registerTask('default', ['build']); + grunt.registerMultiTask('rot13', 'ROT-13 zxcvbn passwords for PG-ness.', function() { + this.files.forEach(function(f) { + // Build AST from source code + var code = grunt.file.read(f.src); + var ast = esprima.parse(code); + + ast = estraverse.replace(ast, { + enter: function(node) { + // Filter string + let key_names = [ + 'passwords', + 'english_wikipedia', + 'female_names', + 'surnames', + 'us_tv_and_film', + 'male_names' + ]; + + if( node.type === 'Property' && key_names.includes( node.key.name ) ) { + // Wrap encrypted string with decrypt function. + var value = { + type: 'CallExpression', + callee: { + type: 'Identifier', + name: 'rot' + }, + arguments: [{ + type: 'Literal', + value: rot(node.value.callee.object.value, 13), + raw: rot(node.value.callee.object.raw, 13) + }, { + type: 'Literal', + value: 13, + raw: 13 + }] + }; + node.value = value; + return node; + } + } + }); + + // ROT-13 decode function + var prependCode = 'var lowercase="abcdefghijklmnopqrstuvwxyz",uppercase="ABCDEFGHIJKLMNOPQRSTUVWXYZ",regexLowercase=/[a-z]/,regexUppercase=/[A-Z]/,rot=function(e,r){if(null==r&&(r=13),r=Number(r),e=String(e),0==r)return e;0>r&&(r+=26);for(var a,c,t,s=e.length,p=-1,n="";++p