diff options
| author | Adam Soltys <[email protected]> | 2020-05-11 20:34:32 -0400 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2020-05-11 20:34:32 -0400 |
| commit | 23a9c10cc6ad2974ab73747606cdbe6015d861b9 (patch) | |
| tree | 0d6e067db9dd15bc9609e345b19ce4f33bde1be5 /routes | |
| parent | 02b41fa0b8009b7bd966787656d5a5d75a8c3ce6 (diff) | |
| download | coinos-server-23a9c10cc6ad2974ab73747606cdbe6015d861b9.tar.gz coinos-server-23a9c10cc6ad2974ab73747606cdbe6015d861b9.zip | |
fix captcha url, banhammer
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/users.js | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/routes/users.js b/routes/users.js index 739143e5..e412173e 100644 --- a/routes/users.js +++ b/routes/users.js @@ -91,18 +91,37 @@ app.post("/register", async (req, res) => { user.address = await bc.getNewAddress("", "bech32"); user.confidential = await lq.getNewAddress(); user.liquid = (await lq.getAddressInfo(user.confidential)).unconfidential; - user.name = user.username; let ip = req.headers["x-forwarded-for"] || req.connection.remoteAddress; try { - let captcha = await axios.post( - `https://www.google.com/recaptcha/api/siteverify/`, { + const url = `https://www.google.com/recaptcha/api/siteverify?secret=${config.captcha}&response=${user.token}&remoteip=${ip}`; + let captcha = await axios.post(url, { secret: config.captcha, response: user.token, - ip - } + remoteip: ip + }, + { timeout: 1000 } ); - l.info(captcha); + + let { success, score } = captcha.data; + + if (!success || score < 0.3) { + l.warn("failed registration attempt", ip); + + if (ip !== "192.168.1.5") { + const spawn = require("child_process").spawn; + proc = spawn("iptables", [ + "-I", + "INPUT", + "-s", + ip, + "-j", + "DROP" + ]); + } + + return res.status(500).send("Failed captcha"); + } } catch(e) { l.error(e.message); } |
