Skip to content

Comments

🛡️ Sentinel: [HIGH] Fix unanchored regex in tweet verification#86

Draft
Dexploarer wants to merge 1 commit intomainfrom
sentinel-fix-tweet-verify-12309087947173640439
Draft

🛡️ Sentinel: [HIGH] Fix unanchored regex in tweet verification#86
Dexploarer wants to merge 1 commit intomainfrom
sentinel-fix-tweet-verify-12309087947173640439

Conversation

@Dexploarer
Copy link
Owner

Vulnerability: The regex used to validate tweet URLs (/(?:twitter\.com|x\.com)\/(\w+)\/status\/(\d+)/) was unanchored, allowing URLs like https://evil.com/twitter.com/user/status/123 to bypass validation.

Fix:

  • Replaced regex matching with new URL() parsing.
  • Enforced strict hostname validation against an allowlist (twitter.com, x.com, and www variants).
  • Enforced strict pathname structure matching ^/(\w+)/status/(\d+)$.
  • Exported parseTweetUrl for testing.
  • Added unit tests in src/api/twitter-verify.test.ts covering valid and invalid cases.

Verification:

  • Ran bun test src/api/twitter-verify.test.ts which confirmed that the new implementation correctly rejects the exploit vector.

PR created automatically by Jules for task 12309087947173640439 started by @Dexploarer

Replace vulnerable regex with strict `URL` parsing in `parseTweetUrl` to prevent acceptance of spoofed URLs.
Adds comprehensive test coverage in `src/api/twitter-verify.test.ts`.
@google-labs-jules
Copy link

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai
Copy link

coderabbitai bot commented Feb 17, 2026

Important

Review skipped

Draft detected.

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.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sentinel-fix-tweet-verify-12309087947173640439

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added the tests label Feb 17, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello @Dexploarer, 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 significantly enhances the security of tweet URL validation by resolving a high-severity vulnerability. The previous regex-based approach was susceptible to bypasses due to being unanchored. The updated implementation now leverages the URL object for more robust parsing and applies strict validation rules for hostnames and path structures, ensuring only legitimate tweet URLs are processed. This change fortifies the system against potential exploits related to malformed or malicious URLs.

Highlights

  • Vulnerability Fix: Addressed a high-severity vulnerability caused by an unanchored regex in tweet URL validation, which could allow malicious URLs to bypass checks.
  • Robust URL Parsing: Replaced the previous regex-based validation with a more secure approach using JavaScript's URL object for parsing.
  • Strict Validation: Implemented strict hostname validation against an allowlist (twitter.com, x.com, and their www variants) and enforced a precise pathname structure.
  • Testability: Exported the parseTweetUrl function to enable direct unit testing.
  • Comprehensive Testing: Introduced new unit tests in src/api/twitter-verify.test.ts to cover various valid and invalid tweet URL scenarios, including the exploit vector.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/api/twitter-verify.test.ts
    • Added a new test file to verify the security and correctness of the parseTweetUrl function.
  • src/api/twitter-verify.ts
    • Modified the parseTweetUrl function to use new URL() for parsing and implemented strict hostname and pathname validation.
    • Exported parseTweetUrl to allow for external testing.
Activity
  • The pull request was automatically created by Jules for a task initiated by @Dexploarer.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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

  1. 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.

Comment on lines +56 to +57
const match = parsed.pathname.match(/^\/(\w+)\/status\/(\d+)$/);
if (!match) return null;

Choose a reason for hiding this comment

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

The regular expression used to extract the screen name and tweet ID from the tweet URL is too restrictive. It only matches URLs of the form /username/status/1234567890 with no trailing slash, query parameters, or fragments. However, real-world tweet URLs often include trailing slashes, query parameters (e.g., ?s=20), or fragments, which will cause this function to return null for otherwise valid URLs.

Recommended solution:
Update the regex to allow for optional trailing slashes and ignore query parameters/fragments. For example:

const match = parsed.pathname.match(/^\/(\w+)\/status\/(\d+)(?:\/)?$/);

Or, better yet, split the pathname and extract the relevant segments, ignoring any extra path components or trailing slashes. This will make the function more robust and user-friendly.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses a high-severity security vulnerability related to an unanchored regex for tweet URL validation. The fix is robust, using the native URL API for parsing and implementing strict checks on both the hostname and pathname. The addition of comprehensive unit tests is excellent and ensures the vulnerability is resolved and won't regress. I have one minor suggestion to improve performance and code style by refactoring the list of valid hosts.

Comment on lines +50 to +54
const validHosts = ["twitter.com", "www.twitter.com", "x.com", "www.x.com"];

if (!validHosts.includes(hostname)) {
return null;
}

Choose a reason for hiding this comment

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

medium

For better performance and to adhere to best practices, it's recommended to define validHosts as a constant outside the parseTweetUrl function. This prevents the array from being recreated on every function call. Additionally, using a Set for validHosts provides a more performant lookup (O(1)) compared to an array's includes method (O(n)).

Suggested change
const validHosts = ["twitter.com", "www.twitter.com", "x.com", "www.x.com"];
if (!validHosts.includes(hostname)) {
return null;
}
const validHosts = new Set(["twitter.com", "www.twitter.com", "x.com", "www.x.com"]);
if (!validHosts.has(hostname)) {
return null;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant