Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ビビってどうする:セキュアなPythonコードを目指して

Avatar for Sau Sau
September 27, 2025

 ビビってどうする:セキュアなPythonコードを目指して

セキュリティは「難しそう」「どこから始めればいいのかわからない」とよく言われており、重要ながらも体系的に学ぶ機会が少ない分野です。このセッションでは、初心者向けにPythonコードをよりセキュアにするための知識と武器を紹介していきます。具体的な事例を交えながら、サプライチェーン攻撃やマルウェアが仕込まれているデータを防ぐ方法・ツールをわかりやすく解説します。

Presented at PyCon JP 2025

Avatar for Sau

Sau

September 27, 2025

More Decks by Sau

Other Decks in Technology

Transcript

  1. Zip bomb (死のzip) 42 kB 5 GB 1.1 Denial of

    Service(DoS攻撃) 💀 8
  2. Zip bomb (死のzip) XML bomb (billion laughs攻撃) < 1 kB

    3 GB 1.1 Denial of Service(DoS攻撃) 10
  3. pickle の歴史 2003: Python 2.3でpickleに対する注意喚起 (PEP-307) 2022: MLコミュニティで、 SafeTensorsという新フォーマットを提案 2024:

    BentoML pickle由来の脆弱性発覚 (CVE-2024-2912) 2025: Hugging Face上、45%のモデルが引き続き pickleを使用* *Kellas et al (2025) "PickleBall: Secure Deserialization of Pickle-based Machine Learning Models" https://arxiv.org/html/2508.15987v1 14
  4. MD5に対する衝突攻撃 23 Source: Nat McHugh (2015) "Create your own MD5

    collisions" https://natmchugh.blogspot.com/2015/02/create-your-own-md5-collisions.html
  5. MD5に対する衝突攻撃(応用版) 24 「アリスはインターンとして 優秀」 「アリスにフルアクセス を与える」 Source: Hash Collisions (The

    Poisoned Message Attack) "The Story of Alice and her Boss" https://www.sos.cs.ru.nl/applications/courses/security2015/md5collisions/index.html
  6. Example: Zip bomb fix in Python 2023/9: Zipfile 脆弱性発覚 (CVE-2024-0450)

    Python 3.12.2, 3.11.8, 3.10.13, 3.9.18, 3.8.18 2024/1: セキュリティパッチをリリース 32
  7. PyPI は無法地帯 asynciio -> asyncio beaufifulsoup -> beautifulsoup matplotib ->

    matplotlib request -> requests pytorch -> torch 37 Source: https://pypi.org/project/pytorch/
  8. Pin 📌 lock🔒 せよ Python: Lock with poetry.lock, Pipfile.lock, uv.lock

    🔒 Github Actions: Pin with the SHA commit hash📌 40 - uses: actions/checkout@692973e3d937129bcbf40652 eb9f2f61becf3332 # v4.1.7 - uses: actions/checkout@main - uses: actions/checkout@v4 - uses: actions/[email protected]
  9. ここまでのまとめ 1. 闇データ: 入力チェックを徹底 2. 闇アルゴリズム: 推奨暗号リストを参照 。セキュリティ用途におい てはrandomよりもsecrets 3.

    闇バージョン: Pythonやライブラリーの 寿命に注意 4. 闇3rd Party:全体のエコシステムに注意。 Pin📌やLock🔒する 43
  10. GitHub 最近のおすすめ設定(上級者向け) GitHub Actions learnings from the recent nx hack

    https://jessehouwing.net/github-actions-learnings-from-the-recent-nx-hack/ GitHub Actions: A Cloudy Day for Security - Part 1 https://binarysecurity.no/posts/2025/08/securing-gh-actions-part1 47
  11. 51