• Resolved Darko A7

    (@darko-a7)


    Hi Jeff,
    Happy holidays ??

    You know that thing when “a new problem” occurs and googling directs to your own post / writing lol?

    related topics:
    https://www.ads-software.com/support/topic/contact-form-7-non-sending-emails/
    https://www.ads-software.com/support/topic/contact-form-7-dont-work-with-disabled-rest-api/

    Yeah, I noticed in error logs that CF7 failed, and given the errors, this plugin was the main suspect. It was 1.5 years ago when I fixed this with a patch, and you should just ask me what it was back then (haven’t noticed further topics and conversations), because it was a very simple patch.

    I didn’t originally post a solution here, because it was a very simple one, and I thought it would be added as an option in the plugin’s settings, because not everyone needs / wants it (e.g. CF7 is not used by everyone).

    Problem: CF7 not sending emails

    jquery.min.js:2 POST https://.../wp-json/contact-form-7/v1/contact-forms/.../feedback 401 (Unauthorized)
    jquery.min.js:2 XHR failed loading: POST "https://.../wp-json/contact-form-7/v1/contact-forms/.../feedback".
    
    rest api response
    {"code":"rest_login_required","message":"REST API restricted to authenticated users.","data":{"status":401}}

    Solution is simple like this:

    in function disable_wp_rest_api() change the line from:

    if (!is_user_logged_in()) {

    to this:

    if ( !is_user_logged_in() && empty($_POST['_wpcf7']) ) {

    It does not check any security tokens.

    Hopefully, you’ll add this in the future, because with each update it stops working, and that could be very bad for many users, unless they apply this patch.

    Thanks!
    Regards

    The page I need help with: [log in to see the link]

Viewing 15 replies - 1 through 15 (of 44 total)
  • Plugin Author Jeff Starr

    (@specialk)

    Hi @darko-a7, thank you for this great feedback, very useful indeed. It shall be done in the next plugin update. Likewise Happy holidays ??

    Thread Starter Darko A7

    (@darko-a7)

    You are welcome ??

    / closed /

    Nice hack, have been looking for a solution, this is it.

    Applied, and looking forward to the next plugin update.

    Thanks both.

    Thinking of another cool addition. Keep API site-wide disabled, but offer whitelist with specific endpoints in combination with supplied url tokens. This way people could use API services without exposing everything.

    • This reply was modified 3 years, 10 months ago by tezalsec.
    Plugin Author Jeff Starr

    (@specialk)

    @tezalsec it sounds interesting, do you have any code example to look at how it may be achieved?

    I worked on some of it in the past, outside of the WP environment, but have no code laying around. I assume it would not have to go deep into the API architecture.

    All you need to do, I guess, is make whitelists that accepts exceptions to your existing disabling code.

    Like in this url:

    https://yoursite.com/wp-json/wp/v2/service?token=regrth57u56guyc3fretwg4t3432@3ttc3t3tw

    The variable elements here are ‘service’, which could be any API service, like Zapier, and the token. The url woudl be parsed before rendering if it connects to wp-json. You could make it so that only the combination of a specific service slug (and thus endpoint) and the token parameter is allowed access to the wp-json. You could make an option to make this more tight by whitelisting static IP adresses. And even more tight, to whitelist certain url parameters, used for querying the endpoint.

    This gives an idea, not for this addition, but in general for creating ones own API plugin: https://webdesign.tutsplus.com/tutorials/how-to-use-the-wordpress-rest-api-a-practical-tutorial–cms-33566

    And your plugin could be configured to whitelist the variable elements: endpoint url, token param, query url params and IP address. Individually, or combined.

    • This reply was modified 3 years, 10 months ago by tezalsec.
    • This reply was modified 3 years, 10 months ago by tezalsec.
    Plugin Author Jeff Starr

    (@specialk)

    Thanks that is very helpful. Sounds like it would just require adding a filter where users could specify their own endpoint and token to allow access. I have added this to the list and will see what I can do for a future update. I appreciate the feedback, @tezalsec.

    PS the tutsplus link leads to a page that doesn’t provide any related infos, just fyi.

    Exactly. I would definitely also add the ip address and url query params as added options. Not necessarily for the big services, but it is a nice way to allow for safe communication between self-managed servers, or business to business data exchange.

    Something like this should be in core, IMO. Like managing ports on a server. Only open what is needed (under controlled conditions), and keep the rest closed. Just allowing it all open with WP-json is bad for security, privacy and resources.

    Weird about the link, yesterday it was an actual article, now it is redirected.

    Good luck, and thanks for your plugin(s).

    • This reply was modified 3 years, 10 months ago by tezalsec.
    Thread Starter Darko A7

    (@darko-a7)

    @tezalsec

    I have created feature request on WordPress Trac here: https://core.trac.www.ads-software.com/ticket/52384

    We’ll see if anyone responds to it. Granted, any of that can be achieved via plugin, but basic features should definitely be in the core.

    Great, Darko, thanks.

    @specialk , thinking about it some more, maybe there is an opportunity here for a whole new plugin, besides the disabling one, named like :

    “WP API Security”

    “Secure your API Access with several optional limiting filters. Protect the security and privacy of your data and your hardware’s resources. Don’t just fully open or close your website’s json data access to the world, but finetune it and only allow specific access to whitelisted services.”

    That would be probably get some attention. More than “just disabling” it.
    ??

    Plugin Author Jeff Starr

    (@specialk)

    @tezalsec I like the idea but keep in mind that API is a general term that refers to any application programming interface, not just the REST API. Here some examples. So maybe something like “REST API Security” would be more suitable. In any case, I definitely like the idea and will take a closer look during the next plugin update. Thanks for sharing ??

    Good point. “REST API Security” it is. ??

    Plugin Author Jeff Starr

    (@specialk)

    Just to follow up with the CF7 bypass, here is the deal. @darko-a7’s elegant solution works great, but also it makes it trivial for anyone to access REST API by simply sending a post variable. Most users would not want this vulnerability introduced. SO, instead I’ve created a simple plugin that you can install alongside Disable WP REST API (version 2.1 or better). Once activated, it enables CF7 to work properly sending emails. Learn more and download at Perishable Press.

    • This reply was modified 3 years, 9 months ago by Jeff Starr. Reason: clarity
    Plugin Author Jeff Starr

    (@specialk)

    Lol my post disappeared..

Viewing 15 replies - 1 through 15 (of 44 total)
  • The topic ‘Contact Form 7 Bypass Solution’ is closed to new replies.