Skip to content

Conversation

@alionazherdetska
Copy link
Contributor

@alionazherdetska alionazherdetska commented Apr 14, 2025

📄 Description

Addressed a potential injection vulnerability in the Internet Header's config.json request mechanism by validating and encoding the input parameters (projectId, environment, and version).

📝 Checklist

  • ✅ My code follows the style guidelines of this project
  • 🛠️ I have performed a self-review of my own code
  • 📄 I have made corresponding changes to the documentation
  • ⚠️ My changes generate no new warnings or errors
  • 🧪 I have added tests that prove my fix is effective or that my feature works
  • ✔️ New and existing unit tests pass locally with my changes

@alionazherdetska alionazherdetska requested a review from a team as a code owner April 14, 2025 19:58
@changeset-bot
Copy link

changeset-bot bot commented Apr 14, 2025

⚠️ No Changeset found

Latest commit: b918701

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@swisspost-bot
Copy link
Contributor

swisspost-bot commented Apr 14, 2025

Related Previews

@alionazherdetska alionazherdetska changed the title fix(component): sanitized and encoded config request parameters in post-internet-header to prevent malicious injection fix(component): sanitized and encoded config request parameters in post-internet-header to prevent injection Apr 15, 2025
Copy link
Member

@gfellerph gfellerph left a comment

Choose a reason for hiding this comment

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

Please add a test case where a "malicious" or invalid payload is trying to modify the URL of the config request where we can see that these changes are preventing the malicious request from being sent. I think it will be valuable in the future to understand the methods used to manipulate the config requests so we can react to them not only in the header, but in other places where we send requests based on properties on a web component.

@alionazherdetska alionazherdetska force-pushed the 4970-escape-query-string-params-before-calling-config branch from 6f15fce to 195eda6 Compare June 2, 2025 17:16
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 2, 2025

@alizedebray alizedebray self-requested a review July 3, 2025 06:58
@alionazherdetska alionazherdetska force-pushed the 4970-escape-query-string-params-before-calling-config branch from f6d651a to fc3cf7a Compare July 15, 2025 06:43
@alionazherdetska alionazherdetska changed the base branch from release/v8 to release/v9 July 15, 2025 06:52
@alionazherdetska alionazherdetska changed the base branch from release/v9 to release/v8 July 15, 2025 06:54
@alionazherdetska alionazherdetska changed the base branch from release/v8 to release/v9 July 15, 2025 06:55
@alionazherdetska alionazherdetska force-pushed the 4970-escape-query-string-params-before-calling-config branch from fc3cf7a to 9687493 Compare July 15, 2025 06:56
@alionazherdetska alionazherdetska force-pushed the 4970-escape-query-string-params-before-calling-config branch from 9687493 to caeba55 Compare July 15, 2025 06:58
@alionazherdetska alionazherdetska marked this pull request as draft July 15, 2025 08:42
@alionazherdetska alionazherdetska force-pushed the 4970-escape-query-string-params-before-calling-config branch 3 times, most recently from a18dfd5 to 2e889b5 Compare July 15, 2025 11:24
@alionazherdetska alionazherdetska marked this pull request as ready for review July 15, 2025 12:02
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
2 Security Hotspots

See analysis details on SonarQube Cloud

Comment on lines +211 to +215
if (!this.isValidEnvironment(this.environment)) {
throw new Error(
`Internet Header environment "${this.environment}" is not valid. Please use one of: ${PostInternetHeader.VALID_ENVIRONMENTS.join(', ')}`
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If you give a default value to the parameter of the handleEnvironmentChange function like so:

  handleEnvironmentChange(newValue = this.environment) {

You can completely reuse it in the componentWillLoad, intead of duplicating the error message:

Suggested change
if (!this.isValidEnvironment(this.environment)) {
throw new Error(
`Internet Header environment "${this.environment}" is not valid. Please use one of: ${PostInternetHeader.VALID_ENVIRONMENTS.join(', ')}`
);
}
this.handleEnvironmentChange();

It's usually how we do it in our components, here the example of the post-banner:
https://github.com/swisspost/design-system/blob/main/packages/components/src/components/post-banner/post-banner.tsx#L87

Copy link
Member

@gfellerph gfellerph left a comment

Choose a reason for hiding this comment

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

@alionazherdetska I think we need to quickly sync on this PR. Generally, it might be easier to validate the params just before sending the request and not in the whole lifecycle.

Copy link
Member

Choose a reason for hiding this comment

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

Solid suite of tests!

const renderLanguageSwitch = config.header.navLang.length > 1;

const initialLogoScale = renderMetaNavigation ? getLogoScale(this.host) : '1';
const safeVersion = this.isValidVersion(packageJson.version) ? packageJson.version : 'unknown';
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this check is effective here. The packageJson.version imported from the actual package.json file cannot be manipulated. I think the issue here is, that after the initial render with the correct version, the version is tampered with and when analytics grabs the value, it grabs the tampered value. Not really an issue for us after all and certainly not something we could fix. Should we revert the changes here to keep code simpler?

Comment on lines 180 to 179
constructor() {}

Copy link
Member

Choose a reason for hiding this comment

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

Empty constructors are not necessary. Please remove this.

Suggested change
constructor() {}

Comment on lines 160 to 167
@Watch('project')
handleProjectChange(newValue: string) {
if (!isValidProjectId(newValue)) {
throw new Error(
`Internet Header project key is invalid. Please provide a valid project key.`
);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

A project change requires a page reload (and is not a real scenario, since one project only ever has one project id). Throwing an error here might suggest that changing project id on the fly is supported. I'd remove this check.

Comment on lines +155 to +158
private isValidVersion(str: string): boolean {
if (typeof str !== 'string') return false;
return /^[a-z0-9.-]+$/.test(str);
}
Copy link
Member

Choose a reason for hiding this comment

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

Possibly not needed since we can't really validate the version at the right time.

@oliverschuerch oliverschuerch force-pushed the release/v9 branch 4 times, most recently from 43820ed to 34664c7 Compare October 22, 2025 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Escape query string params before calling config

5 participants