安全なウェブアプリケーションの作成?運用?閲覧?

体系的に学ぶ 安全なWebアプリケーションの作り方 第2版 脆弱性が生まれる原理と対策の実践』 という本を読みました。

私は(WEB上のマニュアルやドキュメントであればともかく)脆弱性を専門に扱った書籍に触れるのは初めて、フロントエンドも専門外なので、知らないことが幾つも掲載されていて勉強になりました。

脆弱性の実物に触れることを重視していると筆者が前文に書かれているように、主にWEBブラウザ操作に関連する脆弱性とそれに関連した攻撃手法が具体的に解説されており、配布されている実習環境を用いて脆弱性を体験できる構成になっています。

その内容もSQLインジェクション、OSコマンドインジェクション、スピアフィッシングと言ったよく知られたものから文字コードの取り扱いやファイルアップロードに関連する脆弱性まで詳しく説明されています。

本書のタイトルこそ『安全なWebアプリケーションの作り方』ですが、作る側よりもむしろ(ブログソフトウェアやアップローダを使用したサイトの管理者を含めた)使う側に向けたメッセージなのではないかと思わせる項目も少なからずあります。

少なくともクリックジャギング(詳しくは本書を読んでください)などの一部の項目に関しては、意図して実装するのは攻撃者だけなのではないかという感想を抱きます。これだけに関して言えば、脆弱性を把握していなければならないのは閲覧者です。

作成者と利用者(プログラムを利用したウェブサイト・サービスの管理者を含む)のどちらに向けて書かれた内容なのだろうという疑問は読中は常につきまといます。




セキュリティ意識の高くない私でも知っているようなことは多くの人がおそらく理解しています。

そんな私でも(過去に見たことがないから)きっと自分でも書かないようなコードが危険で非推奨となっている例などをみると、ウェブアプリケーションの利用者側に向けて書かれた内容なのだろうかという思いを改めて強くします。

もちろん作成者だけでなく、それを利用する管理者や閲覧者が脆弱性を把握して対策することが重要なのは言うまでもないことです。しかし、誰がどこまで把握しておくべきなのかを考えると線引きは簡単ではありません。

プログラミング言語を専門にしていないウェブデザイナが JavaScript ライブラリを多用したり、コンテンツ管理システムを使ってウェブサイトを自作したりすることは特に珍しいことではありません。

ところが最新の情報セキュリティを継続的に学び続けているのは、誠に失礼ながら専門家を除けば、知っておかなければならない立場にある一部の開発者や管理者に限られる印象を受けます。

本書の内容も、ウェブの利用者なら誰も知っていて損はないものですが、具体的な対策となるとソースコードを見た瞬間に、サーバやデータベースやウェブブラウザで何が起こるかを把握できないとどうしようもありません。

取り上げられている事例だけでも、呆れるほど多彩な手段で執拗にセッションやクッキーが狙われていることが分かったり、インジェクション攻撃でどれだけ簡単に情報を盗んだり、システムを破壊したりすることができるのかを実例を通して理解でき、実習環境上で簡単に再現できる(責任者の説得にも使える)という点では誰にとっても有益ですが、そこから更に進んで対策を行う段階ではウェブブラウザやOSだけでなくプログラミング言語や文字コード、さらには通信の仕組み等についても正確な理解が必要とされるのが難しいところです。

実習環境では主に PHP が用いられているものの、正規表現など基本的な知識を有していれば、PHP を知らなくても問題なく読めます。

自分で PHP を書くことはありませんし、PHP や Perl の CGI を扱うぐらいならば、よく使われている Java や Ruby で良いのに(個人的にはサーバサイド JavaScript/TypeScript 推し)ぐらいには思っていますが、そんな私でも言語の問題で躓くことはありませんでした。

ただし、HTMLメソッドやブラウザやサーバの機能についての理解は必要ですし、本書に詳しい説明はありませんので全く知識のない方は、先にウェブプログラミングを対象とした書籍を何冊か読まれたほうが良いかと思われます。対象の都合上、どうしてもソースコードやログを読み込んでいかないと本書の内容を完全には理解できません。

このように(解説は平易でわかりやすいのですが)敷居はそれなりに高いので誰にでも薦められるわけではないものの、アプリケーションを作る開発者だけでなく利用者にとっても有益な良書という感想を抱きました。

だからこそ、誰に向けて書かれたセキュリティの入門書なのだろうという疑問が生じるのかもしれません。

Finding High-Quality US ASCII English Keyboards in Japan

As a teenager I often took advantage of living in Vienna and traveled across Central Europe by bus. In those days, there existed highway buses going down the same path as Vindobona, a long distance passenger train connecting Vienna and Berlin via Brno, Prague and Dresden. I occasionally took one of those highway buses to Bohemia and stayed in a cheap youth hostel.

There I encountered something I could never handle; the Czech keyboard. The keyboard looked similar to the German keyboard I was familiar with but the @ symbol shared the key with the number 2 and Czech/Sorbian letter ě. Finding a way to type the @ symbol was kinda difficult, while it was essential to check your email and chat histories.

