第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

使用后格雷SQL副本JDBC防止SQL注入

使用后格雷SQL副本JDBC防止SQL注入

暮色呼如 2022-09-28 10:07:51
我有以下代碼來使用PG COPY將表格下載為文件:    public void download(String table, Writer responseWriter) throws SQLException, IOException {        try (Connection conn = dataSource.getConnection()) {            CopyManager copyManager = new CopyManager(conn.unwrap(BaseConnection.class));            // SQL Injection can happen here!            String statement = "COPY " + table + " TO STDOUT WITH NULL ''";            copyManager.copyOut(statement, responseWriter);        }    }顯然,此代碼容易發(fā)生 SQL 注入(表參數(shù)是從彈簧 REST 控制器傳遞的)。當(dāng)然,我可以做一些手動衛(wèi)生,但如果有一個(gè)“準(zhǔn)備聲明”的方式在CopyManager中做到這一點(diǎn),我會更喜歡它。使用春季Jdbc模板的獎(jiǎng)勵(lì)積分。
查看完整描述

1 回答

?
德瑪西亞99

TA貢獻(xiàn)1770條經(jīng)驗(yàn) 獲得超3個(gè)贊

除了一攬子SQL注入(惡意人員試圖執(zhí)行諸如向命令中添加語句之類的操作)之外,還有另一個(gè)問題。由于您的代碼允許運(yùn)行任何有效的表名,因此它仍然存在泄露架構(gòu)中任何表中包含的數(shù)據(jù)的風(fēng)險(xiǎn)。DELETECOPY


因此,這里安全的做法可能是維護(hù)您希望允許用戶訪問的表的白名單。任何與列表不匹配的輸入表名稱都將被拒絕。假設(shè)您的表列表駐留在 中,我們可以對您的代碼進(jìn)行以下更改:List


public void download(String table, Writer responseWriter) throws SQLException, IOException {

    // get list of all allowed tables

    List<String> fileList = getAllowedTables();

    if (!fileList.contains(table)) {

        throw new IllegalAccessException("Someone tried to access a forbidden table.");

    }


    try (Connection conn = dataSource.getConnection()) {

        CopyManager copyManager = new CopyManager(conn.unwrap(BaseConnection.class));

        // SQL Injection can happen here!

        String statement = "COPY " + table + " TO STDOUT WITH NULL ''";

        copyManager.copyOut(statement, responseWriter);

    }

}


查看完整回答
反對 回復(fù) 2022-09-28
  • 1 回答
  • 0 關(guān)注
  • 262 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號