Skip to content

[Smart Hashing] Add eslint rule to limit usage of createHash from crypto module #2861

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ module.exports = {
rules: {
'@typescript-eslint/no-unsafe-call': 'off'
}
},
{
files: ['packages/destination-actions/**/*.ts'],
rules: {
'no-restricted-syntax': [
'error',
{
selector: "ImportDeclaration[source.value='crypto'] ImportSpecifier[imported.name='createHash']",
message:
'The "destination-actions/lib/hashing-utils/processHashing" can autodetect prehashed values and avoid double hashing [https://github.com/segmentio/action-destinations/blob/139f434ff2828ed37c8f364f6ff9bb63dd3725d1/README.md?plain=1#L963]. Avoid importing the "createHash" function from "crypto"'
}
]
}
}
]
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line no-restricted-syntax
import { createHash } from 'crypto'
import { IntegrationError, RetryableError } from '@segment/actions-core'
import type { RequestClient } from '@segment/actions-core'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Settings } from './generated-types'
import type { RequestClient } from '@segment/actions-core'
import { DynamicFieldResponse } from '@segment/actions-core'
// eslint-disable-next-line no-restricted-syntax
import { randomBytes, createHash } from 'crypto'

export const API_HOST = 'https://api.emarsys.net'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line no-restricted-syntax
import { createHash } from 'crypto'
import { IntegrationError } from '@segment/actions-core'
import { InputField } from '@segment/actions-core'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line no-restricted-syntax
import { createHash } from 'crypto'
import {
ConversionCustomVariable,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line no-restricted-syntax
import { createHash } from 'crypto'

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line no-restricted-syntax
import { createHash } from 'crypto'

export function hashAndEncode(value: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { PayloadValidationError, RequestClient } from '@segment/actions-core'
import { Payload } from '../syncAudience/generated-types'
import { UpdateAudienceReq, Columns } from '../types'
import { EMAIL_SCHEMA_NAME, MAID_SCHEMA_NAME } from '../const'
// eslint-disable-next-line no-restricted-syntax
import { createHash } from 'crypto'

export async function send(request: RequestClient, payloads: Payload[]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Settings } from './generated-types'
import { SingleStoreCreateJSON } from './types'
import { createUrl } from './const'
import send from './send'
// eslint-disable-next-line no-restricted-syntax
import { createHash } from 'crypto'
import { encryptText, destinationId, checkChamber } from './util'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as crypto from 'crypto'
import { CLIENT_ID, STAGE_BROKERS, PROD_BROKERS } from './const'
import { IntegrationError } from '@segment/actions-core'
import { Settings } from './generated-types'
// eslint-disable-next-line no-restricted-syntax
import { createHash } from 'crypto'
import { KafkaConfig, ProducerRecord } from 'kafkajs'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Features, IntegrationError } from '@segment/actions-core'
// eslint-disable-next-line no-restricted-syntax
import { createHash } from 'crypto'
import { processHashing } from '../../../lib/hashing-utils'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { APIError, createRequestClient, DynamicFieldResponse } from '@segment/actions-core'
// eslint-disable-next-line no-restricted-syntax
import { createHash } from 'crypto'

interface Advertiser {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import nock from 'nock'
import { createTestEvent, createTestIntegration, IntegrationError } from '@segment/actions-core'
import Destination from '../../index'
// eslint-disable-next-line no-restricted-syntax
import { createHash } from 'crypto'

const testDestination = createTestIntegration(Destination)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line no-restricted-syntax
import { createHash } from 'crypto'
import type { ModifiedResponse } from '@segment/actions-core'
import { RequestClient, IntegrationError } from '@segment/actions-core'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { RequestClient, ModifiedResponse, PayloadValidationError } from '@segment/actions-core'
import { Settings } from './generated-types'
import { Payload } from './syncAudience/generated-types'
// eslint-disable-next-line no-restricted-syntax
import { createHash } from 'crypto'
import { IntegrationError } from '@segment/actions-core'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line no-restricted-syntax
import { createHash } from 'crypto'

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line no-restricted-syntax
import { createHash } from 'crypto'

/**
Expand Down
Loading