Comment faire expirer un nonce?
-
-
Lors de la connexionn'estpas lebonmot.Nonce sera après la connexion ou avant la connexion?During login is not the right word. Nonce will be after login or before login ?
- 0
- 2016-04-15
- Sumit
-
@Sumit,j'ai éditéma réponse,pouvez-vous s'il vousplaîtguidermaintenant?@Sumit , i editted my answer can you please guide now ?
- 0
- 2016-04-15
- Divyanshu Jimmy
-
Cool :) Donc,àmon humble avis,vousn'avezpas à vousen soucier.Parce qu'après la connexionnonce créée à l'aide de l'ID de l'utilisateur connectéet après la déconnexion,l'ID devient 0,la vérificationnonce retournera `false`.Si vous le souhaitez,vouspouvez letester!Cool :) So IMHO you do not need to worry about it. Because after login nonce created using logged-in user's ID and after logout, ID become 0 then nonce verification will return `false`. If you wish you can test it!
- 2
- 2016-04-15
- Sumit
-
@Sumitmerci,j'ai oublié lefait quej'utiliserai l'identifiant d'utilisateur.@Sumit thanks i forgot the fact that i will be using user id .
- 0
- 2016-04-15
- Divyanshu Jimmy
-
yw!À votre santé.. ;)yw! Cheers.. ;)
- 1
- 2016-04-16
- Sumit
-
@sumit vous avez raison,et vous devriezpublier desinformations dans votre commentaireen tant que réponse,afin que la questionpuisse êtremarquée comme répondue au lieu de rester sans réponse.@sumit you are right, and you should post info in your comment as an answer, so the question can be marked as answered instead of stay un answered.
- 1
- 2016-04-16
- gmazzap
-
@gmazzap Je suis désolé d'être absentet maintenant Caspar a déjà répondu à cela :)@gmazzap I am sorry I was away and now Caspar already answered that :)
- 1
- 2016-04-19
- Sumit
-
1 réponses
- votes
-
- 2016-04-18
Leproblème avec l'expiration d'unnonceest que dans WordPress,lesnoncesne sontpas desnonces dans le sens lepluspur duterme: "nombre utilisé unefois". Au contraire,un WPnonceest un hachage (sous-chaîne de a) d'une chaîneimpliquant une signature rythmique aumoment oùil a étégénéré,entre autres: l'ID utilisateur,lenom de l'actionet votrejeton de sessionphp. Entant quetel,unefoisgénéré,ilest ce qu'ilest,sa date depéremptionestintégréeet vousne pouvezpas l'expirer (et vousne pouvezpas laprolonger).
Modifier:
Vouspouvez voir comment lenonceest construit dans
wp-includes/pluggable.php
:function wp_create_nonce($action = -1) { $user = wp_get_current_user(); $uid = (int) $user->ID; if ( ! $uid ) { /** This filter is documented in wp-includes/pluggable.php */ $uid = apply_filters( 'nonce_user_logged_out', $uid, $action ); } $token = wp_get_session_token(); $i = wp_nonce_tick(); return substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 );
Lemêmeensemble de critèresest utilisé dans
wp_verify_nonce()
:nonce_tick (quiest l'élémenttemporel),action,tokenet uid sonttous combinéset hachés dans lemême ordreet comparés à l'élément soumisnonce. Donc,si l'un d'entreeux a changé,les hachagesne correspondentpaset lenonceest rejeté.Fin de lamodification
WP le valide uniquementen indiquant si une chaîne soumise correspond (via
hash_equals()
dephp) à une valeur attenduegénérée lorsque vouspassez la chaînenonce avec l'action. Si lenonceet l'action se combinent avec votre ID utilisateur actuelet votrejeton de sessionpour créer une sous-chaîne de hachage qui correspond au contrôle de hachagetemporel,vous réussissez.Ce quimanquepourfaire d'un WPnonce un "vrai"nonceest une vérificationpour voir s'il a déjà été utilisé/traité unefois auparavant.
L'hypothèse de sécuritéest que celan'apas d'importance,carmême si quelqu'un récupère lenonceet son action correspondante,vous devreztoujours le soumettreen utilisant lemêmeidentifiant d'utilisateuret lemêmejeton de sessionphp sous lequelil a étégénéré - - hautementimprobable àmoins qu'unpiraten'ait détourné votre appareilet ne soit connectéen tant que vous ...mais d'ici là,vous avez un autretype deproblème de sécurité.
The problem with expiring a nonce is that in WordPress, nonces aren't nonces in the purest sense of the term: "number used once." Rather, a WP nonce is a (substring of a) hash of a string involving a time signature at the moment it was generated, among other things: user ID, the action name and your php session token. As such, once generated, it is what it is, it's "use-by" date is baked in, and you can't expire it (and you can't extend it).
Edit:
You can see how the nonce is built in
wp-includes/pluggable.php
:function wp_create_nonce($action = -1) { $user = wp_get_current_user(); $uid = (int) $user->ID; if ( ! $uid ) { /** This filter is documented in wp-includes/pluggable.php */ $uid = apply_filters( 'nonce_user_logged_out', $uid, $action ); } $token = wp_get_session_token(); $i = wp_nonce_tick(); return substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 );
The same set of criteria are used in
wp_verify_nonce()
: nonce_tick (which is the time element), action, token and uid are all combined and hashed in the same order and compared to the submitted nonce. So, if any of these have changed, the hashes will not match and the nonce is rejected.End Edit
WP validates it only by whether a submitted string time-matches (via php's
hash_equals()
) an expected value that is generated when you pass in the nonce string along with the action. If the nonce and action combine with your current user ID and session token to create a hash substring that matches the time-hash check, you pass.What's missing to make a WP nonce a "true" nonce is a check to see if it has already been used/processed once before.
The security assumption is that it doesn't matter, because even if someone gets ahold of the nonce and its corresponding action, you would still need to submit it using the same User ID and php session token under which it was generated -- highly unlikely unless a hacker has hijacked your device and is logged in as you... but by then you have a different kind of security problem.
-
s'il vousplaît voir unpetit exemple dans votre réponse sur lafaçon dont unnoncepeut avoir unjeton de session,entre autrespour dissipermoninquiétude sur lafaçon degérer lepseudononce WPexpirantplease sight a small example in yours answer about how a nonce can have session token among other things to clear my concern on how to handle expiring WP pseudo nonce
- 0
- 2016-04-19
- Divyanshu Jimmy
-
Modifiépourinclure lafaçon dont lejetonestincorporé dansnonce.Edited to include how token is incorporated into nonce.
- 2
- 2016-04-20
- Caspar
Je suis conscient dufait quenouspouvonsmodifier la durée de vienonceen utilisant lefiltre,30 secondesici:
J'ai unefonction logout ()pourmon api de repos. Je souhaitefaireexpirer unnonce quej'ai créé après une connexion réussie:
$nonce = wp_create_nonce( 'login'.$user_id );