You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Benefits of this is that it relies on the the sanitize gem's own configuration capabilities in a clean and clear way, applies on on step 2 only, very clearly and a customizable way.
What gets through vs blocked:
Input style value | Regex match | Result
color: red | ✅ named | allowed
color: #fff | ✅ hex short | allowed
color: #ff6600 | ✅ hex long | allowed
color: rgb(0, 128, 255) | ✅ rgb | allowed
color: hsl(120, 100%, 50%) | ✅ hsl | allowed
color: expression(alert(1)) | ❌ | stripped
color: url(evil.com). | ❌ | stripped
color: red; position: fixed | ⚠️ | only color: red kept
color: currentColor. | ✅ named fallthrough | allowed
color: rgba(0,0,0,0) | ❌ not in regex | blocked*
Within the context of the sanitize gem being intentionally strict, I would suggest that the rule be modified as such:
- # Allow only:- # - Named colors: red, blue, darkslategray, etc. OR NOT?- # - Hex colors: #fff, #ff6600- # - RGB: rgb(0, 128, 255)- # - HSL: hsl(120, 100%, 50%)+ # Allow only hex colors: #fff,#ff6600
valid_color = value.match?(
/\A(
+ \#([0-9a-fA-F]{6}|[0-9a-fA-F]{3}) | # hex, prefer full three-byte form but fallback to shorthand- \#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}) | # hex- rgb\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*\) | # rgb()- hsl\(\s*\d{1,3}\s*,\s*\d{1,3}%\s*,\s*\d{1,3}%\s*\) | # hsl()- [a-zA-Z]{2,50} # named color
)\z/x
)
I'd also suggest adding that if a shortform hex was matched, it gets automatically expanded to a full three-byte form (e.g. #09C -> #0099CC) to ensure global consistency of what value is saved and then later passed along to a renderer.
This allows for full 24 bits "true colour" in a developer-focused, globally 'standard' (insomuch as there is one), and concise format while limiting the opening of any abuse to it's absolute minimum. At a quick check I believe this doesn't open any risk to injection, homograph attacks - only the possibility of having lime green text on a white background.
Now, this doesn't address why #369 and #1440 were closed, not in a small part because GitHub and @zkoppert provided little direct feedback to address the long-standing issue (and with #1440 closed on cart vs horse semantics).
It's worth noting that CommonMark, which GFM is based on, also does not have support for color attributes. Discussion about color alone get redirected (and then lost) in a larger discussion on supporting a broad scope of attributes.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Reacted by Atemo Cajaku, Саша “Nelie” Черных and Steven Parker
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Do we have any hope that since I spelled out a perfectly safe, easy and satisfying fix that this issue will be any more successful than the last 2 issues?
Do we have any hope that since I spelled out a perfectly safe, easy and satisfying fix that this issue will be any more successful than the last 2 issues?
Judging by the many other issues, discussions, etc that have come and gone about this specific subject, I am very confident that there is no hope.
But this one has not been closed yet… Maybe it will be in the next decade, or, surprisingly, solved before that happens.
Activity
perlygatekeeper commentedon Apr 24, 2026
Benefits of this is that it relies on the the sanitize gem's own configuration capabilities in a clean and clear way, applies on on step 2 only, very clearly and a customizable way.
What gets through vs blocked:
BraianS commentedon May 24, 2026
Any news on this?
bakano69-del commentedon Jul 7, 2026
asclepiadae commentedon Jul 7, 2026
Within the context of the sanitize gem being intentionally strict, I would suggest that the rule be modified as such:
I'd also suggest adding that if a shortform hex was matched, it gets automatically expanded to a full three-byte form (e.g.
#09C->#0099CC) to ensure global consistency of what value is saved and then later passed along to a renderer.This allows for full 24 bits "true colour" in a developer-focused, globally 'standard' (insomuch as there is one), and concise format while limiting the opening of any abuse to it's absolute minimum. At a quick check I believe this doesn't open any risk to injection, homograph attacks - only the possibility of having lime green text on a white background.
Now, this doesn't address why #369 and #1440 were closed, not in a small part because GitHub and @zkoppert provided little direct feedback to address the long-standing issue (and with #1440 closed on cart vs horse semantics).
It's worth noting that CommonMark, which GFM is based on, also does not have support for color attributes. Discussion about color alone get redirected (and then lost) in a larger discussion on supporting a broad scope of attributes.
github-actions commentedon Sep 6, 2026
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Atemo-C commentedon Sep 6, 2026
Sigh.
perlygatekeeper commentedon Sep 7, 2026
Do we have any hope that since I spelled out a perfectly safe, easy and satisfying fix that this issue will be any more successful than the last 2 issues?
Atemo-C commentedon Sep 7, 2026
Judging by the many other issues, discussions, etc that have come and gone about this specific subject, I am very confident that there is no hope.
But this one has not been closed yet… Maybe it will be in the next decade, or, surprisingly, solved before that happens.
perlygatekeeper commentedon Sep 27, 2026
How can I get more people invested in this?