-
Notifications
You must be signed in to change notification settings - Fork 211
Revert "[PROD] Security fixes - release" #7053
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
Conversation
| return this.getSheetAPI(req, res); | ||
| } | ||
| res.status(status); | ||
| return res.send((e.response && e.response.data) || { ...e, message: e.message }); |
Check warning
Code scanning / CodeQL
Information exposure through a stack trace Medium
stack trace information
| const res = await fetch(`${this.mailchimpBaseUrl}/lists/${req.params.listId}/members/${req.params.emailHash}`, { | ||
| method: 'GET', | ||
| headers: { | ||
| 'Content-Type': req.headers['content-type'], | ||
| Authorization: this.authorization, | ||
| }, | ||
| }); |
Check failure
Code scanning / CodeQL
Server-side request forgery Critical
URL
user-provided value
The
URL
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 12 months ago
To fix the problem, we need to validate and sanitize the user-provided values (listId and emailHash) before incorporating them into the URL. We can use a whitelist approach to ensure that only valid listId values are accepted. For emailHash, we can validate it using a regular expression to ensure it conforms to the expected format.
- Create a whitelist of valid
listIdvalues. - Validate the
emailHashusing a regular expression. - If the values are not valid, return an error response instead of making the request.
-
Copy modified line R23 -
Copy modified lines R32-R36 -
Copy modified lines R116-R124
| @@ -22,2 +22,3 @@ | ||
| this.authorization = `Basic ${Buffer.from(`apikey:${this.apiKey}`).toString('base64')}`; | ||
| this.validListIds = ['list1', 'list2', 'list3']; // Example whitelist of valid list IDs | ||
| } | ||
| @@ -30,3 +31,7 @@ | ||
| async checkSubscription(req) { | ||
| const res = await fetch(`${this.mailchimpBaseUrl}/lists/${req.params.listId}/members/${req.params.emailHash}`, { | ||
| const { listId, emailHash } = req.params; | ||
| if (!this.isValidListId(listId) || !this.isValidEmailHash(emailHash)) { | ||
| throw new Error('Invalid parameters'); | ||
| } | ||
| const res = await fetch(`${this.mailchimpBaseUrl}/lists/${listId}/members/${emailHash}`, { | ||
| method: 'GET', | ||
| @@ -110,2 +115,11 @@ | ||
| } | ||
|
|
||
| isValidListId(listId) { | ||
| return this.validListIds.includes(listId); | ||
| } | ||
|
|
||
| isValidEmailHash(emailHash) { | ||
| const emailHashRegex = /^[a-f0-9]{32}$/; // Example regex for validating email hash | ||
| return emailHashRegex.test(emailHash); | ||
| } | ||
| } |
| const res = await fetch(`${this.mailchimpBaseUrl}/lists/${req.params.listId}/members`, { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': req.headers['content-type'], | ||
| Authorization: this.authorization, | ||
| }, | ||
| body: formData, | ||
| }); |
Check failure
Code scanning / CodeQL
Server-side request forgery Critical
URL
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 12 months ago
To fix the SSRF vulnerability, we need to validate and sanitize the listId parameter before using it in the URL. One way to do this is to use a whitelist of allowed listId values or to ensure that the listId conforms to a specific pattern expected by the Mailchimp API. This will prevent attackers from injecting malicious values into the URL.
We will implement a validation function that checks if the listId is in a predefined list of allowed values. If the listId is not valid, we will throw an error or handle it appropriately.
-
Copy modified line R23 -
Copy modified lines R44-R45 -
Copy modified lines R113-R119
| @@ -22,2 +22,3 @@ | ||
| this.authorization = `Basic ${Buffer.from(`apikey:${this.apiKey}`).toString('base64')}`; | ||
| this.allowedListIds = ['list1', 'list2', 'list3']; // Example allowed list IDs | ||
| } | ||
| @@ -42,3 +43,4 @@ | ||
| const formData = JSON.stringify(req.body); | ||
| const res = await fetch(`${this.mailchimpBaseUrl}/lists/${req.params.listId}/members`, { | ||
| const listId = this.validateListId(req.params.listId); | ||
| const res = await fetch(`${this.mailchimpBaseUrl}/lists/${listId}/members`, { | ||
| method: 'POST', | ||
| @@ -110,2 +112,9 @@ | ||
| } | ||
| validateListId(listId) { | ||
| if (this.allowedListIds.includes(listId)) { | ||
| return listId; | ||
| } else { | ||
| throw new Error('Invalid list ID'); | ||
| } | ||
| } | ||
| } |
| const res = await fetch(`${this.mailchimpBaseUrl}/lists/${req.params.listId}/members/${req.params.emailHash}`, { | ||
| method: 'PUT', | ||
| headers: { | ||
| 'Content-Type': req.headers['content-type'], | ||
| Authorization: this.authorization, | ||
| }, | ||
| body: formData, | ||
| }); |
Check failure
Code scanning / CodeQL
Server-side request forgery Critical
URL
user-provided value
The
URL
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 12 months ago
To fix the problem, we need to validate and sanitize the user-provided values (listId and emailHash) before incorporating them into the URL. We can use a whitelist approach to ensure that only valid listId values are accepted. For emailHash, we can validate it using a regular expression to ensure it conforms to the expected format.
- Create a whitelist of valid
listIdvalues. - Validate the
listIdagainst the whitelist. - Validate the
emailHashusing a regular expression.
-
Copy modified lines R31-R44 -
Copy modified lines R56-R63 -
Copy modified lines R76-R89 -
Copy modified lines R102-R115
| @@ -30,3 +30,16 @@ | ||
| async checkSubscription(req) { | ||
| const res = await fetch(`${this.mailchimpBaseUrl}/lists/${req.params.listId}/members/${req.params.emailHash}`, { | ||
| const validListIds = ['list1', 'list2', 'list3']; // Example whitelist | ||
| const listId = req.params.listId; | ||
| const emailHash = req.params.emailHash; | ||
|
|
||
| if (!validListIds.includes(listId)) { | ||
| throw new Error('Invalid listId'); | ||
| } | ||
|
|
||
| const emailHashPattern = /^[a-f0-9]{32}$/; // Example pattern for email hash | ||
| if (!emailHashPattern.test(emailHash)) { | ||
| throw new Error('Invalid emailHash'); | ||
| } | ||
|
|
||
| const res = await fetch(`${this.mailchimpBaseUrl}/lists/${listId}/members/${emailHash}`, { | ||
| method: 'GET', | ||
| @@ -42,3 +55,10 @@ | ||
| const formData = JSON.stringify(req.body); | ||
| const res = await fetch(`${this.mailchimpBaseUrl}/lists/${req.params.listId}/members`, { | ||
| const validListIds = ['list1', 'list2', 'list3']; // Example whitelist | ||
| const listId = req.params.listId; | ||
|
|
||
| if (!validListIds.includes(listId)) { | ||
| throw new Error('Invalid listId'); | ||
| } | ||
|
|
||
| const res = await fetch(`${this.mailchimpBaseUrl}/lists/${listId}/members`, { | ||
| method: 'POST', | ||
| @@ -55,3 +75,16 @@ | ||
| const formData = JSON.stringify(req.body); | ||
| const res = await fetch(`${this.mailchimpBaseUrl}/lists/${req.params.listId}/members/${req.params.emailHash}`, { | ||
| const validListIds = ['list1', 'list2', 'list3']; // Example whitelist | ||
| const listId = req.params.listId; | ||
| const emailHash = req.params.emailHash; | ||
|
|
||
| if (!validListIds.includes(listId)) { | ||
| throw new Error('Invalid listId'); | ||
| } | ||
|
|
||
| const emailHashPattern = /^[a-f0-9]{32}$/; // Example pattern for email hash | ||
| if (!emailHashPattern.test(emailHash)) { | ||
| throw new Error('Invalid emailHash'); | ||
| } | ||
|
|
||
| const res = await fetch(`${this.mailchimpBaseUrl}/lists/${listId}/members/${emailHash}`, { | ||
| method: 'PUT', | ||
| @@ -68,3 +101,16 @@ | ||
| const formData = JSON.stringify(req.body); | ||
| const res = await fetch(`${this.mailchimpBaseUrl}/lists/${req.params.listId}/members/${req.params.emailHash}/tags`, { | ||
| const validListIds = ['list1', 'list2', 'list3']; // Example whitelist | ||
| const listId = req.params.listId; | ||
| const emailHash = req.params.emailHash; | ||
|
|
||
| if (!validListIds.includes(listId)) { | ||
| throw new Error('Invalid listId'); | ||
| } | ||
|
|
||
| const emailHashPattern = /^[a-f0-9]{32}$/; // Example pattern for email hash | ||
| if (!emailHashPattern.test(emailHash)) { | ||
| throw new Error('Invalid emailHash'); | ||
| } | ||
|
|
||
| const res = await fetch(`${this.mailchimpBaseUrl}/lists/${listId}/members/${emailHash}/tags`, { | ||
| method: 'POST', |
| const res = await fetch(`${this.mailchimpBaseUrl}/lists/${req.params.listId}/members/${req.params.emailHash}/tags`, { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': req.headers['content-type'], | ||
| Authorization: this.authorization, | ||
| }, | ||
| body: formData, | ||
| }); |
Check failure
Code scanning / CodeQL
Server-side request forgery Critical
URL
user-provided value
The
URL
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 12 months ago
To fix the SSRF vulnerability, we need to validate and sanitize the user input before incorporating it into the URL. Specifically, we should ensure that req.params.listId and req.params.emailHash are valid and conform to expected patterns. This can be achieved by using a whitelist of acceptable values or by validating the format of these parameters.
- Validate
req.params.listIdandreq.params.emailHashto ensure they conform to expected patterns. - Reject or sanitize any input that does not match the expected patterns.
-
Copy modified lines R69-R76
| @@ -68,3 +68,10 @@ | ||
| const formData = JSON.stringify(req.body); | ||
| const res = await fetch(`${this.mailchimpBaseUrl}/lists/${req.params.listId}/members/${req.params.emailHash}/tags`, { | ||
| const listId = req.params.listId; | ||
| const emailHash = req.params.emailHash; | ||
|
|
||
| if (!/^[a-zA-Z0-9]+$/.test(listId) || !/^[a-f0-9]{32}$/.test(emailHash)) { | ||
| throw new Error('Invalid listId or emailHash'); | ||
| } | ||
|
|
||
| const res = await fetch(`${this.mailchimpBaseUrl}/lists/${listId}/members/${emailHash}/tags`, { | ||
| method: 'POST', |
Reverts #7052