{"size": 1277, "ext": "js", "max_stars_repo_path": "middlreware/sqlCheck.js", "max_stars_repo_name": "zhangsean/webfunny_monitor", "max_stars_repo_stars_event_min_datetime": "2018-08-23T06:39:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T09:59:16.000Z", "max_issues_repo_path": "middlreware/sqlCheck.js", "max_issues_repo_name": "zhangsean/webfunny_monitor", "max_issues_repo_issues_event_min_datetime": "2018-08-29T00:58:38.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T09:18:28.000Z", "max_forks_repo_path": "middlreware/sqlCheck.js", "max_forks_repo_name": "zhangsean/webfunny_monitor", "max_forks_repo_forks_event_min_datetime": "2018-09-25T08:01:52.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T03:43:21.000Z"}
{"max_stars_count": 3841, "max_issues_count": 217, "max_forks_count": 669, "avg_line_length": 35.4722222222, "max_line_length": 85, "alphanum_fraction": 0.4447924824}
/**
 * 判断判断是否有sql注入逻辑
 */
const statusCode = require('../util/status-code')
const dangerParams = [";", "'", "<", ">", "(", ")", "update ",
                    "select ", "union ", "and ", "or ", "from ", "insert ",
                    "delete ", "database ", "drop ", "truncate ", "create ", "like "]
module.exports = function () {
    return async function (ctx, next) {
        const { url, query } = ctx
        const { body } = ctx.request
        // 过滤掉一些接口
        if ( url.indexOf("upLog") === -1 &&
            url.indexOf("upMyLog") === -1 &&
            url.indexOf("upDLog") === -1 &&
            url.indexOf("upMog") === -1 ) {
            let goOnFlag = true
            const tempQuery = JSON.stringify(query).toLowerCase()
            const tempBody = JSON.stringify(body).toLowerCase()
            dangerParams.forEach((item) => {
                if (tempBody.indexOf(item) !== -1) {
                    goOnFlag = false
                } else if (tempQuery.indexOf(item) !== -1) {
                    goOnFlag = false
                }
            })
            if (!goOnFlag) {
                ctx.response.status = 413;
                ctx.body = statusCode.ERROR_413(`请求参数不合法`);
                return
            }
        }
        await next();
    }
}
