Skip to content

Commit 1248ec8

Browse files
Merge pull request #413 from contentstack/revert/change
Change revert
2 parents 4336914 + bae744b commit 1248ec8

File tree

1 file changed

+6
-49
lines changed

1 file changed

+6
-49
lines changed

lib/core/Util.js

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,7 @@ const isValidURL = (url) => {
140140
} catch (error) {
141141
// If URL parsing fails, it might be a relative URL without protocol
142142
// Allow it if it doesn't contain protocol indicators or suspicious patterns
143-
if (error instanceof TypeError) {
144-
return !url.includes('://') && !url.includes('\\') && !url.includes('@')
145-
}
146-
return false
143+
return !url.includes('://') && !url.includes('\\') && !url.includes('@')
147144
}
148145
}
149146

@@ -152,7 +149,6 @@ const isAllowedHost = (hostname) => {
152149
const allowedDomains = [
153150
'api.contentstack.io',
154151
'eu-api.contentstack.com',
155-
'au-api.contentstack.com',
156152
'azure-na-api.contentstack.com',
157153
'azure-eu-api.contentstack.com',
158154
'gcp-na-api.contentstack.com',
@@ -181,53 +177,14 @@ const isAllowedHost = (hostname) => {
181177
})
182178
}
183179

184-
// Helper function to validate individual URL properties
185-
const validateURLProperty = (config, prop) => {
186-
if (config[prop] && !isValidURL(config[prop])) {
187-
throw new Error(`SSRF Prevention: ${prop} "${config[prop]}" is not allowed`)
188-
}
189-
}
190-
191-
// Helper function to validate combined URL (baseURL + url)
192-
const validateCombinedURL = (baseURL, url) => {
193-
try {
194-
let fullURL
195-
// Handle relative URLs with baseURL
196-
if (url.startsWith('/') || url.startsWith('./') || url.startsWith('../')) {
197-
fullURL = new URL(url, baseURL).href
198-
} else {
199-
// If url is absolute, it overrides baseURL
200-
fullURL = url
201-
}
202-
203-
if (!isValidURL(fullURL)) {
204-
throw new Error(`SSRF Prevention: Combined URL "${fullURL}" is not allowed`)
205-
}
206-
} catch (error) {
207-
if (error.message.startsWith('SSRF Prevention:')) {
208-
throw error
209-
}
210-
throw new Error(`SSRF Prevention: Invalid URL combination of baseURL "${baseURL}" and url "${url}"`)
211-
}
212-
}
213-
214180
export const validateAndSanitizeConfig = (config) => {
215-
if (!config) {
216-
throw new Error('Invalid request configuration: missing config')
217-
}
218-
219-
// Validate all possible URL properties in axios config to prevent SSRF attacks
220-
const urlProperties = ['url', 'baseURL']
221-
urlProperties.forEach(prop => validateURLProperty(config, prop))
222-
223-
// If we have both baseURL and url, validate the combined URL
224-
if (config.baseURL && config.url) {
225-
validateCombinedURL(config.baseURL, config.url)
181+
if (!config || !config.url) {
182+
throw new Error('Invalid request configuration: missing URL')
226183
}
227184

228-
// Ensure we have at least one URL property
229-
if (!config.url && !config.baseURL) {
230-
throw new Error('Invalid request configuration: missing URL or baseURL')
185+
// Validate the URL to prevent SSRF attacks
186+
if (!isValidURL(config.url)) {
187+
throw new Error(`SSRF Prevention: URL "${config.url}" is not allowed`)
231188
}
232189

233190
return config

0 commit comments

Comments
 (0)