Potential fix for code scanning alert no. 2: DOM text reinterpreted as HTML #9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
imageUrlstate 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
srcattribute: 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:
isValidImageUrl) in the file that checks for a valid image URL (scheme and extension).onChangehandler for the image URL input, only allow setting the state if the entered value is valid, or set an error state/message otherwise.<img>element, only render it if the stored value passes validation (defense in depth).Suggested fixes powered by Copilot Autofix. Review carefully before merging.