There was no such thing as free Wi-Fi at that time. Nobody ever had smartphones, tablet computers or wireless travel routers. Every guest was encouraged to go to the front lobby or the computer room to use desktop computers with internet access. And all the computers had Czech keyboards. Because of the different keyboard layout, I could never use the computers properly and succeed logging in to neither Googlemail (Gmail service provided in Germany) nor facebook, while I was staying in the Czech Republic. I guess this was the first moment I became aware of keyboard layouts.

After returning from my weekend trip, I started learning to use the 104-key US ANSI keyboard. Since then, I’ve been using the US keyboard to write source code for my programs, edit TeX documents, type commands to the computer and do many other things. I must have wanted the standard keyboard available everywhere on the planet. I’m still not sure whether I was really on the right track. But my decision has helped me immensely, since I moved back from Vienna to Kyoto.




There are several US English layout keyboards sold in Japan. Some are expensive, others cheap. And the most of them are made by domestic brands and sold only in the internal market.

It’s really hard to identify good and poor keyboards without touching them. They look all the same in pictures but are different in build quality, have different switches and provide different typing experience. The differences can affect your performance as much as the keyboard layout. Finding the right keyboard will surely improve the comfort of your computer.

Here, I list three really good keyboards you may want to check at your nearest electronics store.



PFU Happy Hacking Keyboard Professional2 PD-KB400B

PFU’s Happy Hacking keyboard is one of the most beloved US keyboards in this country. Even though its layout is totally different from the Japanese keyboard, many computer programmers prefer this small keyboard over any other input devices. They appreciate the HHKB’s quality, reliability and minimalist layout that, in their words, enhances typing performance.

The HHKB isn’t just an ordinary compact keyboard; its layout is highly optimized for the UNIX environment. The keyboard has only 60 keys. The control key isn’t located on the bottom left side but to the left of the ‘A’ key. And there are neither function nor cursor keys on the board (they are mapped on the Fn layer, though).

The HHKB layout is much different from the common 104 keys layout you’re probably familiar with. If you are looking for a standard full-sized ANSI keyboard in Japan, you would be interested in either TOPRE Realforce or FILCO Majestouch. But if you write source code every day and night or are searching for a good, Linux-friendly keyboard, you would love this programming keyboard.



東プレ/TOPRE Realforce 104U-S 英語配列 XF01TS

Well known as the quiet mechanical keyboard, TOPRE’s Realforce is widely supported by clerical workers, typists, writers and those who sit in front of a computer screen for hours each day.

The Realforce isn’t really a mechanical keyboard but a hybrid of a mechanical and a rubber dome. TOPRE’s hybrid switches have different characteristics from other mechanical switches. Some people become addicted to the feel. Its switches, solid heavy body and high-profile spherical keycaps are all dedicated to your comfort.

And there are also 87-Key ANSI English Layout keyboards out there.



FILCO Majestouch Convertible2 FKBC104M (茶軸/Brown)

If you find that the typing feel of the Realforce or TOPRE switches is not for you, it’s time to consider FILCO Majestouch. It’s a mechanical keyboard with the Cherry MX switches.

In comparison with the Realforce, the Majestouch makes relatively loud clicking sounds. And the Majestouch has smooth-surfaced keycaps with visible lettering, while the Realforce has keys with a non-smooth surface. They both are thick and heavy.

I myself have been using a Majestouch for years. It’s just a good keyboard and feels simply the best on my hands. Touch one and you’ll instantly understand what I mean!

What you can do when your Android Studio could not start AVD on Ubuntu 18.04

After experiencing repeated sudden system crashes, I decided to update my Linux environment. Since then, my Android Studio stopped working properly. Several problems were found with the AVD, JVM and Gradle project sync and so forth. And I needed to spend my weekend fixing one problem after another.

I had kvm installed, added myself to its users group and rebooted the system.

$ kvm --version
QEMU emulator version 2.11.1(Debian 1:2.11+dfsg-1ubuntu7.2)
Copyright (c) 2003-2017 Fabrice Bellard and the QEMU Project developers

$ kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used

$ ls -l /dev/kvm 
crw-rw---- 1 root kvm 10, 232 May 28 18:20 /dev/kvm

$ grep kvm /etc/group
kvm:x:128:femoghalvfems

Still it didn’t make any difference. The IDE kept showing the message “Error while waiting for device: Could not start AVD” and would never start the emulator.




This gave no clue what was going on. There had to be permission problems, I suspected. I changed the permission of the directory.

$sudo chmod 777 /dev/kvm

Of course, I knew it is usually not a good idea. Granting the full control permission to everyone would pose a threat to the entire system and even possibly cause another problem. But it worked, anyway. As I changed the directory permission, I became able to build apps using Android studio.

Unfortunately, the case was not yet closed. In the following hours, I got another system crash and had to reinstall the whole system from a bootable flash drive. My workstation contained NVIDIA and CUDA property drivers that conflicted with some other modlues from time to time. They froze all the processes and threads. I could not even raise skinny elephants.

So I reinstalled Ubuntu 18.04 LTS on my workstation and tried building apps with the latest Android Studio.

This time, I could open the AVD by simply adding myself to kvm user group. And it worked well! I didn’t do anything other than newly install a series of the required virtualization tools and add a new user. And it worked!

$ sudo adduser femoghalvfems kvm
Adding user `femoghalvfems' to group `kvm' ...
Adding user femoghalvfems to group kvm
Done.

Now I really don’t know what prevented the IDE from running the virtual machine.