-
Notifications
You must be signed in to change notification settings - Fork 312
SECOPS-25213 [Salesforce Marketing Cloud]: reject subdomain host/path injection #3915
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
Open
harsh-joshi99
wants to merge
10
commits into
main
Choose a base branch
from
STRATCONN-sfmc-subdomain-injection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+96
−0
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5fb80d6
SECOPS-25213 [Salesforce Marketing Cloud]: reject subdomain host/path…
harsh-joshi99 cbdc690
[Salesforce Marketing Cloud] Fix inaccurate threat-model comment in s…
harsh-joshi99 771ad1a
[Salesforce Marketing Cloud] Clarify subdomain-validation comment mat…
harsh-joshi99 9d23b9d
Merge branch 'main' into STRATCONN-sfmc-subdomain-injection
harsh-joshi99 3e571bc
[Salesforce Marketing Cloud] Add refresh-token subdomain-injection test
harsh-joshi99 a011b7b
[Salesforce Marketing Cloud] Validate subdomain at settings-save via …
harsh-joshi99 b9d7f71
Merge branch 'main' into STRATCONN-sfmc-subdomain-injection
harsh-joshi99 e3408db
Merge branch 'main' into STRATCONN-sfmc-subdomain-injection
harsh-joshi99 3ca906a
[Salesforce Marketing Cloud] Validate subdomain only at settings-save
harsh-joshi99 581962a
Merge branch 'main' into STRATCONN-sfmc-subdomain-injection
joe-ayoub-segment File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
...n-actions/src/destinations/salesforce-marketing-cloud/_tests_/subdomainValidation.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import { createTestIntegration, PayloadValidationError } from '@segment/actions-core' | ||
| import Definition from '../index' | ||
| import { Settings } from '../generated-types' | ||
| import { validateSubdomain } from '../sfmc-operations' | ||
|
|
||
| const testDestination = createTestIntegration(Definition) | ||
|
|
||
| const baseSettings: Settings = { | ||
| subdomain: 'test123', | ||
| client_id: 'test123', | ||
| client_secret: 'test123', | ||
| account_id: 'test123' | ||
| } | ||
|
|
||
| // Subdomain values that an attacker could use to redirect requests to a host they | ||
| // control, thereby exfiltrating the OAuth client secret / bearer token. See SECOPS-25213. | ||
| const MALICIOUS_SUBDOMAINS = [ | ||
| 'mc123.attacker.com/', // trailing slash makes the effective host mc123.attacker.com (attacker-controlled); the SFMC suffix becomes part of the path | ||
| 'attacker.com/', // resolves to https://attacker.com/.rest.marketingcloudapis.com/... | ||
| 'mc123.attacker.com', // dot lets the attacker prepend their own host | ||
| 'mc123@attacker.com', // userinfo trick - real host becomes attacker.com | ||
| 'mc123.attacker.com#', // fragment injection | ||
| 'mc123.attacker.com?', // query injection | ||
| 'mc123:8080', // port injection | ||
| 'mc 123', // whitespace | ||
| 'mc123/../../evil', // path traversal | ||
| '' | ||
| ] | ||
|
|
||
| describe('Salesforce Marketing Cloud - subdomain validation', () => { | ||
| describe('validateSubdomain()', () => { | ||
| it('accepts a valid tenant subdomain', () => { | ||
| expect(validateSubdomain('mc563885gzs27c5t9-63k636ttgm')).toBe('mc563885gzs27c5t9-63k636ttgm') | ||
| expect(validateSubdomain('test123')).toBe('test123') | ||
| }) | ||
|
|
||
| it.each(MALICIOUS_SUBDOMAINS)('rejects malicious subdomain %p', (subdomain) => { | ||
| expect(() => validateSubdomain(subdomain)).toThrow(PayloadValidationError) | ||
| }) | ||
|
|
||
| it('rejects non-string values', () => { | ||
| expect(() => validateSubdomain(undefined)).toThrow(PayloadValidationError) | ||
| expect(() => validateSubdomain(null)).toThrow(PayloadValidationError) | ||
| }) | ||
| }) | ||
|
|
||
| // The subdomain is validated only at settings-save time (testAuthentication), so an | ||
| // invalid or injection value is rejected before it can ever be stored - the customer | ||
| // gets a clear, immediate error. We intentionally do NOT re-validate on every event | ||
| // to avoid breaking delivery for any pre-existing config. See SECOPS-25213. | ||
| describe('testAuthentication', () => { | ||
| it('accepts a valid subdomain', async () => { | ||
| await expect(testDestination.testAuthentication(baseSettings)).resolves.not.toThrow() | ||
| }) | ||
|
|
||
| // The core wrapper re-throws as a generic Error but preserves the message, so the | ||
| // customer sees the subdomain problem immediately at save time. | ||
| it.each(MALICIOUS_SUBDOMAINS)('rejects malicious subdomain %p at settings-save time', async (subdomain) => { | ||
| const settings: Settings = { ...baseSettings, subdomain } | ||
| await expect(testDestination.testAuthentication(settings)).rejects.toThrow( | ||
| 'Invalid Salesforce Marketing Cloud subdomain' | ||
| ) | ||
| }) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.