LoginSignup
1
2

More than 5 years have passed since last update.

Angular Translateのセキュリティ対策

Posted at

未だにAngular 1系を使っております。基本的に英語でアプリ書いて必要に応じてAngular Translateで日本語対応させることにしていますが、デフォルトだとangular-translateはsanitizeもescapeもしてくれません。

大事なことだから二度いいます。

デフォルトだとangular-translateはsanitizeもescapeもしてくれません。

Documentを読むと $translateProvider.useSanitizeValueStrategy('sanitize')と指定することでsanitizeがOnになるようですが、これだとUTF8文字列は正しく表示されません。

正解はuseSanitizeValueStrategyを使うことで、具体的には $translateProvider.useSanitizeValueStrategy('escape','sanitizeParameters')のように設定すればUTF8文字列も正しく表示されます。ただし、translateにおいてHTMLタグを使うことはできなくなります。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2