-
Notifications
You must be signed in to change notification settings - Fork 599
fix: support custom-host for azure plugin to support privatelink #1117
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: main
Are you sure you want to change the base?
Conversation
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.
This PR adds support for custom hosts in Azure plugins, which is valuable for private link scenarios. The implementation is generally good, but I've identified a few security and code quality improvements that should be addressed.
Skipped files
package-lock.json
: Skipped file patternpackage.json
: Skipped file pattern
plugins/azure/contentSafety.ts
Outdated
let agent: Agent | null = null; | ||
// privatelink doesn't contain a valid certificate, skipping verification if it's customHost. | ||
if (credentials.customHost) { | ||
agent = new Agent({ | ||
connect: { | ||
rejectUnauthorized: false, | ||
}, | ||
}); | ||
} |
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.
🔒 Security Issue Fix
Issue: The code unconditionally disables SSL verification for all custom hosts, which could create security vulnerabilities if used with untrusted endpoints.
Fix: Add a more explicit comment about the security implications and consider making this configurable.
Impact: Improves security awareness and gives users more control over the security tradeoffs.
let agent: Agent | null = null; | |
// privatelink doesn't contain a valid certificate, skipping verification if it's customHost. | |
if (credentials.customHost) { | |
agent = new Agent({ | |
connect: { | |
rejectUnauthorized: false, | |
}, | |
}); | |
} | |
let agent: Agent | null = null; | |
// SECURITY NOTE: The following disables SSL certificate validation for custom hosts. | |
// This is necessary for Azure Private Link endpoints that may use self-signed certificates, | |
// but should only be used with trusted private endpoints. | |
if (credentials.customHost) { | |
agent = new Agent({ | |
connect: { | |
rejectUnauthorized: false, | |
}, | |
}); | |
} |
plugins/azure/pii.ts
Outdated
let agent: Agent | null = null; | ||
// privatelink doesn't contain a valid certificate, skipping verification if it's customHost. | ||
if (credentials?.customHost) { | ||
agent = new Agent({ | ||
connect: { | ||
rejectUnauthorized: false, | ||
}, | ||
}); | ||
} |
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.
🔒 Security Issue Fix
Issue: The code unconditionally disables SSL verification for all custom hosts, which could create security vulnerabilities if used with untrusted endpoints.
Fix: Add a more explicit comment about the security implications and consider making this configurable.
Impact: Improves security awareness and gives users more control over the security tradeoffs.
let agent: Agent | null = null; | |
// privatelink doesn't contain a valid certificate, skipping verification if it's customHost. | |
if (credentials?.customHost) { | |
agent = new Agent({ | |
connect: { | |
rejectUnauthorized: false, | |
}, | |
}); | |
} | |
let agent: Agent | null = null; | |
// SECURITY NOTE: The following disables SSL certificate validation for custom hosts. | |
// This is necessary for Azure Private Link endpoints that may use self-signed certificates, | |
// but should only be used with trusted private endpoints. | |
if (credentials?.customHost) { | |
agent = new Agent({ | |
connect: { | |
rejectUnauthorized: false, | |
}, | |
}); | |
} |
@@ -63,7 +64,7 @@ export const handler: PluginHandler<{ | |||
|
|||
const apiVersion = parameters.apiVersion || '2024-11-01'; | |||
|
|||
const url = `https://${credentials.resourceName}.cognitiveservices.azure.com/contentsafety/text:analyze?api-version=${apiVersion}`; | |||
const url = `${credentials.customHost || `https://${credentials.resourceName}.cognitiveservices.azure.com`}/contentsafety/text:analyze?api-version=${apiVersion}`; |
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.
🛠️ Code Refactor
Issue: The URL construction doesn't validate if the customHost is a valid URL format.
Fix: Add a simple validation to ensure the customHost is properly formatted.
Impact: Prevents runtime errors from malformed URLs.
const url = `${credentials.customHost || `https://${credentials.resourceName}.cognitiveservices.azure.com`}/contentsafety/text:analyze?api-version=${apiVersion}`; | |
const baseUrl = credentials.customHost || `https://${credentials.resourceName}.cognitiveservices.azure.com`; | |
// Ensure the URL doesn't have trailing slashes that could cause path issues | |
const normalizedBaseUrl = baseUrl.replace(/\\/+$/, ''); | |
const url = `${normalizedBaseUrl}/contentsafety/text:analyze?api-version=${apiVersion}`; |
@@ -29,7 +30,7 @@ const redact = async ( | |||
|
|||
const apiVersion = parameters.apiVersion || '2024-11-01'; | |||
|
|||
const url = `https://${credentials?.resourceName}.cognitiveservices.azure.com/language/:analyze-text?api-version=${apiVersion}`; | |||
const url = `${credentials?.customHost || `https://${credentials?.resourceName}.cognitiveservices.azure.com`}/language/:analyze-text?api-version=${apiVersion}`; |
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.
🛠️ Code Refactor
Issue: The URL construction doesn't validate if the customHost is a valid URL format.
Fix: Add a simple validation to ensure the customHost is properly formatted.
Impact: Prevents runtime errors from malformed URLs.
const url = `${credentials?.customHost || `https://${credentials?.resourceName}.cognitiveservices.azure.com`}/language/:analyze-text?api-version=${apiVersion}`; | |
const baseUrl = credentials?.customHost || `https://${credentials?.resourceName}.cognitiveservices.azure.com`; | |
// Ensure the URL doesn't have trailing slashes that could cause path issues | |
const normalizedBaseUrl = baseUrl.replace(/\\/+$/, ''); | |
const url = `${normalizedBaseUrl}/language/:analyze-text?api-version=${apiVersion}`; |
"customHost": { | ||
"type": "string", | ||
"description": "Custom host for Azure AI services (Private Link etc.)" |
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.
📝 Documentation Improvement
Issue: The description for customHost doesn't mention the security implications of using this feature.
Fix: Enhance the description to include security considerations.
Impact: Improves user awareness of security implications when using custom hosts.
"customHost": { | |
"type": "string", | |
"description": "Custom host for Azure AI services (Private Link etc.)" | |
\"customHost\": { | |
\"type\": \"string\", | |
\"description\": \"Custom host for Azure AI services (Private Link etc.). Note: SSL verification is disabled when using custom hosts.\" |
Important PR Review SkippedPR review skipped as per the configuration setting. Run a manually review by commenting /matter review 💡Tips to use Matter AICommand List
|
5f6d0b6
to
83493d9
Compare
Important PR Review SkippedPR review skipped as per the configuration setting. Run a manually review by commenting /matter review 💡Tips to use Matter AICommand List
|
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.
minor comment, but looks good
@@ -53,8 +54,24 @@ const redact = async ( | |||
throw new Error('Unable to get access token'); | |||
} | |||
|
|||
let agent: Agent | null = null; |
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.
would suggest moving the initialization to a fetchUtils file and creating a method like getInsecureAgent()
Description
CustomHost support for azure plugin to use with azure private-link
Motivation
Type of Change
How Has This Been Tested?
Screenshots (if applicable)
Checklist
Related Issues