akhoury / nodebb-plugin-spam-be-gone

yup
MIT License
23 stars 25 forks source link

SyntaxError with simple-recaptcha #28

Closed ananace closed 1 year ago

ananace commented 9 years ago

Forum has been crashing with the following error recently;

20/1 14:42 [27894] - error: SyntaxError: Unexpected token <
at Object.parse (native)
at IncomingMessage.<anonymous> (/var/www/NodeBB/node_modules/nodebb-plugin-spam-be-gone/node_modules/simple-recaptcha/index.js:44:23)
at IncomingMessage.emit (events.js:117:20)
at _stream_readable.js:929:16
at process._tickDomainCallback (node.js:463:13)

I'm running NodeBB v0.6.0 with spam-be-gone v0.4.0, if that helps.

akhoury commented 9 years ago

Weird, ..

could you put a log statement right before the parse statement on line 44

   response.on('end', function() {
      console.log(options, body); // add this one

      // also to prevent the crash you wrap it with a try/catch
      var data = {};
      try{ data = JSON.parse( body ); }
      catch (e) {}

      if (!data.success) return cb(new Error(data['error-codes']));
      cb(null);
    });

the simple-recaptcha module that I'm using a fork, so we can't create issues but we can create pull requests if you can help me debug the issue

Remember to obfuscate your private key if it shows up in the logs

ananace commented 9 years ago

Changes have been applied and I've activated recaptcha again, I'll report back once I get another error.

ananace commented 9 years ago

There we go, now I have an update for you;

{ host: 'www.google.com',
  port: 443,
  path: '/recaptcha/api/siteverify?secret=REDACTED &remoteip=REDACTED&response=REDACTED',
  method: 'GET',
  headers: { 'Content-Type': 'application/x-www-form-urlencoded' } } '<!DOCTYPE html>\n<html lang=en>\n  <meta charset=utf-8>\n  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">\n  <title>Error 400 (Bad Request)!!1</title>\n  <style>\n    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/errors/logo_sm_2.png) no-repeat}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/errors/logo_sm_2_hr.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/errors/logo_sm_2_hr.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/errors/logo_sm_2_hr.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:55px;width:150px}\n  </style>\n  <a href=//www.google.com/><span id=logo aria-label=Google></span></a>\n  <p><b>400.</b> <ins>That’s an error.</ins>\n  <p>Your client has issued a malformed or illegal request.  <ins>That’s all we know.</ins>\n'
Error:  [SyntaxError: Unexpected token <]

I think the problem is that a space seems to have appeared at the end of my private key, no idea when this happened though since I haven't touched the keys since first adding them when installing the plugin...

Maybe something to check, just to be sure. Strip spaces from the value when saving, if they're going to be fed directly into a request URI later on.

akhoury commented 9 years ago

ah ok, thanks, I will also add a try/catch block in the core so it won't crash the server.