CDATA escaping for inline <script> and <style> tags

オープン
#6 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
haskell
領域
security, web-dev

調査の方向性

Start by tracing the AST and renderer paths used for inline style elements and the proposed script helper, focusing on the Raw behavior described in the issue. Compare the safety check in blaze-markup's Text renderer, then verify that special characters render correctly while closing-tag sequences cannot produce invalid HTML or XSS.

索引モデルが issue の本文から書いたものです。

説明

#3 accidentally introduced a regression wrt. to CSS rendering. <script> and <style> tags are special in HTML, as they are encoded as CDATA. That essentially means – no escaping, but closing tag can't appear in the payload content and HTML does not provide a way to escape this.

At the moment:

  • <style> elements generated by web-view use regular text escaping, thus, if they contain any of escaped characters (<>&"' etc.) rendered CSS will be incorrect,
  • <script> element that we don't have a helper now will: either cause invalid JS to be rendered (if text is used) or invalid HTML (with the risk of opening XSS vulnerability) if raw is used – the latter was also the case for CSS before #3 was merged.

For example, addClass $ cls "test" & prop "background" ("url('https://picsum.photos/200/300?random=1&foo=2=bar')" :: Text)) will generate incorrect result:

<style type='text/css'>
.empty { background:url(&#39;https://picsum.photos/200/300?random=1&amp;foo=2=bar&#39;) }
</style>

Potential solution could be to introduce External to AST, which would be always the same as Raw but would refuse to include any </ sequence which would prevent XSS/invalid HTML. This is what blaze-markup does for these tags.


Trivia: Historically, people would split string literals in JS payloads to "escape" them, e.g.

<script>document.write('<scr'+'ipt type="text/javascript" src="http://example.com/some.js"></sc'+'ript>');</script>
主要言語
Haskell
スター
56
フォーク
7
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

seanhess/atomic-css のほかの issue

seanhess/atomic-css の issue をすべて見る

似ている issue

Haskell の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。