koajs / csrf

CSRF tokens for koa
MIT License
264 stars 32 forks source link

risks on ignoring `GET/HEAD` request? #14

Closed luckydrq closed 9 years ago

luckydrq commented 9 years ago

Think of two situations:

  1. if there are some bad designs in someone's code and GET/HEAD methods are used to do write operations in backend, then risks rise.
  2. even if GET/HEAD are used to query data, attackers can easily get data which may be sensitive via csrf.
dead-horse commented 9 years ago
  1. should _never_ use GET/HEAD to update database or other backend data.
  2. if GET/HEAD request need csrf, how can frontend page get the csrf token ?
luckydrq commented 9 years ago

@dead-horse

if GET/HEAD request need csrf, how can frontend page get the csrf token ?

via cookie

luckydrq commented 9 years ago

frontend page makes the GET/HEAD request taking along with the cookie that contains csrf token planted by previous response.

dead-horse commented 9 years ago

how can frontend page get the cookie when they can't GET the server without csrf token.

it is really unnecessary to verify csrf token when GET/HEAD only query the server.

luckydrq commented 9 years ago

yeath, i know what you mean, not every GET page needs a csrf verification.

maybe some sensitive GET pages need such concern while others doesn't.

dead-horse commented 9 years ago

do not use the default middleware, use this.assertCSRF directly.

luckydrq commented 9 years ago

Alright.

uh..i've reconsidered the scenario and it seems my previous concern is not necessary. even if the victim user gets a sensitive GET page requested from an untrusted website(csrf), how would the attacker get the info?