0

I have a code in Nodejs server which is using google recaptcha V3 to login a user. It's working perfectly with https://localhost:4000/ but for some wired reason it doesn't work with my example.com website ?!

any suggestion to debug this?

I have added both localhost and example.com to the list of google recaptcha console.

the code pauses before fetch, not going further seems like there is something wrong with fetch???

function login(req, res, next) {
    const secret_key = config.recaptchaSecretKey;
    const token = req.body.token;
    const url = `https://www.google.com/recaptcha/api/siteverify?secret=${secret_key}&response=${token}`;

    // the code pauses here not going further seems like there is something wrong with fetch???
    fetch(url, {
        method: 'post'
    })
    .then(response => response.json())
    .then(google_response => {
        if(!google_response.success || google_response.score < 0.4) {
            return res.json({ success: false, error: "captcha verification failed" });
        }
        accountService.login(req.body) 
            .then(result => {
                res.json(result);
            })
            .catch(next);
    })
    .catch(error => res.json({ error }));
}
Sara Ree
  • 3,417
  • 12
  • 48
  • what do you mean by "pauses before fetch"? how are you determining this pause? – limco Sep 08 '22 at 07:42
  • 1
    does adding `mode: 'cors'` to the fetch options help? seems like it's possibly cors related – limco Sep 08 '22 at 07:46
  • I think it might be the cors problem too, but `mode: 'cors'` didn't fix this – Sara Ree Sep 08 '22 at 08:00
  • hmm in that case, it's back to the comment about first pinpointing exactly how it "pauses" as I'm a little unclear on where the error is occurring – limco Sep 08 '22 at 08:03
  • It doesn't log anything after that point... – Sara Ree Sep 08 '22 at 08:09
  • this is the error::: `reason: Hostname/IP does not match certificate's altnames: Host: www.google.com. is not in the cert's altnames: DNS:amazeservice.net, DNS:www.amazeservice.net` – Sara Ree Sep 08 '22 at 08:12
  • Check this post: https://stackoverflow.com/questions/14262986/node-js-hostname-ip-doesnt-match-certificates-altnames Some posts there report the same issue when switching from localhost. There are some workarounds with security implications, but it looks like using http-proxy works best - depends on your requirements. – limco Sep 08 '22 at 08:18

0 Answers0