|
|
@@ -72,7 +72,7 @@ module.exports = { register: app => {
|
|
|
const privId = mCrypto.string(content);
|
|
|
|
|
|
if (req.body['g-recaptcha-response']) {
|
|
|
- const captchaOk = await Security.captchaCheck(req.body['g-recaptcha-response'], req.headers['x-forwarded-for'] || req.socket.remoteAddress);
|
|
|
+ const captchaOk = await Security.captchaCheck(req.body['g-recaptcha-response'], Security.getRequestIp(req));
|
|
|
if (!captchaOk)
|
|
|
return app.routerUtils.jsonResponse(res, { err: "Invalid captcha input", id: null });
|
|
|
} else if (req.body['apiKey']) {
|
|
|
@@ -89,7 +89,7 @@ module.exports = { register: app => {
|
|
|
entity.renew();
|
|
|
await app.databaseHelper.update({privId: privId}, entity);
|
|
|
} else {
|
|
|
- entity = entity || new PasteContent(privId, "paste");
|
|
|
+ entity = entity || new PasteContent(privId, "paste", Security.getRequestIp(req));
|
|
|
entity.expired = false;
|
|
|
entity.apiKey = req.body['apiKey'] || null;
|
|
|
entity.renew();
|
|
|
@@ -111,13 +111,13 @@ module.exports = { register: app => {
|
|
|
app.router.post("/short", async (req, res) => {
|
|
|
const link = "" + req.body.content;
|
|
|
const privId = mCrypto.string(await app.databaseHelper.count(PasteContent) + link);
|
|
|
- const captchaOk = await Security.captchaCheck(req.body['g-recaptcha-response'], req.headers['x-forwarded-for'] || req.socket.remoteAddress);
|
|
|
+ const captchaOk = await Security.captchaCheck(req.body['g-recaptcha-response'], Security.getRequestIp(req));
|
|
|
|
|
|
if (!captchaOk)
|
|
|
return app.routerUtils.jsonResponse(res, { err: "Invalid captcha input", id: null });
|
|
|
if (!link || !link.length)
|
|
|
return app.routerUtils.jsonResponse(res, { err: "Empty input", id: null });
|
|
|
- entity = new PasteContent(privId, "short");
|
|
|
+ entity = new PasteContent(privId, "short", Security.getRequestIp(req));
|
|
|
entity.data = link;
|
|
|
await app.databaseHelper.insertOne(entity);
|
|
|
app.routerUtils.jsonResponse(res, { err: null, id: entity.privId });
|
|
|
@@ -138,7 +138,7 @@ module.exports = { register: app => {
|
|
|
return app.routerUtils.jsonResponse(res, { err: "Invalid captcha input", id: null });
|
|
|
if (!formData.content?.fileData || !formData.content.fileData.length)
|
|
|
return app.routerUtils.jsonResponse(res, { err: "Empty input", id: null });
|
|
|
- const entity = new PasteContent(privId, "file");
|
|
|
+ const entity = new PasteContent(privId, "file", Security.getRequestIp(req));
|
|
|
entity.data = JSON.stringify({ name: formData.content.fileName, type: formData.content.fileType });
|
|
|
fs.writeFileSync(app.getData(privId), formData.content.fileData, {encoding: formData.content.fileType.indexOf('text') >= 0 ? 'utf8' : 'binary'});
|
|
|
await app.databaseHelper.insertOne(entity);
|
|
|
@@ -153,7 +153,7 @@ module.exports = { register: app => {
|
|
|
});
|
|
|
app.router.post("/api", async (req, res) => {
|
|
|
const ipAddress = req.headers['x-forwarded-for'] || req.socket.remoteAddress;
|
|
|
- const captchaOk = await Security.captchaCheck(req.body['g-recaptcha-response'], ipAddress);
|
|
|
+ const captchaOk = await Security.captchaCheck(req.body['g-recaptcha-response'], Security.getRequestIp(req));
|
|
|
|
|
|
if (!captchaOk)
|
|
|
return app.routerUtils.jsonResponse(res, { err: "Invalid captcha input", id: null });
|