Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api v2 get note #720

Merged
merged 55 commits into from
Feb 28, 2025
Merged

Api v2 get note #720

merged 55 commits into from
Feb 28, 2025

Conversation

c8y3
Copy link
Contributor

@c8y3 c8y3 commented Feb 14, 2025

Implementation of endpoint GET /api/v2/cases/{case_identifier}/notes/{identifier} to get a note.

Tasks performed:

  • deprecated GET /case/notes/{note_id}
  • quality: changes in application initialization to try and move from app.post_init import run_post_init at the top of the file
  • quality: set configuration of timezone (app.config['timezone'] = 'Europe/Paris') directly in the __init__.py (because otherwise, the moment this configuration is set in the configuration depends on the order of imports)
  • quality: fixed and activated ruff rule E231
  • quality: fixed and activated ruff rule E305
  • quality: fixed and activated ruff rule W292
  • quality: some fixes to warnings reported by deepsource

This PR goes with the accompanying documentation iris-doc-src PR#42

@c8y3 c8y3 requested a review from whikernel February 14, 2025 13:36
@c8y3 c8y3 linked an issue Feb 14, 2025 that may be closed by this pull request
8 tasks
@@ -113,4 +101,4 @@
if not next_url or urlsplit(next_url).netloc != '':
next_url = url_for('index.index', cid=user.ctx_case)

return redirect(next_url)
return redirect(next_url)

Check warning

Code scanning / CodeQL

URL redirection from remote source Medium

Untrusted URL redirection depends on a
user-provided value
.

Copilot Autofix AI 1 day ago

To fix the problem, we need to enhance the validation of the next_url parameter to ensure it is safe for redirection. We can use the url_has_allowed_host_and_scheme function from Django, which is specifically designed to check if a URL is safe for redirection. This function handles backslashes correctly and ensures that the URL is either relative or has an allowed host and scheme.

We will modify the _is_safe_url function to use url_has_allowed_host_and_scheme for validation. Additionally, we will ensure that the next_url parameter is properly sanitized before being used in the redirect.

Suggested changeset 2
source/app/business/auth.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/source/app/business/auth.py b/source/app/business/auth.py
--- a/source/app/business/auth.py
+++ b/source/app/business/auth.py
@@ -1,2 +1,3 @@
 from urllib.parse import urlparse, urljoin
+from django.utils.http import url_has_allowed_host_and_scheme
 
@@ -68,8 +69,6 @@
     """
-    Check whether the target URL is safe for redirection by ensuring that it is either a relative URL or
-    has the same host as the current request.
+    Check whether the target URL is safe for redirection by using the url_has_allowed_host_and_scheme function.
     """
-    ref_url = urlparse(request.host_url)
-    test_url = urlparse(urljoin(request.host_url, target))
-    return test_url.scheme in ('http', 'https') and ref_url.netloc == test_url.netloc
+    from django.utils.http import url_has_allowed_host_and_scheme
+    return url_has_allowed_host_and_scheme(target, allowed_hosts={request.host})
 
@@ -83,3 +82,3 @@
     # Remove backslashes to mitigate obfuscation
-    next_url = next_url.replace('\\', '')
+    next_url = next_url.replace('\\', '/')
     if _is_safe_url(next_url):
EOF
@@ -1,2 +1,3 @@
from urllib.parse import urlparse, urljoin
from django.utils.http import url_has_allowed_host_and_scheme

@@ -68,8 +69,6 @@
"""
Check whether the target URL is safe for redirection by ensuring that it is either a relative URL or
has the same host as the current request.
Check whether the target URL is safe for redirection by using the url_has_allowed_host_and_scheme function.
"""
ref_url = urlparse(request.host_url)
test_url = urlparse(urljoin(request.host_url, target))
return test_url.scheme in ('http', 'https') and ref_url.netloc == test_url.netloc
from django.utils.http import url_has_allowed_host_and_scheme
return url_has_allowed_host_and_scheme(target, allowed_hosts={request.host})

@@ -83,3 +82,3 @@
# Remove backslashes to mitigate obfuscation
next_url = next_url.replace('\\', '')
next_url = next_url.replace('\\', '/')
if _is_safe_url(next_url):
source/requirements.txt
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/source/requirements.txt b/source/requirements.txt
--- a/source/requirements.txt
+++ b/source/requirements.txt
@@ -52,2 +52,3 @@
 dependencies/iris_intelowl_module-0.1.0-py3-none-any.whl
-dependencies/iris_seika_module-1.0.0-py3-none-any.whl
\ No newline at end of file
+dependencies/iris_seika_module-1.0.0-py3-none-any.whl
+django==5.1.6
\ No newline at end of file
EOF
@@ -52,2 +52,3 @@
dependencies/iris_intelowl_module-0.1.0-py3-none-any.whl
dependencies/iris_seika_module-1.0.0-py3-none-any.whl
dependencies/iris_seika_module-1.0.0-py3-none-any.whl
django==5.1.6
This fix introduces these dependencies
Package Version Security advisories
django (pypi) 5.1.6 None
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@dfir-iris dfir-iris deleted a comment from coderabbitai bot Feb 26, 2025
Copy link

coderabbitai bot commented Feb 26, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

c8y3 added 24 commits February 28, 2025 08:02
@c8y3 c8y3 mentioned this pull request Feb 28, 2025
@whikernel whikernel merged commit dfd9ae5 into develop Feb 28, 2025
18 of 19 checks passed
@whikernel whikernel deleted the api_v2_get_note branch February 28, 2025 15:18
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.

API v2 note get
2 participants