Skip to Content
ウェブアプリケーションセキュリティ 第2版
book

ウェブアプリケーションセキュリティ 第2版

by Andrew Hoffman
March 2025
Intermediate to advanced
444 pages
6h 9m
Japanese
O'Reilly Media, Inc.
Audio summary available
Content preview from ウェブアプリケーションセキュリティ 第2版

第33章 データとオブジェクトを守る

この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com

は様々な攻撃の標的であるにもかかわらず、アプリケーションコード内のデータとオブジェクトを防御するのは、実際には非常に簡単である。データベース内のデータストア以外では、プログラミング言語がやりとりするほとんどのオブジェクトは、エフェメラル(インメモリ)か永続的(ファイルシステム内)に保存される。

プログラミング言語は主にメモリ内で演算を行うため、永続的なファイルストア・データを扱う場合、ほとんどの場合、データは演算の間だけメモリに取り込まれる。このため、エフェメラル・データに利点をもたらす防御が、ファイルシステム・データにも利点をもたらすケースは多い。

大量代入に対するディフェンス

大量代入攻撃は、ウェブ・アプリケーションのプログラミング中にセキュリティへの配慮がなされていれば、比較的容易に防ぐことができる。次のような代入の脆弱性を考えてみよう:

/*
 * This is a server-side API endpoint for updating player data
 * for the web-based video game "MegaGame".
*/
app.post("updatePlayerData", function(req, res, next) {
 // if client sent back player state data, update in the database
 if (!!req.body.data) {
   db.update(session.currentUser, req.body.data);
   return res.sendStatus(200); // success
 } else {
   return res.sendStatus(400); // error
 }
});

この脆弱性は、開発者がクライアントから送信されたデータを信頼し、悪意のあるユーザによって改ざんされる可能性のあるオブジェクトに基づいてデータベースのフィールドを更新することを選択したために存在する。

この種の代入攻撃に対する一般的に受け入れられる防御策は2つある。

バリデーションと許可リスト

大量代入を緩和する最も簡単な方法は、単にクライアントから受け入れられるフィールドを制限することである。これはallowlistの形で行うのが最も良い。

以下のようなallowlistを作成し、関数db.update() を呼び出す前にバリデーションの形で実装することで、admin フィールドの大量代入が不可能であることを保証することができる:

const allowlist = ["hp", "location"]; // only allow these two fields to be updated

データ転送オブジェクト

、より集中的な緩和策として、データ転送オブジェクト(DTO)と呼ばれる仲介オブジェクトを作成する方法がある。DTOは、サービスや関数呼び出しの間でデータを受け渡すときに使われる。

我々の場合、DTOは以下のようになる:

const DTO = function(hp, location) {
 this.hp = hp;
 this.location = location;
};

すべての受信データをDTOコンストラクタに通すことで、追加パラメータは拒否される。これにより、悪意のあるクライアント・データが ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

ハイパーモダンPython ―信頼性の高いワークフローを構築するモダンテクニック

ハイパーモダンPython ―信頼性の高いワークフローを構築するモダンテクニック

Claudio Jolowicz, 嶋田 健志, 鈴木 駿
Kubernetesで実践するクラウドネイティブDevOps

Kubernetesで実践するクラウドネイティブDevOps

John Arundel, Justin Domingus, 須田 一輝, 渡邉 了介
流暢なReact

流暢なReact

Tejas Kumar

Publisher Resources

ISBN: 9798341627505