はじめに

ブログでアップしていた写真のexif情報を消し忘れていたので削除する。
普通にまずいやつ…。

環境

1
2
3
Windows 10 Professional
WSL2 (Ubuntu 22.04LTS)
exiftool 12.40

exiftoolのインストール

以前のexifToolの記事のインストール手順と同じ。

exif情報の一括削除

削除したい写真があるディレクトリで下記を実行する。

オリジナルファイルをバックアップする場合

1
find /path/to/directory -type f -exec exiftool -all= {} \;

オリジナルファイルをバックアップしない場合

1
find /path/to/directory -type f -exec exiftool -overwrite_original -all= {} \;

今回は下記で実行してみた。
カレントディレクトリ以下のファイルに対して exiftool を実行してバックアップを生成せずに更新する。

1
find . -type f -exec exiftool -overwrite_original -all= {} \;

というわけで実行してみる。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
    1 image files updated
    1 image files updated
    1 image files updated
    1 image files updated
    1 image files updated
    1 image files updated
    1 image files updated
    1 image files updated
    1 image files updated
    1 image files updated
    1 image files updated
    1 image files updated
    1 image files updated
    1 image files updated
    1 image files updated
    1 image files updated
    1 image files updated
    1 image files updated
    1 image files updated
    1 image files updated

アップデートされていっている…。

対象のディレクトリはGitで管理されているので、差分が多く出る。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
git status
....
        modified:   tech/tips/use-slack-notifications-gitlab/create_slack_app_3.png
        modified:   tech/tips/use-slack-notifications-gitlab/create_slack_app_4.png
        modified:   tech/tips/use-slack-notifications-gitlab/gitlab_setting_1.png
        modified:   tech/tips/use-slack-notifications-gitlab/gitlab_setting_2.png
        modified:   tech/tips/use-slack-notifications-gitlab/gitlab_setting_3.png
        modified:   tech/tips/use-slack-notifications-gitlab/gitlab_setting_4.png
        modified:   tech/tips/use-slack-notifications-gitlab/gitlab_setting_5.png
        modified:   tech/tips/use-slack-notifications-gitlab/gitlab_setting_6.png
        modified:   tech/tips/use-slack-notifications-gitlab/webhooks_1.png
        modified:   tech/tips/use-slack-notifications-gitlab/webhooks_2.png
        modified:   tech/tips/use-slack-notifications-gitlab/webhooks_3.png
        modified:   tech/tips/use-tesseract/mail-for-ocr.png
        modified:   tech/tips/use-watch/test-1.gif

exif情報が消えているか確認する。

1
exiftool [ファイル名]

を実行する。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
:~/workspace/blog-hugo/static/image$ exiftool column/pass-fp2/fp2-result.jpeg 
ExifTool Version Number         : 12.40
File Name                       : fp2-result.jpeg
Directory                       : column/pass-fp2
File Size                       : 674 KiB
File Modification Date/Time     : 2023:07:16 13:06:02+09:00
File Access Date/Time           : 2023:07:16 13:06:02+09:00
File Inode Change Date/Time     : 2023:07:16 13:06:02+09:00
File Permissions                : -rw-r--r--
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
Image Width                     : 1532
Image Height                    : 1606
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Image Size                      : 1532x1606
Megapixels                      : 2.5

消えていそう!

再発防止のために…

以前の記事でも記載したが、exiftool情報は主要なSNSであれば削除されている(はず)
個人ブログでは、このようなことに気をつけないといけないので、再発防止のために下記を導入する。

Gitのhookスクリプトでexiftool情報を削除する

Gitには、Hookスクリプトという、コミットやマージなどをしたときにそれをトリガーとしてスクリプトを実行できる機能がある。
今回はそれを利用して、コミット時に exif 情報を削除するスクリプトを仕込む。

  1. Gitのルートディレクトリ(.git があるディレクトリ)で、Hookスクリプトのサンプルをコピーする.
1
cp .git/hooks/pre-commit.sample .git/hooks/pre-commit
  1. 実行権限を付与する。
1
chmod u+x .git/hooks/pre-commit
  1. pre-commitを編集して下記のようにする。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#!/bin/sh

# ステージングにあるファイルのEXIF情報を削除する
git diff --cached --name-only --diff-filter=ACM | while read -r file; do
    exiftool -overwrite_original -all= "$file"
    git add "$file"
done

# 他の事前コミット処理が必要な場合はここに追加します

# スクリプトの実行を続行するために必要な最後の行
exit 0

ChatGPTに生成してもらった

動作確認

confirm

コミット時に消えていることを確認できる。

ChatGPT先生の活躍

chatgpt

GitHooksで本当に良いのか

GitHooks では、個人の環境に依存するし、他の環境でも同じように環境を作らないといけないのが漏れにつながると考えており、これでいいのかなと思っていた。
個人のブログで作る人は自分しかいないのでまあ良いのだが…。後で忘れているということもあるなあとも思った。
同じことを考えている人がいないかなと調べたところ、参考 でリンクさせていただいているサイトを見つけた。
CIを使ってやったほうが良いと記載していたので、おお!確かに!とうんうん頷いたので、GitHub Actionとか使う形になるのかな。
CIツール全然使いこなせていないので、勉強する・・・!

参考

おわりに

exif情報は情報漏洩になりがちなので、このあたりはきちんと対処していきたい。
セキュリティ関係の話は網羅しておかないと、こういう事態になるのでしっかり学んでおこう…。