Skip to content

fix(api-service): Intercom hash null data error fixes NV-7061#9847

Merged
scopsy merged 3 commits intonextfrom
cursor/NV-7061-intercom-hash-null-data-847d
Jan 19, 2026
Merged

fix(api-service): Intercom hash null data error fixes NV-7061#9847
scopsy merged 3 commits intonextfrom
cursor/NV-7061-intercom-hash-null-data-847d

Conversation

@scopsy
Copy link
Contributor

@scopsy scopsy commented Jan 18, 2026

What changed? Why was the change needed?

This PR resolves NV-7061, a TypeError occurring in Hmac.update when the createHash function received null or undefined inputs, primarily affecting Intercom hash generation.

The createHash and createContextHash functions in libs/application-generic/src/utils/hmac.ts were updated to:

  1. Validate inputs and log a warning if key or valueToHash are null/undefined.
  2. Return null instead of throwing a TypeError in such cases.

Corresponding callers of createHash were updated to handle the null return value gracefully:

  • Intercom Hash Generation (Login, Register, GetProfile usecases): The Intercom hash update is now skipped if createHash returns null.
  • OAuth State Signature Generation (MS Teams, Slack): A BadRequestException is thrown if createHash fails to generate a signature, preventing malformed state tokens.
  • Conditions Filter: Falls back to an empty string if createHash returns null.

Screenshots

N/A

Expand for optional sections

Related enterprise PR

N/A

Special notes for your reviewer

The changes ensure that the application handles invalid hash inputs gracefully without crashing, improving robustness.


Linear Issue: NV-7061

Open in Cursor Open in Web

- Add null/undefined validation to createHash function in hmac.ts
- Update createContextHash to return string | null
- Add null checks in Intercom hash assignment in login, register, and get-profile
- Add validation in OAuth state generation for Slack and MS Teams
- Handle null gracefully in conditions-filter buildHmac

Fixes NV-7061 - TypeError when data argument is null in Hmac.update

Co-authored-by: dima <dima@novu.co>
@cursor
Copy link
Contributor

cursor bot commented Jan 18, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@linear
Copy link

linear bot commented Jan 18, 2026

@netlify
Copy link

netlify bot commented Jan 18, 2026

Deploy Preview for dashboard-v2-novu-staging canceled.

Name Link
🔨 Latest commit 9abc2ac
🔍 Latest deploy log https://app.netlify.com/projects/dashboard-v2-novu-staging/deploys/696cafd47e280000083198d1

Co-authored-by: dima <dima@novu.co>
@scopsy scopsy changed the title Intercom hash null data fix(api-service): Intercom hash null data error fixes NV-7061 Jan 18, 2026
@scopsy scopsy marked this pull request as ready for review January 18, 2026 09:53
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 18, 2026

Walkthrough

Changes add defensive checks and nullability across authentication, integration, and webhook code paths. HMAC utilities and related methods now return string | null with input validation and early returns. Intercom hash persistence in login, registration, and profile flows is guarded to run only when a truthy hash exists. OAuth state creation for Slack and MS Teams now throws a BadRequestException if the computed signature is falsy. Webhook request headers include the HMAC header only when a valid HMAC is produced. .cspell.json now includes the word "tufjs".

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title directly addresses the main objective: fixing Intercom hash null data errors by validating inputs in hash generation functions and handling null returns gracefully.
Description check ✅ Passed The description comprehensively explains the problem (TypeError from invalid hash inputs), the solution (input validation and null returns), and how different callers handle the changes, all directly related to the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In
`@libs/application-generic/src/usecases/conditions-filter/conditions-filter.usecase.ts`:
- Line 281: The current return uses
createHash(decryptApiKey(environment.apiKeys[0].key), command.environmentId) ||
'' which silently converts a null HMAC into an empty string; update the logic in
the function containing this return (where decryptApiKey, environment.apiKeys,
and createHash are used) to avoid the || '' fallback: if createHash returns null
or if decryptApiKey or command.environmentId are falsy, either throw a
descriptive error (e.g., "Unable to generate nv-hmac-256: missing api key or
environmentId") or return a value that signals omission of the header upstream
so you do not send an empty nv-hmac-256; ensure the change is applied where the
header is set so callers can handle the absent signature.

- Update buildHmac to return string | null instead of using || '' fallback
- Validate apiKey and environmentId before calling createHash
- Update getWebhookResponse to only include nv-hmac-256 header when hmac is valid
- Return null in test environment for consistency

Co-authored-by: dima <dima@novu.co>
@scopsy scopsy merged commit 7c410d6 into next Jan 19, 2026
32 checks passed
@scopsy scopsy deleted the cursor/NV-7061-intercom-hash-null-data-847d branch January 19, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants