{"size": 2113, "ext": "js", "max_stars_repo_path": "lib/rules/sensitive-files.js", "max_stars_repo_name": "sergejmueller/wpcheck", "max_stars_repo_stars_event_min_datetime": "2016-11-03T07:44:46.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-05T18:51:15.000Z", "max_issues_repo_path": "lib/rules/sensitive-files.js", "max_issues_repo_name": "Vollj/wpcheck", "max_issues_repo_issues_event_min_datetime": "2016-11-02T06:16:36.000Z", "max_issues_repo_issues_event_max_datetime": "2020-01-06T19:47:16.000Z", "max_forks_repo_path": "lib/rules/sensitive-files.js", "max_forks_repo_name": "Vollj/wpcheck", "max_forks_repo_forks_event_min_datetime": "2016-12-05T09:11:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-20T06:54:57.000Z"}
{"max_stars_count": 52, "max_issues_count": 6, "max_forks_count": 14, "avg_line_length": 22.0104166667, "max_line_length": 74, "alphanum_fraction": 0.4429720776}

/**
 * wpcheck module sensitive-files.js
 * Check WordPress/Apache/Dot files for their availability
 */


/**
 * Required modules
 */

const request = require( 'request' ).defaults( { followRedirect: false } )
const fs = require( '../fs' )
const log = require( '../log' )


/**
 * Initiator method
 *
 * @param   {Object}  data  Data object with request values
 * @return  void
 */

exports.fire = ( data ) => {

    const { wpURL, siteURL, userAgent, silentMode } = data

    const filterName = fs.fileName( __filename, '.js' )

    const logObj = { silentMode, filterName }

    const targets = [
        {
            'url': `${wpURL}/wp-config.php`,
            'method': 'HEAD',
            'pattern': 'DB_PASSWORD'
        },
        {
            'url': `${wpURL}/wp-admin/maint/repair.php`,
            'method': 'HEAD',
            'pattern': 'repair.php'
        },
        {
            'url': `${siteURL}/.htaccess`
        },
        {
            'url': `${siteURL}/.htpasswd`
        },
        {
            'url': `${siteURL}/.ssh`
        },
        {
            'url': `${siteURL}/.npmrc`
        },
        {
            'url': `${siteURL}/.gitconfig`
        },
        {
            'url': `${siteURL}/config.json`
        },
        {
            'url': `${wpURL}/wp-config-sample.php`
        },
        {
            'url': `${wpURL}/wp-content/debug.log`
        }
    ]

    targets.forEach( ( { url, method = 'GET', pattern = null } ) => {

        request( {
            'url': url,
            'method': method,
            'headers': { 'User-Agent': userAgent }
        }, ( error, response, body ) => {

            if ( error || response.statusCode !== 200 ) {
                return log.ok( `${url} is not public`, logObj )
            }

            if ( ! pattern ) {
                return log.warn( `${url} is public`, logObj )
            }

            if ( ! body.includes( pattern ) ) {
                return log.info( `${url} is public but safe`, logObj )
            }

            return log.warn( `${url} is public and not safe`, logObj )

        } )

    } )

}
