Come prevenire CSRF se vuoi includere plugin Flash nel tuo modulo come Uploadify nel tuo modulo?

5

Che cos'è CSRF?

Ho bisogno di una definizione di base che non sia appena stata sollevata da Wikipedia.

Comprendo l'iniezione SQL, l'XSS, l'avvelenamento da cookie, ma non riesco a spiegarmelo.

Sto usando un framework, CakePHP , che ha un componente che impedisce automaticamente questo CSRF. Tuttavia, ogni volta che faccio qualcosa alla forma come usare jQuery per modificare i valori del campo. O quando includo un Ajax che funziona con plugin Flash come Uploadify , ho bisogno di disabilitare CSRF.

SO in che modo, in linea di principio, prevengo a prevenire CSRF quando tali elementi sono coinvolti nel modulo?

    
posta Kim Stacks 18.01.2011 - 17:26
fonte

1 risposta

7

CSRF o Cross-Site Request Forgery è fondamentalmente una cattiva persona che inganna il browser di una persona buona per eseguire funzioni sul tuo sito web per conto delle persone non autorizzate.

Ecco un esempio:

  1. Good user logs into your website and obtains a valid session
  2. Bad user tricks good user into following a link to a malicious site
  3. Malicious site contains a form with falsified data which posts to your website (however since it's sent from client side, your site thinks it originated from the good user)
  4. Your site then see's the good user submitted a form and processes the action.

Mettiamolo nel contesto:

  1. Good user is an administrator on your website.
  2. From the admin panel, good user can add a user by filling out a form that looks like this:

    <form action="/new_user.php" name="myform" method="POST">
        <input type="text" name="new_username">
        <input type="password" name="new_password">
        <input type="Submit">
    </form>
    
  3. Good user follows a link to a malicious site, which contains the following javascript:

    <form action="http://www.yoursite.com/new_user.php" name="myform" method="POST">
        <input type="hidden" name="new_username" value="MaliciousHax0r">
        <input type="hidden" name="new_password" value="MaliciousPass">
    </form>
    <script type="text/javascript">
        document.myform.submit();
    </script>
    
  4. Your application now receives the request which was submitted by Good user, on Bad user's behalf. Since it originated from Good user, who happens to be logged into your website, all is well and your website processes the request.

Now keep in mind this is a simple example, and the Good user would see the submit happen which SHOULD raise a red flag, however using slightly more complex methods, such as XMLHttpRequest() in javascript would be silent/unknown to the Good user.

Bad user has now obtained an account on your system.

Come eliminare CSRF:

  1. The trick is to add a token to each form that has a random value which is generated for each request.
  2. When the form is submitted, your application checks to make sure the token is passed, and matches the random one which was generated when the form was loaded.

The malicious site wouldn't have access to this token, therefore it wouldn't be able to provide that required peice, and a form submission would not be processed.

Come far funzionare altri strumenti senza disattivare la protezione CSRF in CakePHP:

Non lo so. Controlla la documentazione per la protezione CSRF, per CakePHP e per gli altri componenti aggiuntivi.

Chiedi se usare o meno questi add-on vale la perdita di protezione CSRF e considera soluzioni alternative.

Risorsa CSRF:

link

    
risposta data 18.01.2011 - 19:17
fonte

Leggi altre domande sui tag