Fix: correct regex for file-preview URL re-signing#25620
Fix: correct regex for file-preview URL re-signing#25620QuantumGhost merged 17 commits intolanggenius:mainfrom
Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @hyongtao-code, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request resolves a bug where unescaped ? characters in URL regex patterns caused incorrect matching and re-signing of malformed file-preview and image-preview URLs. The changes ensure robust URL validation and re-signing, preventing potential issues with file access. Additionally, it updates deprecated datetime function calls to improve code maintainability and consistency.
Highlights
- Regex Correction for URL Re-signing: The regex patterns for
file-previewandimage-previewURLs have been corrected by escaping the?character. This prevents incorrect matches and ensures that only valid URLs are considered for re-signing. - Enhanced URL Validation: The re-signing mechanism now strictly processes only genuinely valid
file-previewandimage-previewURLs, avoiding malformed URL re-signing that previously occurred due to the unescaped?. - New Unit Tests: Comprehensive unit tests have been added to validate the corrected URL re-signing logic. These tests cover scenarios for correctly re-signed valid URLs and confirm that misspelled preview URLs are no longer incorrectly matched.
- Deprecated Function Update: The deprecated
datetime.utcnow()function has been replaced withnaive_utc_now()across several files, improving code maintainability and addressing best practices for handling timestamps.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a regex vulnerability in URL re-signing logic where unescaped ? characters caused incorrect URL pattern matching for file-preview and image-preview endpoints. The fix ensures only valid URLs are re-signed by properly escaping the regex patterns.
Key changes:
- Fixed regex patterns by escaping
?characters in file-preview and image-preview URL matching - Replaced deprecated
datetime.utcnow()calls withnaive_utc_now()for future compatibility - Added comprehensive unit tests to verify correct behavior for valid and misspelled URLs
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| api/models/model.py | Fixed regex patterns by escaping ? in file-preview and image-preview URL matching |
| api/tests/unit_tests/models/test_model.py | Added unit tests covering valid URL re-signing and protection against misspelled URL matching |
| api/tests/unit_tests/core/repositories/test_workflow_node_execution_conflict_handling.py | Replaced deprecated datetime.utcnow() with naive_utc_now() |
| api/tests/test_containers_integration_tests/tasks/test_batch_clean_document_task.py | Replaced deprecated datetime.utcnow() with naive_utc_now() |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
api/tests/test_containers_integration_tests/tasks/test_batch_clean_document_task.py
Show resolved
Hide resolved
There was a problem hiding this comment.
Code Review
This pull request effectively addresses a bug in the URL re-signing logic by correcting the regular expressions for file-preview and image-preview URLs. The unescaped ? was causing incorrect matches, and this fix resolves that. The inclusion of new unit tests is excellent, as it covers both the valid cases and the previously failing cases with misspelled URLs, ensuring the fix is robust. Additionally, I appreciate the proactive replacement of the deprecated datetime.utcnow() function, which improves the overall health of the codebase. My feedback includes a minor suggestion to enhance the readability of the new regular expressions.
Co-authored-by: Asuka Minato <i@asukaminato.eu.org>
Fixes langgenius#25619 The regex patterns for file-preview and image-preview contained an unescaped `?`, which caused incorrect matches such as `file-previe` or `image-previw`. This led to malformed URLs being incorrectly re-signed. Changes: - Escape `?` in both file-preview and image-preview regex patterns. - Ensure only valid URLs are re-signed. Added unit tests to cover: - Valid file-preview and image-preview URLs (correctly re-signed). - Misspelled file/image preview URLs (no longer incorrectly matched). Other: - Fix a deprecated function `datetime.utcnow()` Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Asuka Minato <i@asukaminato.eu.org> Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com>
Fixes #25619
The regex patterns for file-preview and image-preview contained an unescaped
?,which caused incorrect matches such as
file-previeorimage-previw.This led to malformed URLs being incorrectly re-signed.
Changes:
?in both file-preview and image-preview regex patterns.Added unit tests to cover:
Other:
datetime.utcnow()Related with #24180
Important
Fixes #<issue number>.Summary
Screenshots
Checklist
dev/reformat(backend) andcd web && npx lint-staged(frontend) to appease the lint gods