Bugfix for repeated getting new bypass when tor user didnt need one. not necessarily a big problem but it means they would keep getting new ids. this could actually be leveraged for a scuffed auto-refresh system in future

merge-requests/208/head
Thomas Lynch 4 years ago
parent b0797f0418
commit 786f5a2ffa
  1. 6
      configs/main.js.example
  2. 6
      controllers/forms.js
  3. 2
      gulp/res/css/style.css
  4. BIN
      gulp/res/img/robot.gif
  5. 2
      helpers/checks/blockbypass.js
  6. 8
      helpers/checks/torprebypass.js
  7. 3
      helpers/filemiddlewares.js
  8. 12
      helpers/processip.js

@ -19,7 +19,7 @@ module.exports = {
ipHashSecret: 'long random string', ipHashSecret: 'long random string',
postPasswordSecret: 'long random string', postPasswordSecret: 'long random string',
//enable secure cookies, only use with https //enable secure cookies, only use with https/not tor
secureCookies: true, secureCookies: true,
//check referrer to prevent some CSRF attack //check referrer to prevent some CSRF attack
@ -31,7 +31,7 @@ module.exports = {
//header for country codes, for cloudflare, use 'Cf-Ipcountry' //header for country codes, for cloudflare, use 'Cf-Ipcountry'
countryCodeHeader: 'x-country-code', countryCodeHeader: 'x-country-code',
//header for visitor IP, for cloudflare use 'CF-Connecting-IP' //header for visitor IP, for cloudflare use 'CF-Connecting-IP'
ipHeader: 'X-Real-IP', ipHeader: 'x-real-ip',
//data used in opengraph meta tags. used to generate link previews in e.g. discord, twitter, etc //data used in opengraph meta tags. used to generate link previews in e.g. discord, twitter, etc
meta: { meta: {
@ -108,7 +108,7 @@ module.exports = {
thumbExtension: '.jpg', thumbExtension: '.jpg',
//max thumb dimensions (square) in px. images smaller than this are not thumbnailed //max thumb dimensions (square) in px. images smaller than this are not thumbnailed
thumbSize: 220, thumbSize: 250,
/* extra mime types for files to be uploaded as attachments (no thumbnails) e.g. text files/archives /* extra mime types for files to be uploaded as attachments (no thumbnails) e.g. text files/archives
NOTE: appropriate extensions will need to be added to nginx configuration, and uncommend the provided NOTE: appropriate extensions will need to be added to nginx configuration, and uncommend the provided

@ -79,12 +79,12 @@ router.post('/global/editaccounts', useSession, sessionRefresh, csrf, calcPerms,
router.post('/global/settings', useSession, sessionRefresh, csrf, calcPerms, isLoggedIn, hasPerms(0), paramConverter, globalSettingsController); //global settings router.post('/global/settings', useSession, sessionRefresh, csrf, calcPerms, isLoggedIn, hasPerms(0), paramConverter, globalSettingsController); //global settings
//create board //create board
router.post('/create', /*geoAndTor, torPreBypassCheck, processIp,*/ useSession, sessionRefresh, isLoggedIn, verifyCaptcha, calcPerms, hasPerms(4), createBoardController); router.post('/create', geoAndTor, torPreBypassCheck, processIp, useSession, sessionRefresh, isLoggedIn, verifyCaptcha, calcPerms, hasPerms(4), createBoardController);
//accounts //accounts
router.post('/login', useSession, loginController); router.post('/login', useSession, loginController);
router.post('/logout', useSession, logout); router.post('/logout', useSession, logout);
router.post('/register', /*geoAndTor, torPreBypassCheck, processIp,*/ useSession, sessionRefresh, verifyCaptcha, calcPerms, registerController); router.post('/register', geoAndTor, torPreBypassCheck, processIp, useSession, sessionRefresh, verifyCaptcha, calcPerms, registerController);
router.post('/changepassword', /*geoAndTor, torPreBypassCheck, processIp,*/ useSession, sessionRefresh, verifyCaptcha, changePasswordController); router.post('/changepassword', geoAndTor, torPreBypassCheck, processIp, useSession, sessionRefresh, verifyCaptcha, changePasswordController);
//removes captcha cookie, for refreshing for noscript users //removes captcha cookie, for refreshing for noscript users
router.post('/newcaptcha', newCaptcha); router.post('/newcaptcha', newCaptcha);

@ -2,7 +2,7 @@
--attachment-img: url('/file/attachment.png'); --attachment-img: url('/file/attachment.png');
--spoiler-img: url('/file/spoiler.png'); --spoiler-img: url('/file/spoiler.png');
--audio-img: url('/file/audio.png'); --audio-img: url('/file/audio.png');
--thumbnail-size: 220px; --thumbnail-size: 250px;
} }
body { body {

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

@ -9,7 +9,7 @@ const { Bypass } = require(__dirname+'/../../db/')
module.exports = async (req, res, next) => { module.exports = async (req, res, next) => {
if (!blockBypass.enabled && !res.locals.tor) { //for now, tor MUST solve a bypass if (res.locals.preFetchedBypassId || !blockBypass.enabled && !res.locals.tor) { //for now, tor MUST solve a bypass
return next(); return next();
} }

@ -10,7 +10,6 @@ const { Bypass, Captchas } = require(__dirname+'/../../db/')
module.exports = async (req, res, next) => { module.exports = async (req, res, next) => {
console.log('TOR PRE BYPASS')
//early byapss is only needed for tor users //early byapss is only needed for tor users
if (!res.locals.tor) { if (!res.locals.tor) {
return next(); return next();
@ -26,7 +25,8 @@ console.log('TOR PRE BYPASS')
}); });
} }
const captchaId = req.cookies.captchaid; const captchaId = req.cookies.captchaid;
if (input) { let bypassId = req.signedCookies.bypassid;
if (input && !bypassId) {
// try to get the captcha from the DB // try to get the captcha from the DB
let captcha; let captcha;
try { try {
@ -52,6 +52,8 @@ console.log('TOR PRE BYPASS')
//they dont have a valid bypass, but just solved a captcha, so give them a new one //they dont have a valid bypass, but just solved a captcha, so give them a new one
const newBypass = await Bypass.getBypass(); const newBypass = await Bypass.getBypass();
const newBypassId = newBypass.insertedId; const newBypassId = newBypass.insertedId;
bypassId = newBypassId.toString();
res.locals.preFetchedBypassId = bypassId;
res.locals.blockBypass = newBypass.ops[0]; res.locals.blockBypass = newBypass.ops[0];
res.cookie('bypassid', newBypassId.toString(), { res.cookie('bypassid', newBypassId.toString(), {
'maxAge': blockBypass.expireAfterTime, 'maxAge': blockBypass.expireAfterTime,
@ -63,7 +65,6 @@ console.log('TOR PRE BYPASS')
} }
//check if blockbypass exists and right length //check if blockbypass exists and right length
const bypassId = req.signedCookies.bypassid;
if (!bypassId || bypassId.length !== 24) { if (!bypassId || bypassId.length !== 24) {
return dynamicResponse(req, res, 403, 'message', { return dynamicResponse(req, res, 403, 'message', {
'title': 'Forbidden', 'title': 'Forbidden',
@ -76,7 +77,6 @@ console.log('TOR PRE BYPASS')
}); });
} }
console.log('in tor pre bypass', bypassId)
return next(); return next();
} }

@ -46,8 +46,6 @@ module.exports = {
}), }),
handlePostFilesEarlyTor: (req, res, next) => { handlePostFilesEarlyTor: (req, res, next) => {
console.log('handlePostFilesEarlyTor')
console.log(res.locals.tor, postFiles)
if (res.locals.tor) { if (res.locals.tor) {
return postFiles(req, res, next); return postFiles(req, res, next);
} }
@ -55,7 +53,6 @@ console.log(res.locals.tor, postFiles)
}, },
handlePostFiles: (req, res, next) => { handlePostFiles: (req, res, next) => {
console.log('handlePostFiles')
if (res.locals.tor) { if (res.locals.tor) {
return next(); return next();
} }

@ -8,14 +8,14 @@ const { ipHeader, ipHashPermLevel } = require(__dirname+'/../configs/main.js')
module.exports = (req, res, next) => { module.exports = (req, res, next) => {
//tor user ip uses bypassid, if they dont have one send to blockbypass //tor user ip uses bypass id, if they dont have one send to blockbypass
if (res.locals.tor) { if (res.locals.tor) {
const bypassId = req.signedCookies.bypassid; const pseudoIp = res.locals.preFetchedBypassId || req.signedCookies.bypassid;
res.locals.ip = { res.locals.ip = {
raw: bypassId, raw: pseudoIp,
single: bypassId, single: pseudoIp,
qrange: bypassId, qrange: pseudoIp,
hrange: bypassId, hrange: pseudoIp,
}; };
return next(); return next();
} }

Loading…
Cancel
Save