Skip to content

Commit

Permalink
refactor: rename to blocklist/allowlist
Browse files Browse the repository at this point in the history
  • Loading branch information
AndersDJohnson committed Sep 22, 2022
1 parent d485920 commit 1738c45
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 31 deletions.
6 changes: 3 additions & 3 deletions __tests__/errors-cache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ 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()

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()
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -107,7 +107,7 @@ app.prepare().then(() => {
}),
errorMiddleware,
resolvePackageMiddleware,
blockBlacklistMiddleware,
blockBlocklistMiddleware,
cachedResponseMiddleware,
buildMiddleware
)
Expand All @@ -116,7 +116,7 @@ app.prepare().then(() => {
'/api/exports',
errorMiddleware,
resolvePackageMiddleware,
blockBlacklistMiddleware,
blockBlocklistMiddleware,
exportsMiddlware
)

Expand All @@ -132,7 +132,7 @@ app.prepare().then(() => {
}),
errorMiddleware,
resolvePackageMiddleware,
blockBlacklistMiddleware,
blockBlocklistMiddleware,
cachedResponseMiddleware,
exportsSizesMiddlware
)
Expand Down
4 changes: 2 additions & 2 deletions pages/scan/Scan.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -147,7 +147,7 @@ export default class Scan extends Component {
<input
type="checkbox"
defaultChecked={
!scanBlacklist.some(regex => regex.test(name))
!scanBlocklist.some(regex => regex.test(name))
}
value={`${name}#${resolvedVersion}`}
onChange={this.handleSelectionChange}
Expand Down
2 changes: 1 addition & 1 deletion server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {

DEFAULT_DEV_PORT: 5000,

blackList: [
blockList: [
/hack-cheats/,
/hacks?-cheats?/,
/hack-unlimited/,
Expand Down
12 changes: 6 additions & 6 deletions server/middlewares/rateLimit.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 =
Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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
Expand All @@ -31,4 +31,4 @@ async function blockBlacklistMiddleware(ctx, next) {
await next()
}

module.exports = blockBlacklistMiddleware
module.exports = blockBlocklistMiddleware
6 changes: 3 additions & 3 deletions server/middlewares/results/error.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
})
Expand Down
2 changes: 1 addition & 1 deletion server/middlewares/similar-packages/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
},
Expand Down
1 change: 0 additions & 1 deletion test-packages/blacklist-error/index.js

This file was deleted.

1 change: 1 addition & 0 deletions test-packages/blocklist-error/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("I'm not a blocklisted package, hence will throw")
File renamed without changes.
8 changes: 4 additions & 4 deletions utils/rebuild.utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { blackList } = require('../server/config')
const { blockList } = require('../server/config')

require('dotenv-defaults').config()
const firebase = require('firebase')
Expand Down Expand Up @@ -82,8 +82,8 @@ async function getPackageResult({ name, version }) {
return snapshot.val()
}

function filterBlacklistedPackages() {
blackList
function filterBlocklistedPackages() {
blockList
}

async function trim(packages) {
Expand Down Expand Up @@ -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
// }
//
Expand Down

0 comments on commit 1738c45

Please sign in to comment.