Skip to content

fix: security hardening and non-atomic move bugfix#6

Open
TheTrustedAdvisor wants to merge 1 commit intoLars147:mainfrom
TheTrustedAdvisor:fix/security-hardening
Open

fix: security hardening and non-atomic move bugfix#6
TheTrustedAdvisor wants to merge 1 commit intoLars147:mainfrom
TheTrustedAdvisor:fix/security-hardening

Conversation

@TheTrustedAdvisor
Copy link
Copy Markdown

Summary

  • Non-atomic move fix: move_recipe_in_plan now adds to the new date before removing from the old date — a duplicate is recoverable, a lost recipe is not.
  • Password security: --password CLI flag is now marked as insecure in help text; COOKIDOO_PASSWORD env var is checked before falling back to interactive prompt, keeping credentials out of ps output.
  • Bare except cleanup: All 7 bare except: clauses replaced with specific exception types (Exception, json.JSONDecodeError, KeyError, OSError, ValueError, TypeError) for better error visibility and debuggability.
  • Cache file gitignore: cookidoo_categories.json added to the Cache section of .gitignore to prevent accidental commit.
  • Hardcoded URL fix: Two https://cookidoo.de/shopping/de-DE hardcoded URLs in clear_shopping_list and add_custom_item_to_shopping_list replaced with COOKIDOO_BASE/LOCALE constants so locale changes apply everywhere.

Test plan

  • tmx login without --password flag prompts interactively as before
  • COOKIDOO_PASSWORD=secret tmx login --email user@example.com logs in without prompt
  • tmx login --help shows the (UNSICHER - nutze COOKIDOO_PASSWORD Umgebungsvariable) warning on --password
  • tmx plan move <recipe_id> <from_date> <to_date> succeeds without data loss (recipe appears on new date, removed from old)
  • Simulate add failure in move_recipe_in_plan: recipe should remain on original date (not lost)
  • cookidoo_categories.json is not tracked by git after git add .
  • Shopping list clear/add-item endpoints still work correctly with non-de-DE locale if LOCALE constant is changed
  • No bare except: lines remain: grep -n "except:" tmx_cli.py returns empty

🤖 Generated with Claude Code

- Reverse move_recipe_in_plan operation order to prevent data loss
  (add first, then remove — duplicate is safer than lost recipe)
- Warn about --password CLI flag security risk, support COOKIDOO_PASSWORD env var
- Replace 7 bare except: clauses with specific exception types
- Add cookidoo_categories.json to .gitignore
- Fix hardcoded URLs bypassing COOKIDOO_BASE/LOCALE constants

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 18, 2026 07:18
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the CLI’s security posture and improves resilience by addressing a non-atomic “move recipe” workflow, avoiding insecure password handling patterns, tightening exception handling, and removing locale-specific hardcoded URLs.

Changes:

  • Make move_recipe_in_plan add-first-then-remove to avoid data loss on partial failure.
  • Prefer COOKIDOO_PASSWORD env var for login and mark --password as insecure in help text.
  • Replace several bare except: clauses with explicit exception types; fix hardcoded shopping URLs; ignore categories cache file in git.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 3 comments.

File Description
tmx_cli.py Updates move semantics, login password sourcing/help text, exception specificity, and locale-aware shopping URLs.
.gitignore Adds cookidoo_categories.json to prevent committing generated cache data.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tmx_cli.py
# Only remove from old date after successful add
success, msg = remove_recipe_from_plan(recipe_id, from_date)
if not success:
return False, f"Verschoben, aber Entfernen vom alten Datum fehlgeschlagen: {msg}"
Comment thread tmx_cli.py
Comment on lines 657 to 665
if SEARCH_TOKEN_FILE.exists():
try:
with open(SEARCH_TOKEN_FILE, "r") as f:
cached = json.load(f)
# Check if still valid (with 5 min buffer)
if cached.get("validUntil", 0) > dt.datetime.now().timestamp() + 300:
return cached.get("apiKey")
except:
except (json.JSONDecodeError, KeyError, OSError):
pass
Comment thread tmx_cli.py
Comment on lines 1886 to 1892
try:
with open(CATEGORIES_CACHE_FILE, "r", encoding="utf-8") as f:
cache_data = json.load(f)
ts = cache_data.get("timestamp", "")[:16].replace("T", " ")
print(f" (aus Cache, Stand: {ts} UTC)")
except:
except (json.JSONDecodeError, OSError):
print(" (aus Cache)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants