143
Hidden Features in HTTP by Sumana Harihareswara @brainwane Changeset Consulting

Hidden Features in HTTP

Embed Size (px)

Citation preview

Page 1: Hidden Features in HTTP

Hidden Features in HTTP

by Sumana Harihareswara

@brainwane

Changeset Consulting

Page 2: Hidden Features in HTTP

HTTP Can Do That?!

A collection of bad ideas

by Sumana Harihareswara

@brainwane

Changeset Consulting

Page 3: Hidden Features in HTTP

@brainwane

HTTP

Hypertext

Transfer

Protocol

Page 4: Hidden Features in HTTP

@brainwane

Diagrams!

– Internet Engineering Task Force (IETF) RFC 7230Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing

Page 5: Hidden Features in HTTP

@brainwane

HTTP: crash course

Client Server

Page 6: Hidden Features in HTTP

@brainwane

Client Server

Request

HTTP: crash course

Page 7: Hidden Features in HTTP

@brainwane

Client Server

Request

Response

HTTP: crash course

Page 8: Hidden Features in HTTP

@brainwane

An HTTP Message(Request or Response)

START-LINE

HTTP version (1.1)Request method (GET, POST)Response status code (200, 404, 500)

Page 9: Hidden Features in HTTP

@brainwane

An HTTP Message(Request or Response)

HEADERS

Content­TypeContent­Length…...

START-LINE

HTTP version (1.1)Request method (GET, POST)Response status code (200, 404, 500)

Page 10: Hidden Features in HTTP

@brainwane

An HTTP Message(Request or Response)

HEADERS

Content­TypeContent­Length…...

BODY

START-LINE

HTTP version (1.1)Request method (GET, POST)Response status code (200, 404, 500)

Page 11: Hidden Features in HTTP

@brainwane

Example Request

HEADERS

Host: www.sumana.bizAccept: text/htmlUser­Agent: ScraperBot

BODY

START-LINE

GET / HTTP/1.1

Page 12: Hidden Features in HTTP

@brainwane

Example Response

HEADERS

Content­Type: text/htmlContent­Length: 203Date: Tue, 16 Jun 2015 16:21:56 GMTLast­Modified: Tue, 16 Jun 2015 13:27:14 GMT

BODY<html><head><title>Welcome to Sumanaville</title></head><body><center><h1>Rockin'</h1><p>This is a pretty rockin' site. I'm glad you decided to visit.</p>

<h2>Wheee!</h2></center></body></html>

START-LINE

HTTP/1.1 200 OK

Page 13: Hidden Features in HTTP

@brainwane

● GETgimme

● POSThere you go

Popular request methods(“verbs”)

Page 14: Hidden Features in HTTP

@brainwane

First bad idea:POST but not GET

more: https://github.com/brainwane/secureapi

Page 15: Hidden Features in HTTP

@brainwane

POST but not GET:use cases

letters to Santa Claus

Page 16: Hidden Features in HTTP

@brainwane

POST but not GET:use cases

employee suggestion box

Page 17: Hidden Features in HTTP

@brainwane

POST but not GET:use cases

extremely moderated blog comments

Page 18: Hidden Features in HTTP

@brainwane

(a logistical note)

Page 19: Hidden Features in HTTP

@brainwane

Page 20: Hidden Features in HTTP

@brainwane

Page 21: Hidden Features in HTTP

@brainwane

Bad Idea Scale

Page 22: Hidden Features in HTTP

@brainwane

Giving client no way to GET –bad idea

Page 23: Hidden Features in HTTP

@brainwane

Remember “CRUD”?

Create Read

DeleteUpdate

Page 24: Hidden Features in HTTP

@brainwane

Remember “CRUD”?

Create

POST

Read

GET

Delete

POST

Update

POST

Page 25: Hidden Features in HTTP

@brainwane

Remember “CRUD”?

Create

POST

Read

GET

Delete

POST

Update

POST

Page 26: Hidden Features in HTTP

@brainwane

Remember “CRUD”?

Create

POST

Read

GET

Delete

POST

Update

POST

INELEGANT!

INELEGANT!

Page 27: Hidden Features in HTTP

@brainwane

DELETEdelete a resource!

Underappreciated methods

Page 28: Hidden Features in HTTP

@brainwane

Implementing DELETE

Page 29: Hidden Features in HTTP

@brainwane

Implementing DELETE

Page 30: Hidden Features in HTTP

@brainwane

Implementing DELETE

Page 31: Hidden Features in HTTP

@brainwane

Implementing DELETE

Page 32: Hidden Features in HTTP

@brainwane

Implementing DELETE

Page 33: Hidden Features in HTTP

@brainwane

Implementing DELETE

Page 34: Hidden Features in HTTP

@brainwane

Implementing DELETE

Page 35: Hidden Features in HTTP

@brainwane

Implementing DELETE

Page 36: Hidden Features in HTTP

@brainwane

Implementing DELETE

Page 37: Hidden Features in HTTP

@brainwane

Implementing DELETE

Page 38: Hidden Features in HTTP

@brainwane

DELETE – good idea?

Page 39: Hidden Features in HTTP

@brainwane

PUT“here you go”

Underappreciated methods

Page 40: Hidden Features in HTTP

@brainwane

I thought POST meant “here you go”

Wait

Page 41: Hidden Features in HTTP

@brainwane

So what is POST,anyway?

The standard says it means:

“Above our pay grade; take this to the boss”

a.k.a. Overloaded POST

Page 42: Hidden Features in HTTP

@brainwane

So what is POST,anyway?

Often, we use it for:

“Create a new item in this set”

a.k.a. POST-to-append

Page 43: Hidden Features in HTTP

@brainwane

Page 44: Hidden Features in HTTP

@brainwane

PUT vs. POSTPUT /cards/5

Body:

Means:

“Put this picture at /cards/5 .”

POST /cards/5

Body:

Means:

“Tell the webapp that this picture applies to /cards/5 somehow – figure it out.”

Page 45: Hidden Features in HTTP

@brainwane

“CRUD” & HTTP verbs

Create

PUT

Read

GET

Delete

DELETE

Update

PUT

Page 46: Hidden Features in HTTP

@brainwane

PUT – good idea?

Page 47: Hidden Features in HTTP

@brainwane

● PATCHupdate just part of this document/resource

More underused methods

Page 48: Hidden Features in HTTP

@brainwane

PATCH – good idea?

Page 49: Hidden Features in HTTP

@brainwane

● PATCHupdate just part of this document/resource

● OPTIONSask what verbs the client’s allowed to use (for a specific path, or server-wide)

More underused methods

Page 50: Hidden Features in HTTP

@brainwane

OPTIONS – good idea?

Page 51: Hidden Features in HTTP

@brainwane

 HEADlike GET, but just for metadata

A super-cool method

Page 52: Hidden Features in HTTP

@brainwane

GET vs. HEAD

Request:

GET / HTTP/1.1

Response:● Start-line● Headers● Body

Request:

HEAD / HTTP/1.1

Response:● Start-line● Headers

Page 53: Hidden Features in HTTP

@brainwane

HEAD saves time

Page 54: Hidden Features in HTTP

@brainwane

HEAD saves time

Page 55: Hidden Features in HTTP

@brainwane

HEAD saves time

Page 56: Hidden Features in HTTP

@brainwane

You don’t need the body to check:

Does it exist?Do I have permission to GET it?

Content­LengthLast­ModifiedContent­Type

ETagRetry­After

Page 57: Hidden Features in HTTP

@brainwane

HEAD – good idea?

Page 58: Hidden Features in HTTP

@brainwane

Popular headers include:

Content­TypeContent­Length

Page 59: Hidden Features in HTTP

@brainwane

Popular headers include:

Content­TypeContent­Length

Also known as MIME or Mime

Page 60: Hidden Features in HTTP

@brainwane

Popular headers include:

Content­TypeContent­Length

text/*

Page 61: Hidden Features in HTTP

@brainwane

Popular headers include:

Content­TypeContent­Length

application/*

Page 62: Hidden Features in HTTP

@brainwane

Popular headers include:

Content­TypeContent­Length

chemical/*

Page 63: Hidden Features in HTTP

@brainwane

Popular headers include:

Content­EncodingAccept­EncodingContent­LanguageAccept­Language

Page 64: Hidden Features in HTTP

@brainwane

More headers

ETagIf­Match

If­None­Match

Page 65: Hidden Features in HTTP

@brainwane

More headers

If­Modified­SinceIf­Unmodified­Since

Last­ModifiedCache­Control

Page 66: Hidden Features in HTTP

@brainwane

A popular header

User­Agent

Page 67: Hidden Features in HTTP

@brainwane

An unpopular header

From

The email addressof the person making the request

Page 68: Hidden Features in HTTP

@brainwane

Uses for From

Really bad auth

Page 69: Hidden Features in HTTP

@brainwane

Uses for From

“Yes, I saw your site launch”

Page 70: Hidden Features in HTTP

@brainwane

Uses for From

Coded messagesmeant for network surveillor

Page 71: Hidden Features in HTTP

@brainwane

From – bad idea

Page 72: Hidden Features in HTTP

@brainwane

Another spy trick

“Each header field consists of a case-insensitive field name followed by a colon (":")...”

So: vary the case of the headers you send!!!

– Internet Engineering Task Force (IETF) RFC 7230Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing

Page 73: Hidden Features in HTTP

@brainwane

Header casingas secret info channel –

bad idea

Page 74: Hidden Features in HTTP

@brainwane

A popular header

Host

Page 75: Hidden Features in HTTP

@brainwane

A required header

Host

required in request messages

Page 76: Hidden Features in HTTP

@brainwane

$ netcat myhostname.tld 80

GET /bicycle HTTP/1.1

Host: myhostname.tld

Host & path work together

Page 77: Hidden Features in HTTP

@brainwane

Host & path work together

Page 78: Hidden Features in HTTP

@brainwane

Host & path work together

Page 79: Hidden Features in HTTP

@brainwane

Host & path work together

Page 80: Hidden Features in HTTP

@brainwane

Host & path work together

Page 81: Hidden Features in HTTP

@brainwane

A popular header

Host

(wait –why do we need to repeat this?

It's in the URL!right?)

Page 82: Hidden Features in HTTP

@brainwane

How Host helps

HTTPis separate from

the Domain Name System

Page 83: Hidden Features in HTTP

@brainwane

How Host helps

Hosthelps route requests

among different domainsthat sit on the same server

Page 84: Hidden Features in HTTP

@brainwane

Examples of virtual hosts

www.debian.org

Page 85: Hidden Features in HTTP

@brainwane

Examples of virtual hosts

bugs.debian.org

Page 86: Hidden Features in HTTP

@brainwane

Examples of virtual hosts

lists.debian.org

Page 87: Hidden Features in HTTP

@brainwane

Examples of virtual hosts

wiki.debian.org

Page 88: Hidden Features in HTTP

@brainwane

But watch out...

Page 89: Hidden Features in HTTP

@brainwane

But watch out...

Page 90: Hidden Features in HTTP

@brainwane

But watch out...

Page 91: Hidden Features in HTTP

@brainwane

A spam story

Page 92: Hidden Features in HTTP

@brainwane

A spam story

My 404 logs (Drupal admin console):

TYPE page not found

DATE Thursday, October 9, 2014 - 10:46

USER Anonymous (not verified)

LOCATION http://myphishingsite.biz/http://myphishingsite.biz

REFERRER

MESSAGE ttp://myphishingsite.biz

SEVERITY warning

HOSTNAME [IP address]

Page 93: Hidden Features in HTTP

@brainwane

A spam story

My 404 logs (Drupal admin console):

TYPE page not found

DATE Thursday, October 9, 2014 - 10:46

USER Anonymous (not verified)

LOCATION http://myphishingsite.biz/http://myphishingsite.biz

REFERRER

MESSAGE ttp://myphishingsite.biz

SEVERITY warning

HOSTNAME [IP address]

Page 94: Hidden Features in HTTP

@brainwane

A spam story

My access logs:

[IP address] ­ ­ [09/Oct/2014:10:46:09 ­0400]

"GET http://myphishingsite.biz HTTP/1.1" 404 7574 "­" [User­Agent]

Page 95: Hidden Features in HTTP

@brainwane

A spam story

Legit mistakes would look like:

[IP address] ­ ­ [09/Oct/2014:10:46:09 ­0400]

"GET /http://berkeley.edu HTTP/1.1" 404 7574 "­" [User­Agent]

Page 96: Hidden Features in HTTP

@brainwane

A spam story

Intentionally malform your request!

$ netcat myhostname.tld 80

GET http://spam.com HTTP/1.1

Host: spam.com

Page 97: Hidden Features in HTTP

@brainwane

A spam story

Intentionally malform your request!

$ netcat myhostname.tld 80

GET /viagra­bitcoin HTTP/1.1

Host: spam.com

Page 98: Hidden Features in HTTP

@brainwane

404 spamming –bad idea

Page 99: Hidden Features in HTTP

@brainwane

Define your own header!

“Header fields are fully extensible: there is no limit on the introduction of new field names, each presumably defining new semantics, nor on the number of header fields used in a given message.”

-(RFC 7230)

Page 100: Hidden Features in HTTP

@brainwane

Define your own header!

X­blah­blah­blah

Page 101: Hidden Features in HTTP

@brainwane

Define your own header!

X­Clacks­Overhead: GNU Terry Pratchett

Page 102: Hidden Features in HTTP

@brainwane

Define your own header!

Page 103: Hidden Features in HTTP

@brainwane

Define your own header!

Page 104: Hidden Features in HTTP

@brainwane

Define your own header!

Page 105: Hidden Features in HTTP

@brainwane

Define your own header!

Page 106: Hidden Features in HTTP

@brainwane

Defining your own headers –good idea?

Page 107: Hidden Features in HTTP

@brainwane

Status codes

100 & 101: Informational2xx: Successful3xx: Redirection4xx: Client error5xx: Server error

Page 108: Hidden Features in HTTP

@brainwane

Status (response) codes

404 Not Found

Code Reason-phrase

Page 109: Hidden Features in HTTP

@brainwane

Status (response) codes

“A client SHOULD ignore

the reason-phrase content.”

Page 110: Hidden Features in HTTP

@brainwane

Heard of these?

● 410 GoneIt was here, but now it’s not.

● 304 Not ModifiedYou said, ‘GET this, if it’s been modified since [date]’. It hasn’t been.

Page 111: Hidden Features in HTTP

@brainwane

451 Unavailable For Legal Reasons

Server is legally required

to reject client’s request

Page 112: Hidden Features in HTTP

@brainwane

451 Unavailable For Legal Reasons

Can’t let you see that; it’s censored.

Page 113: Hidden Features in HTTP

@brainwane

451 Unavailable For Legal Reasons

“This is considered a client-side error even though the request is well formed and the legal requirement exists on the server side. After all, that representation was censored for a reason. There must be something wrong with you, citizen.”

-RESTful Web APIs,

Leonard Richardson & Mike Amundsen

Page 114: Hidden Features in HTTP

@brainwane

451 Unavailable For Legal Reasons

Page 115: Hidden Features in HTTP

@brainwane

451 – good idea?

Page 116: Hidden Features in HTTP

@brainwane

WTF responses

All of thesewere found in the wild

Page 117: Hidden Features in HTTP

@brainwane

WTF responses

Code: 126

Reason: Incorrect key file for table '/tmp/mysqltmp/#sql_13fb_2.MYI'; try to repair it SQL=SHOW FULL COLUMNS FROM `y4dnu_extensions`

Page 118: Hidden Features in HTTP

@brainwane

WTF responses

Code: 301

Reason: explicit_header_response_code

Page 119: Hidden Features in HTTP

@brainwane

WTF responses

Code: 403

Reason: You've got to ask yourself one question: Do I feel lucky?

Page 120: Hidden Features in HTTP

@brainwane

WTF responses

Code: 403

Reason: can't put wasabi in bed

Page 121: Hidden Features in HTTP

@brainwane

WTF responses

Code: 404

Reason: HTTP/1.1 404

Page 122: Hidden Features in HTTP

@brainwane

WTF responses

Code: 404

Reason: Not Found"); ?><?php Header("cache-Control: no-store, no-cache, must-revalidate

Page 123: Hidden Features in HTTP

@brainwane

WTF responses

Code: 200

Reason: Forbidden

Page 124: Hidden Features in HTTP

@brainwane

WTF responses

Code: 404

Reason: Apple WebObjects

Page 125: Hidden Features in HTTP

@brainwane

WTF responses

Code: 404

Reason: forbidden

Page 126: Hidden Features in HTTP

@brainwane

WTF responses

Code: 434

Reason: HTTP/1.1 434

Page 127: Hidden Features in HTTP

@brainwane

WTF responses

Code: 451

Reason: Unknown Reason-Phrase

Page 128: Hidden Features in HTTP

@brainwane

WTF responses

Code: 503

Reason: Backend is unhealthy

Page 129: Hidden Features in HTTP

@brainwane

WTF responses

Code: 520

Reason: Origin Error

Page 130: Hidden Features in HTTP

@brainwane

WTF responses

Code: 525

Reason: Origin SSL Handshake Error

Page 131: Hidden Features in HTTP

@brainwane

WTF responses

Code: 533

Reason: mtd::http: Unknown: Banned

Page 132: Hidden Features in HTTP

@brainwane

WTF responses

Code: 732

Reason: http://www.[hostname].com/intro/copyright.php

Page 133: Hidden Features in HTTP

@brainwane

WTF responses

Code: 999

Reason: Request denied

Page 134: Hidden Features in HTTP

@brainwane

Changing Reason-phrases

more at https://gitlab.com/brainwane/http-can-do-that/

Page 135: Hidden Features in HTTP

@brainwane

Page 136: Hidden Features in HTTP

@brainwane

Page 137: Hidden Features in HTTP

@brainwane

Bespoke status codes/reasons – good idea?

Page 138: Hidden Features in HTTP

@brainwane

There’s so much more

● “Don’t cache this”● Pragma – pass instructions to server/client

● CONNECT, TRACE, LINK, & UNLINK methods

● 409 Conflict

● Look-before-you-leap requests● Resources at HTTPS vs. HTTP URLs can differ● “q” and preference ranking in the Accept header● Content-Disposition (e.g. “attachment”)

Page 139: Hidden Features in HTTP

@brainwane

The feeling of power

The sense of wonder

Page 140: Hidden Features in HTTP

@brainwane

What might the web have been?

What might it still be?

Page 141: Hidden Features in HTTP

@brainwane

Read & play

● RFCs 7230-7235● netcat, wget, netstat, telnet

● basic HTTP servers (in your favorite language)● https://gitlab.com/brainwane/http-can-do-

that/

Page 142: Hidden Features in HTTP

@brainwane

Thanks

Leonard RichardsonGreg HendershottZack Weinberg

The Recurse CenterClay Hallock

Paul TagliamonteOpen Source Bridge

Julia Evans, Allison Kaptur, Amy Hanlon, and Katie Silverio

Page 143: Hidden Features in HTTP

Thank you

Sumana Harihareswara

http://changeset.nyc

@brainwane

https://gitlab.com/brainwane/http-can-do-that/

[email protected]