-
Notifications
You must be signed in to change notification settings - Fork 21
fix(component): sanitized and encoded config request parameters in post-internet-header to prevent injection
#5281
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
base: release/v9
Are you sure you want to change the base?
Conversation
|
|
Related Previews |
post-internet-header to prevent malicious injectionpost-internet-header to prevent injection
gfellerph
left a comment
There was a problem hiding this 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.
packages/internet-header/src/components/post-internet-header/post-internet-header.tsx
Outdated
Show resolved
Hide resolved
6f15fce to
195eda6
Compare
|
packages/internet-header/src/components/post-internet-header/post-internet-header.tsx
Outdated
Show resolved
Hide resolved
packages/internet-header/src/components/post-internet-header/post-internet-header.tsx
Outdated
Show resolved
Hide resolved
packages/internet-header/src/components/post-internet-header/post-internet-header.tsx
Outdated
Show resolved
Hide resolved
f6d651a to
fc3cf7a
Compare
fc3cf7a to
9687493
Compare
9687493 to
caeba55
Compare
a18dfd5 to
2e889b5
Compare
|
| if (!this.isValidEnvironment(this.environment)) { | ||
| throw new Error( | ||
| `Internet Header environment "${this.environment}" is not valid. Please use one of: ${PostInternetHeader.VALID_ENVIRONMENTS.join(', ')}` | ||
| ); | ||
| } |
There was a problem hiding this comment.
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:
| 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
gfellerph
left a comment
There was a problem hiding this 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.
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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?
| constructor() {} | ||
|
|
There was a problem hiding this comment.
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.
| constructor() {} |
| @Watch('project') | ||
| handleProjectChange(newValue: string) { | ||
| if (!isValidProjectId(newValue)) { | ||
| throw new Error( | ||
| `Internet Header project key is invalid. Please provide a valid project key.` | ||
| ); | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
| private isValidVersion(str: string): boolean { | ||
| if (typeof str !== 'string') return false; | ||
| return /^[a-z0-9.-]+$/.test(str); | ||
| } |
There was a problem hiding this comment.
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.
43820ed to
34664c7
Compare





📄 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