K0p1-Git / cloudflare-ddns-updater

Dynamic DNS (DDNS) service based on Cloudflare! Access your home network remotely via a custom domain name without a static IP! Written in pure BASH~
MIT License
1.33k stars 372 forks source link

Ensure Cloudflare is returning a valid IP address before comparing old_ip to current IP #73

Open octopop opened 10 months ago

octopop commented 10 months ago

Cloudflare API is down today and as a result at random returns the following instead of the IP address: {"success":false,"errors":[{"code":10000,"message":"Internal authentication error: internal server error"}]}

The causes $old_ip == $ip to fail and force a IP update.

FIX: Sanitize and ensure that the returned string from the API call is actually an IP before comparing. Suggested snippet below adds a comparison to ensure $old_ip is a valid IP first:

if [[ $old_ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then # <== NEW

        # Compare if they're the same
        if [[ $ip == $old_ip ]]; then
        logger "DDNS Updater: IP ($ip) for ${record_name} has not changed."
        exit 0
        fi
fi
K0p1-Git commented 10 months ago

Hi if possible, please submit a pull request!

Sailboat265 commented 10 months ago

Interesting. So Cloudflare will return an JSON response if it's down, and seemingly with a HTTP response code of 200.

Ahhhh I see, that's why my patch fix of catching the HTTP response code didn't work last time on issue #44.

Anyways, just wanna say that ensuring $old_ip is valid should effectively clear out the infamous double Discord webhook bug here.