経験のあるプログラマー向けの序文 Foreword for Experienced Programmers

Flaskでのスレッド局所的領域(Thread-Locals) Thread-Locals in Flask

Flaskでの設計上の決定のひとつに、シンプルなタスクはシンプルであるべきだというものがあります;それは大量のコードを使わず、それでもあなたを制限しないようにするべきです。この理由によって、ある人たちには驚くべきものまたは不自然なものだと見出されるかもしれない設計上の決定を、Flaskはいくつかしています。例えば、スレッドセーフであり続けるためにリクエスト処理中は関数の間でオブジェクトをたらい回しにすることが不要になるよう、Flaskは内部的にスレッド局所領域(thread-local)オブジェクトを使用します。このアプローチは便利ですが、依存性注入(dependensy injection)やリクエストに釘付けされた値を使用するコードの再利用をするときには、適切なrequest contextを必要とします。Flaskプロジェクトはthread-localについて正直に、それを隠すことはせず、それが使用されるところではコードやドキュメントの中で目立つようにしています。 One of the design decisions in Flask was that simple tasks should be simple; they should not take a lot of code and yet they should not limit you. Because of that, Flask has a few design choices that some people might find surprising or unorthodox. For example, Flask uses thread-local objects internally so that you don’t have to pass objects around from function to function within a request in order to stay threadsafe. This approach is convenient, but requires a valid request context for dependency injection or when attempting to reuse code which uses a value pegged to the request. The Flask project is honest about thread-locals, does not hide them, and calls out in the code and documentation where they are used.

Web向けの注意深い開発 Develop for the Web with Caution

webアプリケーションを構築するときは、常にセキュリティーに注意してください。 Always keep security in mind when building web applications.

もしwebアプリケーションを書いた場合、ユーザーが自分のデータをサーバー上に登録し残していくことをおそらく許すでしょう。ユーザーはデータについてあなたを信頼します。もし自分だけがアプリケーションにデータを残す唯一のユーザーである場合でも、それでもそのデータが安全に格納されることを望むでしょう。 If you write a web application, you are probably allowing users to register and leave their data on your server. The users are entrusting you with data. And even if you are the only user that might leave data in your application, you still want that data to be stored securely.

不幸にも、webアプリケーションの安全性を損なわせる方法が数多く存在します。Flaskは近年のwebアプリケーションで最もありがちなセキュリティ上の問題の一つに対してあなたを守ります: クロスサイトスクリプティング(XSS)に対して。安全でないHTMを安全であると故意に印付け(mark)しない限り、Flaskとその土台にあるJinja2テンプレートエンジンがあなたを守ります。しかしながら、セキュリティ上の問題を引き起こすもっと多くの方法が存在します。 Unfortunately, there are many ways the security of a web application can be compromised. Flask protects you against one of the most common security problems of modern web applications: cross-site scripting (XSS). Unless you deliberately mark insecure HTML as secure, Flask and the underlying Jinja2 template engine have you covered. But there are many more ways to cause security problems.

このドキュメントでは、セキュリティーに注意を払う必要のあるweb開発の側面に関して警告を示すようにしています。これらのセキュリティ上の注意事項は、人が考えるかもしれないことよりもはるかに複雑であり、私たちは皆ときどき脆弱性が悪用されるかもしれない可能性について、アプリケーションを悪用する方法を悪賢い攻撃者が見つけ出すまで、過小評価します。攻撃の種類によっては、データベースをspam、悪意のあるリンクなどで満たす方法で自動化botが証明する(自動化botによって実際に攻撃される)恐れがあります。 The documentation will warn you about aspects of web development that require attention to security. Some of these security concerns are far more complex than one might think, and we all sometimes underestimate the likelihood that a vulnerability will be exploited - until a clever attacker figures out a way to exploit our applications. And don't think that your application is not important enough to attract an attacker. Depending on the kind of attack, chances are that automated bots are probing for ways to fill your database with spam, links to malicious software, and the like.

Flaskは、開発者であるあなたが自分のやりたいことに対して構築するとき、得られるものを見守り(watching for exploits)つつ注意深く構築する必要があることについて、ほかのあらゆるフレームワークと異なることはありません。 Flask is no different from any other framework in that you the developer must build with caution, watching for exploits when building to your requirements.