https://avatars.githubusercontent.com/u/6058558

程式狂想筆記

CSP 網頁安全性設計

CSP 是 Content Security Policy 的縮寫,主要用途是告訴瀏覽器「這個頁面允許載入哪些資源、允許哪些腳本行為」。平常如果只把它當成安全掃描報告裡的一個名詞,很容易低估它對前端行為的實際影響。

ElasticSearch 6.3 升級 6.6.1

ElasticSearch 做版本升級時,最怕的不是指令本身,而是升級後才發現資料、外掛或設定彼此不相容。尤其從 6.3 升到 6.6.1 這種同大版本下的小升級,看起來跨度不大,但實務上還是不能直接當作覆蓋檔案就結束。

MultipartFile.transferTo 遇到 FileNotFoundException 問題

之前公司同事有教,在 Window 在專案 D 朝設定 /app/file(參照位置),執行時候就會吃D:/app/file。這個非常實用,不需要再重新配置。

但在用 Spring Boot 會發生讀不到檔案。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
    @Override
    public String store(MultipartFile file, String fileName) throws IOException {

        String destPath "/app/file/";
        File filePath = new File(destPath);
        File dest = new File(filePath, fileName);
        if (!filePath.exists()) {
            filePath.mkdirs();
        }
        try {
            file.transferTo(dest);
            log.info("file save success");
        } catch (IOException e) {
            log.error("File upload Error: ", e);
            throw e;
        }
        return dest.getCanonicalPath();
    }

SSRF 風險

SSRF 全名是 Server-Side Request Forgery,中文通常翻成伺服器端請求偽造。它的危險點在於:攻擊者不是直接從自己電腦打內網,而是誘導你的伺服器幫他去打。只要系統有「替使用者抓網址內容」這類功能,就值得特別留意。