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版

第29章. CSRF攻撃から身を守る

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

第 2 部では、ユーザに代わってリクエストを行うために、ユーザの認証されたセッションを利点とする クロスサイトリクエストフォージェリ(CSRF)攻撃を構築した。CSRF 攻撃は、<a></a> のリンク、<img></img> のタグ、さらにはウェブ・フォームを使った HTTP POST 経由で行われた。CSRF スタイルの攻撃は、高い特権レベルで機能し、多くの場合、認証されたユーザには検出できないので、アプリケーションに対し ていかに効果的で危険であるかを見た。

この章では、そのような攻撃からコードベースを防御する方法を学び、ユーザが認証セッションを標的にするあらゆるタイプの攻撃に対してリスクにさらされる確率を軽減する。

ヘッダ検証

<a></a> リンクを使って構築したCSRF攻撃を覚えているだろうか?その議論では、リンクは電子メールまたはターゲットとは全く別のWebサイト経由で配布された。

多くの CSRF リクエストの原点はウェブ・アプリケーションとは別なので、リクエストの原点をチェックすることで CSRF 攻撃のリスクを軽減することができる。HTTP の世界では、リクエストの元をチェックする際に注目するヘッダが 2 つある:refererorigin 。これらのヘッダが重要なのは、主要なブラウザーではJavaScriptでプログラ ム的に変更できないからである。そのため、適切に実装されたブラウザのreferrer またはorigin ヘッダは、なりすまされる可能性が低い:

オリジン・ヘッダ

origin ヘッダはHTTPのPOSTリクエストでのみ送られる。それはリクエストがどこから発信されたかを示す単純なヘッダである。(HTTPやHTTPSに関係なく)すべてのリクエストに現れるreferer とは異なる。origin ヘッダは以下のようになる:Origin: https://www.mega-bank.com:80.

リファラーヘッダ

referer 、 のヘッダはすべてのリクエストにセットされ、リクエストがどこから来たか も示す。このヘッダが存在しないのは、参照元リンクにrel=noreferer 属性がセットされているときだけである。referer ヘッダは以下のようになる:Referer: https://www.mega-bank.com:80.

POSTリクエストがウェブサーバに行われたとき、例えば、https://www.mega-bank.com/transfer にパラメーamount=1000to_user=123を付けたとき、これらのヘッダの場所が、ウェブサーバを実行している信頼できるオリジンと同じであることを確認できる。このようなチェックのノード実装を以下に示す:

const transferFunds = require('../operations/transferFunds');
const session = require('../util/session');

const validLocations = [
 'https://www.mega-bank.com',
 'https://api.mega-bank.com',
 'https://portal.mega-bank.com'
 ];

const validateHeadersAgainstCSRF ...
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