aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
Diffstat (limited to 'routes')
-rw-r--r--routes/users.js31
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);
}