Skip to content
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

✨ [RUM-4052] Sanitize site parameter in configuration #2735

Merged
merged 5 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ describe('validateAndBuildConfiguration', () => {
})
})

describe('site parameter validation', () => {
it('should validate the site parameter', () => {
validateAndBuildConfiguration({ clientToken, site: 'foo.com' })
expect(displaySpy).toHaveBeenCalledOnceWith('Site should be a valid Datadog site.')
})
})

describe('serializeConfiguration', () => {
it('should serialize the configuration', () => {
// By specifying the type here, we can ensure that serializeConfiguration is returning an
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/domain/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ export interface Configuration extends TransportConfiguration {
batchMessagesLimit: number
messageBytesLimit: number
}
function isDatadogSite(site: string) {
return /(datadog|ddog|datad0g|dd0g)/.test(site)
nulrich marked this conversation as resolved.
Show resolved Hide resolved
}

export function validateAndBuildConfiguration(initConfiguration: InitConfiguration): Configuration | undefined {
if (!initConfiguration || !initConfiguration.clientToken) {
Expand Down Expand Up @@ -148,6 +151,11 @@ export function validateAndBuildConfiguration(initConfiguration: InitConfigurati
return
}

if (initConfiguration.site && !isDatadogSite(initConfiguration.site)) {
display.error('Site should be a valid Datadog site.')
Copy link
Collaborator

Choose a reason for hiding this comment

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

💭 thought: ‏ Should we link the the valid datadog site documentation? (i.e. https://docs.datadoghq.com/getting_started/site/)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have included the documentation link.

return
}

// Set the experimental feature flags as early as possible, so we can use them in most places
if (Array.isArray(initConfiguration.enableExperimentalFeatures)) {
addExperimentalFeatures(
Expand Down