Escape HTML in user metadata description before appending to card #13241
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.
Description
Currently the model description is appended to a card on the document as-is. This allows for the user to inadvertently add HTML to the model description shown on-card and have it be appended onto the DOM if
show descriptions on card
is enabled. On a single-user system this presents a minimal security hazard, but on a shared system, any user could insert malicious code into the card metadata via the metadata editor.This also can cause issues where HTML in the description results in unexpected behavior, like the model card or other cards ceasing to display. For instance, replacing the model description with
<div>
causes the model to vanish on refresh, while setting it to<div><div>
causes other models to cease appearing. In a real-world case, zixaphir/Stable-Diffusion-Webui-Civitai-Helper#10 is caused by the text<title>_<trigger word>
appearing in the model description. While I can easily fix this on my end by removing the offending text, it will result in an unexpected state for the user where important informal text is removed, like information about other models used (IE, "used detailer model with<lora:detailer:0.6>
)"Screenshots/videos:
Checklist: