diff --git a/Gruntfile.js b/Gruntfile.js
index 2d0b8b295c..f72fafec16 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -1445,7 +1445,8 @@ module.exports = function(grunt) {
 				'build:css',
 				'includes:emoji',
 				'includes:embed',
-				'replace:emojiBannerText'
+				'replace:emojiBannerText',
+				'build:protect_folders'
 			] );
 		}
 	} );
@@ -1516,6 +1517,93 @@ module.exports = function(grunt) {
 		} );
 	} );
 
+	grunt.registerTask( 'build:protect_folders', 'Ensures every directory has an index.php file.', function() {
+		var defaultIndexFile = BUILD_DIR + 'wp-content/index.php',
+			folders = [
+				'wp-includes',
+				'wp-admin',
+				'wp-content',
+			],
+			excluded = [
+				'wp-includes/ID3',
+				'wp-includes/PHPMailer',
+				'wp-includes/Requests',
+				'wp-includes/SimplePie',
+				'wp-includes/sodium_compat',
+				'wp-includes/Text',
+			];
+
+		/**
+		 * Gets all folders from a given path.
+		 *
+		 * @param   {string} dirPath Directory path to search against.
+		 * @param   {array}  arrayOfFiles Array of files in the directory.
+		 * @param   {array}  arrayOfFolders Array of directories in the directory.
+		 * @returns {array}  Array of folders
+		 */
+		var getAllFolders = function( dirPath, arrayOfFiles, arrayOfFolders ) {
+			// Let's get all of the folders on this path.
+			var files = fs.readdirSync( dirPath );
+
+			arrayOfFiles = arrayOfFiles || [];
+			arrayOfFolders = arrayOfFolders || [];
+
+			// Let's loop through the folders, looking for more directories.
+			files.forEach( function( file ) {
+				// Let's look for a directory.
+				if ( fs.statSync( dirPath + "/" + file ).isDirectory() ) {
+					// Let's see if the path contains any of the `excluded` paths.
+					var dir = dirPath + "/" + file,
+						block = false;
+
+						excluded.map( function( path ) {
+						if ( dir.includes( BUILD_DIR + path ) ) {
+							block = true;
+						}
+					});
+
+					// This is a legit path, let's add to our array of valid paths.
+					if ( ! block ) {
+						arrayOfFolders.push( dir );
+						arrayOfFolders = getAllFolders( dirPath + "/" + file, arrayOfFiles, arrayOfFolders );
+					}
+				} else {
+					// Keep digging for paths.
+					arrayOfFiles.push( path.join( __dirname, dirPath, "/", file ) );
+				}
+			});
+
+			return arrayOfFolders;
+		}
+
+		/**
+		 * Checks if index.php exists in the current directory.
+		 *
+		 * @param   {string} dirPath Path to start a search for index.php files.
+		 * @returns {bool}
+		 */
+		var doesDirHaveIndex = function ( dirPath ) {
+			var index = '/index.php';
+
+			return fs.existsSync( dirPath + index );
+		}
+
+		// Loop through folders, looking for blank index.php files.
+		folders.forEach( function( path ) {
+			var folder = getAllFolders( BUILD_DIR + path );
+
+			folder.forEach( function( path ) {
+				if( ! doesDirHaveIndex( path ) ) {
+					var newFile = path + '/index.php',
+						index = fs.readFileSync( defaultIndexFile );
+
+					// The `wx` flag ensures that it doesn't overwrite any existing files.
+					fs.writeFileSync( newFile, index, {flag: "wx"} );
+				}
+			})
+		});
+	});
+
 	// Travis CI tasks.
 	grunt.registerTask('travis:js', 'Runs JavaScript Travis CI tasks.', [ 'jshint:corejs', 'qunit:compiled' ]);
 	grunt.registerTask('travis:phpunit', 'Runs PHPUnit Travis CI tasks.', [ 'build', 'phpunit' ]);
