From 7a31e881c68a9f24d3341100076a89d41a3ca0e0 Mon Sep 17 00:00:00 2001 From: "Anders D. Johnson" Date: Wed, 21 Sep 2022 19:51:44 -0500 Subject: [PATCH] refactor: rename to blocklist/allowlist --- __tests__/errors-cache.test.js | 6 +++--- client/config/{scanBlacklist.js => scanBlocklist.js} | 0 index.js | 8 ++++---- pages/scan/Scan.js | 4 ++-- server/config.js | 2 +- server/middlewares/rateLimit.middleware.js | 12 ++++++------ ...st.middleware.js => blockBlocklist.middleware.js} | 12 ++++++------ server/middlewares/results/error.middleware.js | 6 +++--- server/middlewares/similar-packages/fixtures.js | 2 +- test-packages/blacklist-error/index.js | 1 - test-packages/blocklist-error/index.js | 1 + .../package.json | 0 utils/rebuild.utils.js | 8 ++++---- 13 files changed, 31 insertions(+), 31 deletions(-) rename client/config/{scanBlacklist.js => scanBlocklist.js} (100%) rename server/middlewares/results/{blockBlacklist.middleware.js => blockBlocklist.middleware.js} (67%) delete mode 100644 test-packages/blacklist-error/index.js create mode 100644 test-packages/blocklist-error/index.js rename test-packages/{blacklist-error => blocklist-error}/package.json (100%) diff --git a/__tests__/errors-cache.test.js b/__tests__/errors-cache.test.js index 3bd7260e..164bd5b3 100644 --- a/__tests__/errors-cache.test.js +++ b/__tests__/errors-cache.test.js @@ -48,7 +48,7 @@ describe('build api', () => { done() }) - it('gives right error messages on when trying to build blacklisted packages', async done => { + it('gives right error messages on when trying to build blocklisted packages', async done => { const resultURL = baseURL + 'polymer-cli' const result = await fetch(resultURL) const errorJSON = await result.json() @@ -56,9 +56,9 @@ describe('build api', () => { expect(result.status).toBe(403) expect(result.headers.get('cache-control')).toBe('max-age=60') - expect(errorJSON.error.code).toBe('BlacklistedPackageError') + expect(errorJSON.error.code).toBe('BlocklistedPackageError') expect(errorJSON.error.message).toBe( - 'The package you were looking for is blacklisted due to suspicious activity in the past' + 'The package you were looking for is blocklisted due to suspicious activity in the past' ) done() diff --git a/client/config/scanBlacklist.js b/client/config/scanBlocklist.js similarity index 100% rename from client/config/scanBlacklist.js rename to client/config/scanBlocklist.js diff --git a/index.js b/index.js index 38732dd2..dfc24fd1 100644 --- a/index.js +++ b/index.js @@ -26,7 +26,7 @@ const resolvePackageMiddleware = require('./server/middlewares/results/resolvePa const cachedResponseMiddleware = require('./server/middlewares/results/cachedResponse.middleware') const buildMiddleware = require('./server/middlewares/results/build.middleware') const errorMiddleware = require('./server/middlewares/results/error.middleware') -const blockBlacklistMiddleware = require('./server/middlewares/results/blockBlacklist.middleware') +const blockBlocklistMiddleware = require('./server/middlewares/results/blockBlocklist.middleware') const requestLoggerMiddleware = require('./server/middlewares/requestLogger.middleware') const similarPackagesMiddleware = require('./server/middlewares/similar-packages/similarPackages.middleware') const generateImgMiddleware = require('./server/middlewares/generateImg.middleware') @@ -107,7 +107,7 @@ app.prepare().then(() => { }), errorMiddleware, resolvePackageMiddleware, - blockBlacklistMiddleware, + blockBlocklistMiddleware, cachedResponseMiddleware, buildMiddleware ) @@ -116,7 +116,7 @@ app.prepare().then(() => { '/api/exports', errorMiddleware, resolvePackageMiddleware, - blockBlacklistMiddleware, + blockBlocklistMiddleware, exportsMiddlware ) @@ -132,7 +132,7 @@ app.prepare().then(() => { }), errorMiddleware, resolvePackageMiddleware, - blockBlacklistMiddleware, + blockBlocklistMiddleware, cachedResponseMiddleware, exportsSizesMiddlware ) diff --git a/pages/scan/Scan.js b/pages/scan/Scan.js index 112a6a4a..0c89c90e 100644 --- a/pages/scan/Scan.js +++ b/pages/scan/Scan.js @@ -3,7 +3,7 @@ import Analytics from '../../client/analytics' import ResultLayout from '../../client/components/ResultLayout' import Separator from '../../client/components/Separator' import MetaTags from '../../client/components/MetaTags' -import scanBlacklist from '../../client/config/scanBlacklist' +import scanBlocklist from '../../client/config/scanBlocklist' import Dropzone from 'react-dropzone' import Router from 'next/router' import * as semver from 'semver' @@ -145,7 +145,7 @@ export default class Scan extends Component { regex.test(name)) + !scanBlocklist.some(regex => regex.test(name)) } value={`${name}#${resolvedVersion}`} onChange={this.handleSelectionChange} diff --git a/server/config.js b/server/config.js index 191acac0..09d1ff5b 100644 --- a/server/config.js +++ b/server/config.js @@ -14,7 +14,7 @@ module.exports = { DEFAULT_DEV_PORT: 5000, - blackList: [ + blockList: [ /hack-cheats/, /hacks?-cheats?/, /hack-unlimited/, diff --git a/server/middlewares/rateLimit.middleware.js b/server/middlewares/rateLimit.middleware.js index b752b7a2..8521d5f2 100644 --- a/server/middlewares/rateLimit.middleware.js +++ b/server/middlewares/rateLimit.middleware.js @@ -4,8 +4,8 @@ const ipchecker = require('ipchecker') const defaults = { duration: 1000 * 60 * 60, - whiteList: [], - blackList: [], + allowList: [], + blockList: [], accessLimited: '429: Too Many Requests.', accessForbidden: '403: This is forbidden area for you.', max: 100, @@ -36,8 +36,8 @@ module.exports = function betterlimit(options = {}) { options.accessForbidden = options.message_403 } - const whiteListMap = ipchecker.map(options.whiteList) - const blackListMap = ipchecker.map(options.blackList) + const allowListMap = ipchecker.map(options.allowList) + const blockListMap = ipchecker.map(options.blockList) return function* ratelimit(next) { const ip = @@ -48,12 +48,12 @@ module.exports = function betterlimit(options = {}) { if (!ip) { return yield* next } - if (ipchecker.check(ip, blackListMap)) { + if (ipchecker.check(ip, blockListMap)) { this.response.status = 403 this.response.body = options.accessForbidden return } - if (ipchecker.check(ip, whiteListMap)) { + if (ipchecker.check(ip, allowListMap)) { return yield* next } diff --git a/server/middlewares/results/blockBlacklist.middleware.js b/server/middlewares/results/blockBlocklist.middleware.js similarity index 67% rename from server/middlewares/results/blockBlacklist.middleware.js rename to server/middlewares/results/blockBlocklist.middleware.js index addfa708..855be7d8 100644 --- a/server/middlewares/results/blockBlacklist.middleware.js +++ b/server/middlewares/results/blockBlocklist.middleware.js @@ -1,8 +1,8 @@ const { parsePackageString } = require('../../../utils/common.utils') -const CustomError = require('./../../CustomError') +const CustomError = require('../../CustomError') const CONFIG = require('../../config') -async function blockBlacklistMiddleware(ctx, next) { +async function blockBlocklistMiddleware(ctx, next) { const { package: packageString, force } = ctx.query if (force) { await next() @@ -11,9 +11,9 @@ async function blockBlacklistMiddleware(ctx, next) { const parsedPackage = parsePackageString(packageString) - // If package is blacklisted, fail fast - if (CONFIG.blackList.some(entry => entry.test(parsedPackage.name))) { - throw new CustomError('BlacklistedPackageError', { ...parsedPackage }) + // If package is blocklisted, fail fast + if (CONFIG.blockList.some(entry => entry.test(parsedPackage.name))) { + throw new CustomError('BlocklistedPackageError', { ...parsedPackage }) } // If package is unsupported, fail fast @@ -31,4 +31,4 @@ async function blockBlacklistMiddleware(ctx, next) { await next() } -module.exports = blockBlacklistMiddleware +module.exports = blockBlocklistMiddleware diff --git a/server/middlewares/results/error.middleware.js b/server/middlewares/results/error.middleware.js index 29318eea..04186c36 100644 --- a/server/middlewares/results/error.middleware.js +++ b/server/middlewares/results/error.middleware.js @@ -42,11 +42,11 @@ async function errorHandler(ctx, next) { } switch (err.name) { - case 'BlacklistedPackageError': + case 'BlocklistedPackageError': respondWithError(403, { - code: 'BlacklistedPackageError', + code: 'BlocklistedPackageError', message: - 'The package you were looking for is blacklisted ' + + 'The package you were looking for is blocklisted ' + "because it failed to build multiple times in the past and further tries aren't likely to succeed. This can " + "happen if this package wasn't meant to be bundled in a client side application.", }) diff --git a/server/middlewares/similar-packages/fixtures.js b/server/middlewares/similar-packages/fixtures.js index dced56af..acb94787 100644 --- a/server/middlewares/similar-packages/fixtures.js +++ b/server/middlewares/similar-packages/fixtures.js @@ -232,7 +232,7 @@ const categories = { { tag: 'escape', weight: Weight.MID }, { tag: 'filter', weight: Weight.NORMAL }, { tag: 'xss', weight: Weight.HIGH }, - { tag: 'whitelist', weight: Weight.SMALL }, + { tag: 'allowlist', weight: Weight.SMALL }, ], similar: ['sanitize-html', 'xss', 'dompurify', 'sanitizer'], }, diff --git a/test-packages/blacklist-error/index.js b/test-packages/blacklist-error/index.js deleted file mode 100644 index c499b260..00000000 --- a/test-packages/blacklist-error/index.js +++ /dev/null @@ -1 +0,0 @@ -console.log("I'm not a blacklisted package, hence will throw") diff --git a/test-packages/blocklist-error/index.js b/test-packages/blocklist-error/index.js new file mode 100644 index 00000000..4f153d4e --- /dev/null +++ b/test-packages/blocklist-error/index.js @@ -0,0 +1 @@ +console.log("I'm not a blocklisted package, hence will throw") diff --git a/test-packages/blacklist-error/package.json b/test-packages/blocklist-error/package.json similarity index 100% rename from test-packages/blacklist-error/package.json rename to test-packages/blocklist-error/package.json diff --git a/utils/rebuild.utils.js b/utils/rebuild.utils.js index d8ca3eb0..e47a0771 100644 --- a/utils/rebuild.utils.js +++ b/utils/rebuild.utils.js @@ -1,4 +1,4 @@ -const { blackList } = require('../server/config') +const { blockList } = require('../server/config') require('dotenv-defaults').config() const firebase = require('firebase') @@ -82,8 +82,8 @@ async function getPackageResult({ name, version }) { return snapshot.val() } -function filterBlacklistedPackages() { - blackList +function filterBlocklistedPackages() { + blockList } async function trim(packages) { @@ -122,7 +122,7 @@ async function run() { // Object.keys(packs[packName]).forEach(version => { // // if (packName !== 'react') return // // - // if (blackList.some(entry => entry.test(packName))) { + // if (blockList.some(entry => entry.test(packName))) { // return // } //