Skip to content

fix leak token when input url as raw html #1179

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

phamngocquy
Copy link

@phamngocquy phamngocquy commented Jun 3, 2025

Summary

Please include a summary of the change and/or which issues are fixed.

eg: Fixes #123 (Tag GitHub issue numbers in this format, so it automatically links the issues with your PR)

List of files changed and why

eg: quickstart.py - To update the example as per new changes

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added/updated unit tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of URLs starting with "raw:" or "raw://", ensuring correct processing of raw HTML content.
  • Style

    • Minor whitespace cleanup for improved code readability (no user-facing impact).

Copy link
Contributor

coderabbitai bot commented Jun 3, 2025

Walkthrough

A conditional check was added after fetching page content to identify URLs starting with "raw:" or "raw://". Such URLs are internally replaced with "RAW html" and influence the is_raw_html flag during HTML processing. Minor whitespace cleanup was also performed, with no changes to method signatures or overall control flow.

Changes

File(s) Change Summary
crawl4ai/async_webcrawler.py Added conditional logic for "raw:" URLs, replaced URL with "RAW html" if matched, minor whitespace cleanup in aprocess_html.

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Timeout setting (#123) No timeout-related logic or settings were added or modified in this change.

Poem

In the warren where code and carrots entwine,
A crawler now checks for "raw:" in the line.
If found, it hops to "RAW html" with glee,
Tidying whitespace as quick as can be.
🥕 The web is now parsed with a rabbit’s keen eye—
Onward, sweet crawler, to burrows nearby!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 897e017 and 8ddd79f.

📒 Files selected for processing (1)
  • crawl4ai/async_webcrawler.py (3 hunks)

@@ -360,7 +363,7 @@ async def arun(
pdf_data=pdf_data,
verbose=config.verbose,
is_raw_html=True if url.startswith("raw:") else False,
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Use the preserved flag when calling aprocess_html

The is_raw_html parameter should use the flag set above, not re-inspect the mutated URL. Update this line to:

-                        is_raw_html=True if url.startswith("raw:") else False,
+                        is_raw_html=is_raw_html,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
is_raw_html=True if url.startswith("raw:") else False,
is_raw_html=is_raw_html,
🧰 Tools
🪛 Ruff (0.11.9)

365-365: Use bool(...) instead of True if ... else False

Replace with `bool(...)

(SIM210)

🪛 Pylint (3.3.7)

[refactor] 365-365: The if expression can be replaced with 'bool(test)'

(R1719)

🤖 Prompt for AI Agents
In crawl4ai/async_webcrawler.py at line 365, the is_raw_html parameter is
incorrectly set by re-inspecting the mutated URL instead of using the preserved
flag defined earlier. Modify the is_raw_html argument to use the existing
preserved flag variable directly rather than checking the URL prefix again.

Comment on lines +338 to +340
if url.startswith("raw:") or url.startswith("raw://"):
url = "RAW html"

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Preserve raw HTML flag before mutating URL

The current logic replaces the url without capturing whether it originated from raw HTML, and then you recompute is_raw_html against the mutated URL (always false). Instead, compute a flag first and then set the display url.
Apply this diff:

-                    if url.startswith("raw:") or url.startswith("raw://"):
-                        url = "RAW html"
+                    # Detect raw HTML input and prepare display URL
+                    is_raw_html = url.startswith("raw:") or url.startswith("raw://")
+                    url = "Raw HTML" if is_raw_html else url
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if url.startswith("raw:") or url.startswith("raw://"):
url = "RAW html"
# Detect raw HTML input and prepare display URL
is_raw_html = url.startswith("raw:") or url.startswith("raw://")
url = "Raw HTML" if is_raw_html else url
🤖 Prompt for AI Agents
In crawl4ai/async_webcrawler.py around lines 338 to 340, the code replaces the
url string before checking if it is raw HTML, causing the raw HTML flag to be
lost. To fix this, first compute a boolean flag indicating if the original url
starts with "raw:" or "raw://", then assign the display url to "RAW html" if
needed, preserving the raw HTML flag for later use.

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.

1 participant