-
Notifications
You must be signed in to change notification settings - Fork 0
Security hardening and code quality improvements #10
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
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,9 @@ on: | |
| branches: | ||
| - main | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| spellcheck: | ||
| runs-on: ubuntu-latest | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /** | ||
| * Shared semver comparison utility for registry scripts. | ||
| * | ||
| * Handles strict major.minor.patch versions. Rejects pre-release suffixes | ||
| * and non-numeric components rather than silently degrading. | ||
| */ | ||
|
|
||
| /** | ||
| * Parse a semver string into its numeric components. | ||
| * Throws if any component is not a non-negative integer. | ||
| * | ||
| * @param {string} version - Semver string (e.g., "1.2.3") | ||
| * @returns {number[]} Array of [major, minor, patch] | ||
| */ | ||
| export function parseSemver(version) { | ||
| const parts = version.split('.'); | ||
| const nums = parts.map((part, i) => { | ||
| const n = Number(part); | ||
| if (!Number.isInteger(n) || n < 0) { | ||
| throw new Error( | ||
| `Invalid semver component "${part}" at position ${i} in version "${version}"` | ||
| ); | ||
| } | ||
| return n; | ||
| }); | ||
| return nums; | ||
| } | ||
|
|
||
| /** | ||
| * Compare two semver strings (major.minor.patch) for sorting ascending. | ||
| * Returns negative if a < b, positive if a > b, 0 if equal. | ||
| * | ||
| * Throws on invalid version strings (pre-release suffixes, non-numeric parts) | ||
| * rather than silently producing incorrect sort order. | ||
| * | ||
| * @param {string} a - First version string | ||
| * @param {string} b - Second version string | ||
| * @returns {number} Comparison result for Array.sort() | ||
| */ | ||
| export function compareSemver(a, b) { | ||
| const pa = parseSemver(a); | ||
| const pb = parseSemver(b); | ||
| const len = Math.max(pa.length, pb.length); | ||
| for (let i = 0; i < len; i++) { | ||
| const diff = (pa[i] || 0) - (pb[i] || 0); | ||
| if (diff !== 0) return diff; | ||
| } | ||
| return 0; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,8 @@ $parentDir = Split-Path -Parent $repoDir | |
| $extensions = @( | ||
| @{ Name = "app"; Color = "Cyan"; Path = Join-Path $parentDir "azd-app\cli" }, | ||
| @{ Name = "copilot"; Color = "Magenta"; Path = Join-Path $parentDir "azd-copilot\cli" }, | ||
| @{ Name = "exec"; Color = "Green"; Path = Join-Path $parentDir "azd-exec\cli" } | ||
| @{ Name = "exec"; Color = "Green"; Path = Join-Path $parentDir "azd-exec\cli" }, | ||
| @{ Name = "rest"; Color = "Yellow"; Path = Join-Path $parentDir "azd-rest\cli" } | ||
| ) | ||
|
|
||
| # Validate all repos exist before starting | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -198,9 +198,9 @@ const { id, name, tagline, description, icon, website, repository, features, sce | |
| const command = (btn as HTMLElement).dataset.command || ''; | ||
| try { | ||
| await navigator.clipboard.writeText(command); | ||
| btn.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>'; | ||
| btn.innerHTML = '<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>'; | ||
| } catch { | ||
| btn.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>'; | ||
| btn.innerHTML = '<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>'; | ||
| } | ||
| setTimeout(() => { btn.innerHTML = originalHTML; copying = false; }, 1500); | ||
| }); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,6 +127,7 @@ const installAzdTabs = [ | |
| publishedDate="2025-11-09T20:22:39Z" | ||
| > | ||
| <Fragment slot="head"> | ||
| <meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self'; font-src 'self'; connect-src 'self'; base-uri 'self'; form-action 'none'; frame-ancestors 'none';" /> | ||
| <meta name="keywords" content="Azure, Azure Developer CLI, azd, azd extensions, azd app, azd exec, azd copilot, azd rest, Azure CLI, developer tools, Jon Gallant, jongio, Azure authentication, local development, AI assistant, REST API" /> | ||
| <meta name="robots" content="index, follow" /> | ||
| <link rel="icon" type="image/svg+xml" href="/azd-extensions/favicon.svg" /> | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / CodeQL
Incomplete URL substring sanitization High
Copilot Autofix
AI 3 months ago
In general, to fix this kind of problem you must avoid substring/suffix checks for host validation and instead compare the parsed
hostnameagainst a whitelist of exact allowed hostnames or well-defined patterns that cannot be spoofed by prefixing or embedding the allowed host. For GitHub artifacts, that usually means allowing onlygithub.comand possiblyobjects.githubusercontent.comor similar, as explicit, complete hostnames.For this code, the safest change that preserves functionality and intent is to replace the
endsWith(ALLOWED_ARTIFACT_HOST)check with an equality check against a whitelist of allowed hostnames. Since the surrounding comment says “Allowed hostname for artifact download URLs (GitHub releases only)” and the constant is singular, we can update it to an array of explicit hostnames and checkincludes(parsed.hostname). This avoids accidental acceptance ofevilgithub.comwhile still allowing additional GitHub-related artifact hosts if desired in the future.Concretely, in
scripts/update-registry.js:ALLOWED_ARTIFACT_HOSTfrom a string to an array like['github.com'](or include any additional strictly-known hosts).isAllowedArtifactUrlso that it returnstrueonly if:parsed.protocol === 'https:', andALLOWED_ARTIFACT_HOSTS.includes(parsed.hostname)(exact match, case-sensitive, which is fine given Node’s URL normalization).ALLOWED_ARTIFACT_HOSTSto reflect that it is now a list, but keep usage limited to the provided snippet.No new imports are needed; we continue using the built-in
URLclass and existing imports only.