
session.cookie_httponly = True
hash-based defence CSRF validation token has not been implemented in WordPress because if done, it would hinder the trackbacks and pingbacks features of WordPress. Server cannot distinguish illegal CSRF request from legal PINGBACK/TRACEBACK request, wordpress automatically accept comment without correct CSRF-token as a PINFBACK and TRACEBACK request and filter that comment with a white-list filter.
To defence this CSRF vulnerability, we add a new field in the form called hashnonce to verify that the comment is send by administrator. The admin sign a signature on the value of comment field with their cookie.
The signature of the value of comment field used md5 to generated the hash value(see graph ).
When admin tries to adopt PINFBACK and TRACEBACK and the _wp_unfiltered_html can not be provided, we use the wp_verify_hashNonce. If the validation fails, an error will be reported. Even if the validation is successful, the logic error has been corrected and "wp_filter_kses" will be used to filter comments.
Code modified:
the third method is change from https://github.com/sijiahi/Wordpress_cve-2019-9787_defense