Skip to content

Conversation

@linuskang
Copy link
Contributor

Potential fix for https://github.com/bubblymaps/maps/security/code-scanning/2

The best way to resolve this issue is to validate and sanitize the user-provided URL before setting it in the imageUrl state and passing it to the <img src> attribute. Specifically, ensure that the URL conforms to expected schemes (http, https) and points to a legitimate image file (e.g., ends with .jpg, .jpeg, .png, .gif, .webp). This should be done in the handler for the input field: before updating the state, check validity and only set the value if the requirements are met. Additionally, provide user feedback if their input is invalid.

You also must do this validation whenever the value is used in the src attribute: if for any reason a previously-stored value could be invalid, it should not be rendered (or should be rendered in a non-dangerous way or with a fallback image). A simple, robust fix is to add a utility function that validates the image URL, call it on input change, and only update the state (and render the image) if the URL passes the checks.

Specifically:

  • Add a function (e.g., isValidImageUrl) in the file that checks for a valid image URL (scheme and extension).
  • In the onChange handler for the image URL input, only allow setting the state if the entered value is valid, or set an error state/message otherwise.
  • When rendering the <img> element, only render it if the stored value passes validation (defense in depth).

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…s HTML

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

👋 Thanks for opening your first pull request!

Please make sure you've:

  • ✅ Read the contributing guidelines
  • ✅ Tested your changes locally
  • ✅ Added appropriate documentation

A maintainer will review your PR soon.

@linuskang linuskang moved this from Backlog to In progress in Bubbly Maps Nov 16, 2025
@linuskang linuskang marked this pull request as ready for review November 16, 2025 21:18
@linuskang linuskang merged commit ead875f into master Nov 16, 2025
8 checks passed
@github-project-automation github-project-automation bot moved this from In progress to Done in Bubbly Maps Nov 16, 2025
@linuskang linuskang deleted the alert-autofix-2 branch November 17, 2025 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants