mirror of
https://github.com/goldbergyoni/nodebestpractices.git
synced 2025-11-03 03:36:26 +08:00
Merge pull request #187 from YukiOta/ja-trans/6.15
translate 6.15 into japanese
This commit is contained in:
@ -918,15 +918,15 @@ null == undefined; // true
|
||||
|
||||
<br/><br/>
|
||||
|
||||
## ![✔] 6.15. Avoid JavaScript eval statements
|
||||
## ![✔] 6.15. JavaScript の eval 構文を避ける
|
||||
|
||||
<a href="https://www.owasp.org/index.php/Top_10-2017_A7-Cross-Site_Scripting_(XSS)" target="_blank"><img src="https://img.shields.io/badge/%E2%9C%94%20OWASP%20Threats%20-%20A7:XSS%20-green.svg" alt=""/></a> <a href="https://www.owasp.org/index.php/Top_10-2017_A1-Injection" target="_blank"><img src="https://img.shields.io/badge/%E2%9C%94%20OWASP%20Threats%20-%20A1:Injection%20-green.svg" alt=""/></a> <a href="https://www.owasp.org/index.php/Top_10-2017_A4-XML_External_Entities_(XXE)" target="_blank"><img src="https://img.shields.io/badge/%E2%9C%94%20OWASP%20Threats%20-%20A4:External%20Entities%20-green.svg" alt=""/></a>
|
||||
|
||||
**TL;DR:** `eval` is evil as it allows executing custom JavaScript code during run time. This is not just a performance concern but also an important security concern due to malicious JavaScript code that may be sourced from user input. Another language feature that should be avoided is `new Function` constructor. `setTimeout` and `setInterval` should never be passed dynamic JavaScript code either.
|
||||
**TL;DR:** `eval` は、ランタイムにおいてカスタム JavaScript コードの実行を許可しているため、有害です。これは単にパフォーマンス的な懸念だけではなく、ユーザーの入力を元にした悪意のある JavaScript コードのために、重大なセキュリティ的な懸念でもあります。その他の避けるべき言語仕様は、`new Function` コンストラクタです。`setTimeout` と `setInterval` も動的な JavaScript コードに渡されるべきではありません。
|
||||
|
||||
**Otherwise:** Malicious JavaScript code finds a way into text passed into `eval` or other real-time evaluating JavaScript language functions, and will gain complete access to JavaScript permissions on the page. This vulnerability is often manifested as an XSS attack.
|
||||
**さもないと:** 悪意のある JavaScript コードが `eval` やその他のリアルタイムに評価する JavaScript の関数に渡されるテキストへたどり着き、そのページにおける JavaScript の完全な権限を獲得してしまいます。この脆弱性はしばしば XSS 攻撃として顕在化します。
|
||||
|
||||
🔗 [**Read More: Avoid JavaScript eval statements**](/sections/security/avoideval.md)
|
||||
🔗 [**さらに読む: JavaScript の eval 構文を避ける**](/sections/security/avoideval.japanese.md)
|
||||
|
||||
<br/><br/>
|
||||
|
||||
|
||||
@ -1,23 +1,22 @@
|
||||
# Avoid JS eval statements
|
||||
# JavaScript の eval 構文を避ける
|
||||
|
||||
### One Paragraph Explainer
|
||||
### 一段落説明
|
||||
|
||||
`eval()`, `setTimeout()`, `setInterval()`, and `new Function()` are global functions, often used in Node.js, which accept a string parameter representing a JavaScript expression, statement, or sequence of statements. The security concern of using these functions is the possibility that untrusted user input might find its way into code execution leading to server compromise, as evaluating user code essentially allows an attacker to perform any actions that you can. It is suggested to refactor code to not rely on the usage of these functions where user input could be passed to the function and executed.
|
||||
`eval()`、`setTimeout()`、`setInterval()`、そして `new Function()` は Node.js でしばしば利用される、JavaScript の式、文そして連続した文を表す文字列パラメータを受け取るグローバル関数です。これらの関数を利用することをセキュリティ的な懸念は、ユーザーのコードを評価することは本質的には攻撃者にあらゆるアクションを実行することを許すことなので、信頼されていないユーザーの入力がコード実行の中に入り込み、サーバーを危険にさらす可能性があるということです。ユーザーの入力が渡されて実行されるような関数の利用に依存しないようにコードをリファクタすることが推奨されています。
|
||||
|
||||
### Code example
|
||||
### コード例
|
||||
|
||||
```javascript
|
||||
// example of malicious code which an attacker was able to input
|
||||
// 攻撃者が入力できる悪意のあるコードの例
|
||||
const userInput = "require('child_process').spawn('rm', ['-rf', '/'])";
|
||||
|
||||
// malicious code executed
|
||||
// 悪意のあるコードが実行される
|
||||
eval(userInput);
|
||||
```
|
||||
|
||||
### What other bloggers say
|
||||
### 他のブロガーが言っていること
|
||||
|
||||
From the Essential Node.js Security book by [Liran Tal](https://leanpub.com/nodejssecurity):
|
||||
> The eval() function is perhaps of the most frowned upon JavaScript pieces from a security
|
||||
perspective. It parses a JavaScript string as text, and executes it as if it were a JavaScript code.
|
||||
Mixing that with untrusted user input that might find it’s way to eval() is a recipe for disaster that
|
||||
can end up with server compromise.
|
||||
[Liran Tal](https://leanpub.com/nodejssecurity) による書籍 Essential Node.js Security より:
|
||||
> セキュリティの観点から見ると、eval() 関数はおそらく JavaScript の中でもっとも忌み嫌われている部分でしょう。
|
||||
> それは JavaScript の文字列をテキストにパースし、まるで JavaScript コードのように実行します。
|
||||
> これを、eval() へ渡されることが分かっているかもしれない信頼されていないユーザー入力と混ぜることは、サーバーを危険にさらすことになる、崩壊へのレシピといえるでしょう。
|
||||
|
||||
Reference in New Issue
Block a user