Skip to content

Commit

Permalink
Misc.: Remove problematic "blacklist"/"whitelist" language #43395 (#4…
Browse files Browse the repository at this point in the history
…3690)

* Misc.: Remove problematic "blacklist"/"whitelist" language #43395

* Tours: Rename selector for clarity
  • Loading branch information
sarayourfriend committed Jun 30, 2020
1 parent 6355b36 commit c685ff3
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 42 deletions.
2 changes: 1 addition & 1 deletion bin/validate-config-keys.js
Expand Up @@ -33,7 +33,7 @@ const environmentKeys = fs
.readdirSync( configRoot, { encoding: 'utf8' } )
.filter( ( filename ) => /\.json$/.test( path.basename( filename ) ) ) // only the JSON config files
.filter( ( filename ) => '_shared.json' !== filename ) // base config for all environments
.filter( ( filename ) => 'client.json' !== filename ) // whitelist of keys allowed in client
.filter( ( filename ) => 'client.json' !== filename ) // list of keys allowed in client
.filter( ( filename ) => ! /secrets/g.test( filename ) ) // secret tokens not part of this system
.map( ( filename ) => [ filename, Object.keys( parseConfig( filename ) ) ] );

Expand Down
Expand Up @@ -94,7 +94,7 @@ class AcceptedFilenames extends Component {
<Card>
<form>
<FormLabel>{ translate( 'Do not cache these page types.' ) }</FormLabel>

{ /* eslint-disable-next-line wpcalypso/jsx-classname-namespace */ }
<FormSettingExplanation className="wp-super-cache__condition-settings-explanation">
{ translate(
' See the {{a}}Conditional Tags{{/a}} ' +
Expand All @@ -117,10 +117,14 @@ class AcceptedFilenames extends Component {
{ this.renderToggle( 'single', translate( 'Single Posts (is_single)' ) ) }
{ this.renderToggle( 'pages', translate( 'Pages (is_page)' ) ) }
{ this.renderToggle( 'frontpage', translate( 'Front Page (is_front_page)' ) ) }

{ /* eslint-disable-next-line wpcalypso/jsx-classname-namespace */ }
<div className="wp-super-cache__nested-page-types">
{ this.renderToggle( 'home', translate( 'Home (is_home)' ), 'frontpage' ) }
</div>
{ this.renderToggle( 'archives', translate( 'Archives (is_archive)' ) ) }

{ /* eslint-disable-next-line wpcalypso/jsx-classname-namespace */ }
<div className="wp-super-cache__nested-page-types">
{ this.renderToggle( 'tag', translate( 'Tags (is_tag)' ), 'archives' ) }
{ this.renderToggle(
Expand Down Expand Up @@ -154,7 +158,7 @@ class AcceptedFilenames extends Component {
</FormFieldset>

<FormFieldset>
<FormLabel>{ translate( 'Whitelisted filenames:' ) }</FormLabel>
<FormLabel>{ translate( 'Allowed filenames:' ) }</FormLabel>
<FormTextarea
disabled={ isDisabled }
onChange={ handleChange( 'cache_acceptable_files' ) }
Expand Down
Expand Up @@ -126,6 +126,7 @@ const SiteTitle: React.FunctionComponent< Props > = ( { onSubmit } ) => {
autoComplete="off"
placeholder={ placeHolder }
autoCorrect="off"
// Unable to remove this instance due to it being a HotJar term: https://github.com/Automattic/wp-calypso/pull/43348#discussion_r442015229
data-hj-whitelist
></TextControl>
<p className="site-title__input-hint">
Expand Down
4 changes: 2 additions & 2 deletions client/lib/i18n-utils/empathy-mode.js
Expand Up @@ -41,7 +41,7 @@ export function initLanguageEmpathyMode() {
const i18nEmpathy = new I18N();
const i18nEmpathyTranslate = i18nEmpathy.translate.bind( i18nEmpathy );
const i18nEmpathyRegisterHook = i18nEmpathy.registerTranslateHook.bind( i18nEmpathy );
const translationsWhitelist = [ defaultUntranslatedPlacehoder ];
const availableEmpathyTranslations = [ defaultUntranslatedPlacehoder ];

i18n.translateHooks.forEach( i18nEmpathyRegisterHook );

Expand All @@ -51,7 +51,7 @@ export function initLanguageEmpathyMode() {
if (
! isActive ||
locale === i18n.defaultLocaleSlug ||
translationsWhitelist.includes( options.original )
availableEmpathyTranslations.includes( options.original )
) {
return translation;
}
Expand Down
6 changes: 3 additions & 3 deletions client/server/pages/index.js
Expand Up @@ -263,10 +263,10 @@ function getDefaultContext( request, entrypoint = 'entry-main' ) {
let initialServerState = {};
let lang = config( 'i18n_default_locale_slug' );
const bodyClasses = [];
// We don't compare context.query against a whitelist here. Whitelists are route-specific,
// We don't compare context.query against an allowed list here. Explicit allowance lists are route-specific,
// i.e. they can be created by route-specific middleware. `getDefaultContext` is always
// called before route-specific middleware, so it's up to the cache *writes* in server
// render to make sure that Redux state and markup are only cached for whitelisted query args.
// render to make sure that Redux state and markup are only cached for specified query args.
const cacheKey = getNormalizedPath( request.path, request.query );
const geoLocation = ( request.headers[ 'x-geoip-country-code' ] || '' ).toLowerCase();
const devEnvironments = [ 'development', 'jetpack-cloud-development' ];
Expand Down Expand Up @@ -976,7 +976,7 @@ export default function pages() {
} );
} );

// catchall to render 404 for all routes not whitelisted in client/sections
// catchall to render 404 for all routes not explicitly allowed in client/sections
app.use( render404() );

// Error handling middleware for displaying the server error 500 page must be the very last middleware defined
Expand Down
8 changes: 5 additions & 3 deletions client/server/sanitize/index.js
@@ -1,3 +1,5 @@
/* eslint-disable jsdoc/check-values */

/**
* Encode single characters with backslashes.
*
Expand Down Expand Up @@ -41,15 +43,15 @@ function jsSlashEncoder( charStr ) {
/**
* Create JSON serialized string suitable for inclusion in HTML
*
* @param {mixed} value The variable to be serialized
* @param {any} value The variable to be serialized
* @returns {string} JSON serialized string
**/
exports.jsonStringifyForHtml = function ( value ) {
const jsonInHtmlBlacklist = /[^\x22,\-\.0-9:A-Z\[\x5C\]_a-z{}]/g;
const jsonInHtmlFilter = /[^\x22,\-.0-9:A-Z[\x5C]_a-z{}]/g;
const cdataClose = /\]\](?:>|\\x3E|\\u003E)/gi;
return (
JSON.stringify( value )
.replace( jsonInHtmlBlacklist, jsSlashEncoder )
.replace( jsonInHtmlFilter, jsSlashEncoder )
// prevent breaking out of CDATA context. Escaping < below is sufficient
// to prevent opening a CDATA context.
.replace( cdataClose, '\\x5D\\x5D\\x3E' )
Expand Down
4 changes: 2 additions & 2 deletions client/state/happychat/test/middleware-calypso.js
Expand Up @@ -214,7 +214,7 @@ describe( 'middleware', () => {
expect( store.dispatch.mock.calls[ 1 ][ 0 ].payload.text ).toBe( 'def' );
} );

test( 'should only send a timeline event for whitelisted tracks events', () => {
test( 'should only send a timeline event for allowed tracks events', () => {
const analyticsMeta = [
{
type: ANALYTICS_EVENT_RECORD,
Expand Down Expand Up @@ -326,7 +326,7 @@ describe( 'middleware', () => {
sendActionLogsAndEvents( store, action );

// All 4 analytics records will be sent to the "firehose" log
// The two whitelisted analytics events and the SITE_SETTINGS_SAVE_SUCCESS itself
// The two allowed analytics events and the SITE_SETTINGS_SAVE_SUCCESS itself
// will be sent as customer events
expect( store.dispatch ).toHaveBeenCalledTimes( 7 );
expect( store.dispatch.mock.calls[ 0 ][ 0 ].type ).toBe( HAPPYCHAT_IO_SEND_MESSAGE_EVENT );
Expand Down
2 changes: 1 addition & 1 deletion client/state/logstash/actions.ts
Expand Up @@ -13,7 +13,7 @@ interface LogToLogstashParams {
/**
* Feature name.
*
* Should be whitelisted. @see D31385-code
* Should be explicitly allowed. @see D31385-code
*/
feature: 'calypso_ssr' | 'calypso_client';
message: string;
Expand Down
4 changes: 2 additions & 2 deletions client/state/nps-survey/selectors.js
Expand Up @@ -10,7 +10,7 @@ import { get } from 'lodash';
import { NOT_SUBMITTED, SUBMITTING, SUBMIT_FAILURE, SUBMITTED } from './constants';
import { getSectionName } from 'state/ui/selectors';

const SECTION_NAME_WHITELIST = [
const ALLOWED_SECTION_NAMES = [
'discover',
'menus',
'people',
Expand All @@ -33,7 +33,7 @@ export function isSessionEligibleForNpsSurvey( state ) {

export function isSectionEligibleForNpsSurvey( state ) {
const sectionName = getSectionName( state );
return SECTION_NAME_WHITELIST.indexOf( sectionName ) > -1;
return ALLOWED_SECTION_NAMES.indexOf( sectionName ) > -1;
}

export function isSectionAndSessionEligibleForNpsSurvey( state ) {
Expand Down
43 changes: 26 additions & 17 deletions client/state/plugins/premium/selectors.js
Expand Up @@ -24,35 +24,44 @@ export const hasRequested = function ( state, siteId ) {
return state.plugins.premium.hasRequested[ siteId ];
};

export const getPluginsForSite = function ( state, siteId, whitelist = false ) {
/**
* Gets the list of plugins for a site and optionally filters to a single specific
* plugin.
*
* @param {object} state The current state.
* @param {number} siteId The site ID.
* @param {string?} forPlugin Name of a specific plugin to filter for, `false` otherwise to return the full list.
* @returns {Array<object>} The list of plugins.
*/
export const getPluginsForSite = function ( state, siteId, forPlugin = false ) {
const pluginList = state.plugins.premium.plugins[ siteId ];
if ( typeof pluginList === 'undefined' ) {
return [];
}

// patch to solve a bug in jp 4.3 ( https://github.com/Automattic/jetpack/issues/5498 )
if ( whitelist === 'backups' || whitelist === 'scan' ) {
whitelist = 'vaultpress';
if ( forPlugin === 'backups' || forPlugin === 'scan' ) {
forPlugin = 'vaultpress';
}

return filter( pluginList, ( plugin ) => {
// eslint-disable-next-line no-extra-boolean-cast
if ( !! whitelist ) {
return whitelist === plugin.slug;
if ( !! forPlugin ) {
return forPlugin === plugin.slug;
}
return true;
} );
};

export const isStarted = function ( state, siteId, whitelist = false ) {
const pluginList = getPluginsForSite( state, siteId, whitelist );
export const isStarted = function ( state, siteId, forPlugin = false ) {
const pluginList = getPluginsForSite( state, siteId, forPlugin );
return ! every( pluginList, ( item ) => {
return 'wait' === item.status;
} );
};

export const isFinished = function ( state, siteId, whitelist = false ) {
const pluginList = getPluginsForSite( state, siteId, whitelist );
export const isFinished = function ( state, siteId, forPlugin = false ) {
const pluginList = getPluginsForSite( state, siteId, forPlugin );
if ( pluginList.length === 0 ) {
return true;
}
Expand All @@ -62,8 +71,8 @@ export const isFinished = function ( state, siteId, whitelist = false ) {
} );
};

export const isInstalling = function ( state, siteId, whitelist = false ) {
const pluginList = getPluginsForSite( state, siteId, whitelist );
export const isInstalling = function ( state, siteId, forPlugin = false ) {
const pluginList = getPluginsForSite( state, siteId, forPlugin );
if ( pluginList.length === 0 ) {
return false;
}
Expand All @@ -74,8 +83,8 @@ export const isInstalling = function ( state, siteId, whitelist = false ) {
} );
};

export const getActivePlugin = function ( state, siteId, whitelist = false ) {
const pluginList = getPluginsForSite( state, siteId, whitelist );
export const getActivePlugin = function ( state, siteId, forPlugin = false ) {
const pluginList = getPluginsForSite( state, siteId, forPlugin );
const plugin = find( pluginList, ( item ) => {
return ! includes( [ 'done', 'wait' ], item.status ) && item.error === null;
} );
Expand All @@ -85,8 +94,8 @@ export const getActivePlugin = function ( state, siteId, whitelist = false ) {
return plugin;
};

export const getNextPlugin = function ( state, siteId, whitelist = false ) {
const pluginList = getPluginsForSite( state, siteId, whitelist );
export const getNextPlugin = function ( state, siteId, forPlugin = false ) {
const pluginList = getPluginsForSite( state, siteId, forPlugin );
const plugin = find( pluginList, ( item ) => {
return 'wait' === item.status && item.error === null;
} );
Expand All @@ -97,8 +106,8 @@ export const getNextPlugin = function ( state, siteId, whitelist = false ) {
};

export const getPluginKeys = createSelector(
( state, siteId, whitelist = false ) => {
const pluginList = getPluginsForSite( state, siteId, whitelist );
( state, siteId, forPlugin = false ) => {
const pluginList = getPluginsForSite( state, siteId, forPlugin );

return pluginList.reduce( ( keys, plugin ) => {
const key = get( plugin, 'key' );
Expand Down
4 changes: 2 additions & 2 deletions client/state/plugins/premium/test/selectors.js
Expand Up @@ -91,11 +91,11 @@ describe( 'Premium Plugin Selectors', () => {
expect( isInstalling( state, 'installing.site' ) ).toBe( true );
} );

test( 'Should get `true` if there is a plugin installing on the requested site, using whitelist', () => {
test( 'Should get `true` if there is a plugin installing on the requested site, filtering for a specified plugin (akismet)', () => {
expect( isInstalling( state, 'installing.site', 'akismet' ) ).toBe( true );
} );

test( 'Should get `true` if there is a plugin configuring on the requested site, using whitelist', () => {
test( 'Should get `true` if there is a plugin configuring on the requested site, filtering for a specified plugin (akismet)', () => {
expect( isInstalling( state, 'config.site', 'akismet' ) ).toBe( true );
} );

Expand Down
6 changes: 3 additions & 3 deletions client/state/posts/actions/start-editing-post-copy.js
Expand Up @@ -35,22 +35,22 @@ export const startEditingPostCopy = ( siteId, postToCopyId ) => ( dispatch ) =>
postAttributes.featured_image = getFeaturedImageId( postToCopy );

/**
* A post metadata whitelist for the `updatePostMetadata()` action.
* A list of allowed post metadata for the `updatePostMetadata()` action.
*
* This is needed because blindly passing all post metadata to `editPost()`
* causes unforeseeable issues, such as Publicize not triggering on the copied post.
*
* @see https://github.com/Automattic/wp-calypso/issues/14840
*/
const metadataWhitelist = [ 'geo_latitude', 'geo_longitude', 'geo_address', 'geo_public' ];
const allowedMetadata = [ 'geo_latitude', 'geo_longitude', 'geo_address', 'geo_public' ];

// Filter the post metadata to include only the ones we want to copy,
// use only the `key` and `value` properties (and, most importantly exclude `id`),
// and add an `operation` field to the copied values.
const copiedMetadata = reduce(
postToCopy.metadata,
( copiedMeta, { key, value } ) => {
if ( includes( metadataWhitelist, key ) ) {
if ( includes( allowedMetadata, key ) ) {
copiedMeta.push( { key, value, operation: 'update' } );
}
return copiedMeta;
Expand Down
7 changes: 4 additions & 3 deletions client/state/ui/guided-tours/selectors/index.js
Expand Up @@ -31,7 +31,7 @@ import createSelector from 'lib/create-selector';
import findOngoingTour from './find-ongoing-tour';
import getToursHistory from './get-tours-history';

const BLACKLISTED_SECTIONS = [
const SECTIONS_WITHOUT_TOURS = [
'signup',
'upgrades', // checkout
'checkout-thank-you', // thank you page
Expand Down Expand Up @@ -149,7 +149,8 @@ const findTriggeredTour = ( state ) => {
} );
};

const isSectionBlacklisted = ( state ) => includes( BLACKLISTED_SECTIONS, getSectionName( state ) );
const doesSectionAllowTours = ( state ) =>
! includes( SECTIONS_WITHOUT_TOURS, getSectionName( state ) );

export const hasTourJustBeenVisible = createSelector(
( state, now = Date.now() ) => {
Expand All @@ -163,7 +164,7 @@ export const hasTourJustBeenVisible = createSelector(
[ getActionLog ]
);

const shouldBailAllTours = ( state ) => isSectionBlacklisted( state );
const shouldBailAllTours = ( state ) => ! doesSectionAllowTours( state );

const shouldBailNewTours = ( state ) => hasTourJustBeenVisible( state );

Expand Down
2 changes: 1 addition & 1 deletion packages/i18n-calypso-cli/test/i18n.js
Expand Up @@ -8,7 +8,7 @@ const path = require( 'path' );
*/
const i18n = require( '..' );

// generate whitelist file
// generate allowed file
const sourceFiles = [
'examples/i18n-test-examples.jsx',
'examples/i18n-test-example-second-file.jsx',
Expand Down

0 comments on commit c685ff3

Please sign in to comment.