The document discusses regular expression denial of service (ReDoS) attacks. It begins by introducing regular expressions and how they are used to search for patterns in strings. It then demonstrates how the number of steps needed to evaluate a regular expression can increase exponentially based on input length due to the use of non-deterministic finite automata (NFA). To mitigate ReDoS, it recommends using libraries that implement deterministic finite automata (DFA) instead of NFA, limiting the length of user inputs, and setting execution timeouts.
4. 正規表現はどう使うのか
○基本的にできること
l ⼤量の⽂字から特定の⽂字列を探す
l “This is a pen.”の中に”pen”があるかまた何⽂字⽬にあるか
l ⽂字列が正しい形式か判定する
l 電話番号に0-0-0-0みたいなものを⼊⼒されないように
l ⼊⼒に変な⽂字(制御⽂字など)を⼊⼒されないように
○↑を⽤いてすること
l ⽂字列の置換
l “This is a pen. I like pen”の中にある”pen”を全て”apple”に変える
l ⽂字列の分割
l ⽂字列をスペース,カンマ,タブのいずれかで分割
2021/5/18 Ritsumeikan Security Team
5
5. 正規表現はどう使うのか
○基本的にできること(Python re モジュール)
l ⼤量の⽂字から特定の⽂字列を探す (re.search)
l “This is a pen.”の中に”pen”があるかまた何⽂字⽬にあるか
l ⽂字列が正しい形式か判定する (re.match)
l 電話番号に0-0-0-0みたいなものを⼊⼒されないように
l ⼊⼒に変な⽂字(制御⽂字など)を⼊⼒されないように
○↑を⽤いてすること
l ⽂字列の置換 (re.sub)
l “This is a pen. I like pen”の中にある”pen”を全て”apple”に変える
l ⽂字列の分割 (re.split)
l ⽂字列をスペース,カンマ,タブのいずれかで分割
2021/5/18 Ritsumeikan Security Team
6
20. 2021/5/18 Ritsumeikan Security Team
21
なぜこうなるのか
○ 正規表現 : ^(a+)+b$
○ ⼊⼒: aaaaaa
a a a a a a
テーマ: +の適⽤範囲が難しい
問題:(a+)と+はどの部分を指しますか︖
(a+) +
(a+) +
(a+) +
→いっぱいあって難しいから,とりあえずいっぱい進んで,
ダメだったら少し戻る⽅針