khoj-ai / khoj

Your AI second brain. Self-hostable. Get answers from the web or your docs. Build custom agents, schedule automations, do deep research. Turn any online or local LLM into your personal, autonomous AI (e.g gpt, claude, gemini, llama, qwen, mistral).
https://khoj.dev
GNU Affero General Public License v3.0
14.11k stars 703 forks source link

Disable Minutely Recurrence for Automations #781

Closed debanjum closed 5 months ago

debanjum commented 5 months ago

Disable setting recurrence of automations to less than an hourly frequency.

Checks crontime string for minutely recurrence and either

hakunamatata1997 commented 5 months ago

PR Review ๐Ÿ”

โฑ๏ธ Estimated effort to review [1-5] 3, because the PR involves changes in multiple functions across different files and includes logic changes related to scheduling and error handling. Understanding the implications of these changes requires a good understanding of the existing scheduling system and how these changes affect the overall functionality.
๐Ÿงช Relevant tests No
โšก Possible issues Random Minute Selection: The use of `random()` to assign a random minute might lead to unexpected scheduling as it does not ensure a uniform distribution or prevent potential clustering at certain times. This could lead to performance issues if many jobs are scheduled at the same minute.
๐Ÿ”’ Security concerns No
Code feedback:
relevant filesrc/khoj/routers/api.py
suggestion       Consider adding a more specific check for minute-level recurrence instead of just checking if `crontime` starts with "*". This would handle cases where users might use specific minute values like "5 * * * *" which are currently not caught by this logic. [important]
relevant lineif crontime.startswith("*"):

relevant filesrc/khoj/routers/helpers.py
suggestion       Instead of using `math.floor(random() * 60)` directly, consider using `randint(0, 59)` from the `random` module for clarity and directness in generating a random minute. [medium]
relevant linecrontime = " ".join([str(math.floor(random() * 60))] + crontime.split(" ")[1:])

relevant filesrc/khoj/routers/api.py
suggestion       To improve user experience, instead of directly rejecting minute-level recurrences, consider providing an alternative suggestion or automatically adjusting to a valid frequency, if applicable. [medium]
relevant linecontent="Recurrence of every X minutes is unsupported. Please create a less frequent schedule.",

relevant filesrc/khoj/routers/helpers.py
suggestion       Ensure that the random minute assignment is logged or traceable for debugging purposes, as this could help in troubleshooting issues related to job scheduling. [medium]
relevant linecrontime = " ".join([str(math.floor(random() * 60))] + crontime.split(" ")[1:])

gitguardian[bot] commented 5 months ago

โš ๏ธ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

๐Ÿ”Ž Detected hardcoded secret in your pull request
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | | | -------------- | ------------------ | ------------------------------ | ---------------- | --------------- | -------------------- | | [10005301](https://dashboard.gitguardian.com/workspace/453364/incidents/10005301?occurrence=139775937) | Triggered | Generic Password | 97c5906d00cf7ce9714ab59b52623a8d201a5830 | src/khoj/app/settings.py | [View secret](https://github.com/khoj-ai/khoj/commit/97c5906d00cf7ce9714ab59b52623a8d201a5830#diff-12e11c5157feddb98d0a76795945d4ecbea098e12b35c03ee964fb832f85b6adL126) |
๐Ÿ›  Guidelines to remediate hardcoded secrets
1. Understand the implications of revoking this secret by investigating where it is used in your code. 2. Replace and store your secret safely. [Learn here](https://blog.gitguardian.com/secrets-api-management?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment) the best practices. 3. Revoke and [rotate this secret](https://docs.gitguardian.com/secrets-detection/secrets-detection-engine/detectors/generics/generic_password#revoke-the-secret?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment). 4. If possible, [rewrite git history](https://blog.gitguardian.com/rewriting-git-history-cheatsheet?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment). Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data. To avoid such incidents in the future consider - following these [best practices](https://blog.gitguardian.com/secrets-api-management/?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment) for managing and storing secrets including API keys and other credentials - install [secret detection on pre-commit](https://docs.gitguardian.com/ggshield-docs/integrations/git-hooks/pre-commit?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment) to catch secret before it leaves your machine and ease remediation.

๐Ÿฆ‰ GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.