~cadence/bibliogram

d4f9af44b04d1e1ebb0a83414c6b0dff6cd9f7a5 — Cadence Ember a month ago f0a28d4
Notify users if they were blocked due to proxy
3 files changed, 21 insertions(+), 2 deletions(-)

M src/lib/quota/index.js
M src/site/api/routes.js
M src/site/pug/quota_reached.pug
M src/lib/quota/index.js => src/lib/quota/index.js +9 -0
@@ 38,5 38,14 @@ function add(req, count) {
	return limiter.add(identifier, count)
}

function isProxyNetwork(req) {
	if (!constants.quota.enabled) return false // no need to try to perform detection if we didn't even load the lists

	const ip = getIPFromReq(req)
	const identifier = getIdentifier(ip)
	return identifier === "proxy"
}

module.exports.remaining = remaining
module.exports.add = add
module.exports.isProxyNetwork = isProxyNetwork

M src/site/api/routes.js => src/site/api/routes.js +4 -2
@@ 159,7 159,8 @@ module.exports = [
				} else if (error === constants.symbols.extractor_results.AGE_RESTRICTED) {
					return render(403, "pug/age_gated.pug", {settings})
				} else if (error === constants.symbols.QUOTA_REACHED) {
					return render(429, "pug/quota_reached.pug")
					const isProxyNetwork = quota.isProxyNetwork(req)
					return render(429, "pug/quota_reached.pug", {isProxyNetwork})
				} else {
					throw error
				}


@@ 302,7 303,8 @@ module.exports = [
				} else if (error === constants.symbols.RATE_LIMITED) {
					return render(503, "pug/blocked_graphql.pug")
				} else if (error === constants.symbols.QUOTA_REACHED) {
					return render(429, "pug/quota_reached.pug")
					const isProxyNetwork = quota.isProxyNetwork(req)
					return render(429, "pug/quota_reached.pug", {isProxyNetwork})
				} else {
					throw error
				}

M src/site/pug/quota_reached.pug => src/site/pug/quota_reached.pug +8 -0
@@ 1,3 1,5 @@
//- Needs isProxyNetwork

include includes/error.pug

doctype html


@@ 10,5 12,11 @@ html
			| Each person has a limited number of requests to Bibliogram.
			| You have reached that limit. You cannot load any more data on this instance.
			| Your quota will reset automatically after some time has passed.
			if isProxyNetwork
				|
				|
				| However, this website has detected that you are using a proxy network, like Tor or a VPN.
				| To prevent bot abuse, all users on proxy networks share the same request quota.
			|
			|
			|