A security review flags that your tool uses `pickle` to cache API responses on disk. What do you change?
IntermediateScenarioAutomation scripting & CLI design
Answer
Situation read → pickle.load on a file someone else can write is arbitrary code execution.
What I'd do →
- Switch the cache to JSON (or
sqlite3), which is data-only. - Store it in a user-owned directory with
0600permissions (platformdirs.user_cache_dir). - Add expiry metadata so stale data is not trusted forever.
Why → JSON cannot execute code on load; pickle can.
Interview tip → Know the rule: never unpickle data you did not produce in a location only you can write.
More on Automation scripting & CLI design
Your team has a 300-line Bash script that parses JSON with `jq`, loops over AWS accounts and retries with `sleep`. It breaks every month. Do you rewrite it in Python?BeginnerA colleague's script deletes files older than 30 days from `/var/log/app`. You are asked to review it before it goes into cron. What do you look for?IntermediateYou need a script that ops engineers run from laptops and that CI runs nightly. How do you design its interface?IntermediateA script reads a 15 GB access log to count 5xx errors per endpoint, and the box runs out of memory. How do you fix it?BeginnerYou must run the same Python automation on 40 servers that have Python 3.6, 3.9 and 3.12. What do you do?IntermediateA cron job that runs a Python script fails silently. Nobody noticed for two weeks. How do you make sure that never happens again?Intermediate