Commit ccbdfa3
authored
fix(scripts): eliminate false positives in dependency pinning npm pattern (#273)
## Description
Replace regex-based pattern matching with JSON parsing for package.json
validation, targeting only actual dependency sections. The previous
regex approach incorrectly flagged metadata fields like `name`,
`version`, `description`, and `repository` URLs as unpinned
dependencies.
- Add `Get-NpmDependencyViolations` function that parses package.json as
structured JSON and checks only `dependencies`, `devDependencies`,
`peerDependencies`, and `optionalDependencies` sections
- Update npm pattern config to use `ValidationFunc` dispatcher instead
of `VersionPatterns` regex approach
- Add ValidationFunc dispatch logic to `Get-DependencyViolation` for
type-specific validation functions
- Update `Test-ShellDownloadSecurity` to use consistent `FileInfo`
hashtable parameter
- Create test fixtures for metadata-only and with-dependencies npm
scenarios
- Add Pester tests covering JSON parsing, dependency extraction, and
version pattern matching
## Related Issue(s)
Fixes #267
## Type of Change
Select all that apply:
**Code & Documentation:**
- [x] Bug fix (non-breaking change fixing an issue)
- [ ] New feature (non-breaking change adding functionality)
- [ ] Breaking change (fix or feature causing existing functionality to
change)
- [ ] Documentation update
**Infrastructure & Configuration:**
- [ ] GitHub Actions workflow
- [ ] Linting configuration (markdown, PowerShell, etc.)
- [ ] Security configuration
- [ ] DevContainer configuration
- [ ] Dependency update
**AI Artifacts:**
- [ ] Reviewed contribution with `prompt-builder` agent and addressed
all feedback
- [ ] Copilot instructions (`.github/instructions/*.instructions.md`)
- [ ] Copilot prompt (`.github/prompts/*.prompt.md`)
- [ ] Copilot agent (`.github/agents/*.agent.md`)
> **Note for AI Artifact Contributors**:
>
> - **Agents**: Research, indexing/referencing other project (using
standard VS Code GitHub Copilot/MCP tools), planning, and general
implementation agents likely already exist. Review `.github/agents/`
before creating new ones.
> - **Model Versions**: Only contributions targeting the **latest
Anthropic and OpenAI models** will be accepted. Older model versions
(e.g., GPT-3.5, Claude 3) will be rejected.
> - See [Agents Not
Accepted](../docs/contributing/custom-agents.md#agents-not-accepted) and
[Model Version
Requirements](../docs/contributing/ai-artifacts-common.md#model-version-requirements).
**Other:**
- [x] Script/automation (`.ps1`, `.sh`, `.py`)
- [ ] Other (please describe):
## Sample Prompts (for AI Artifact Contributions)
<!-- Not applicable - no AI artifacts in this PR -->
## Testing
- PSScriptAnalyzer: All files passed with 0 issues
- Pester: 33 tests passed (including 4 new tests for
`Get-NpmDependencyViolations`)
- Full dependency scan: 100% compliance, 0 violations
## Checklist
### Required Checks
- [x] Documentation is updated (if applicable)
- [x] Files follow existing naming conventions
- [x] Changes are backwards compatible (if applicable)
- [x] Tests added for new functionality (if applicable)
### AI Artifact Contributions
<!-- Not applicable - no AI artifacts in this PR -->
### Required Automated Checks
The following validation commands must pass before merging:
- [ ] Markdown linting: `npm run lint:md`
- [ ] Spell checking: `npm run spell-check`
- [ ] Frontmatter validation: `npm run lint:frontmatter`
- [ ] Link validation: `npm run lint:md-links`
- [x] PowerShell analysis: `npm run lint:ps`
## Security Considerations
- [x] This PR does not contain any sensitive or NDA information
- [x] Any new dependencies have been reviewed for security issues
- [x] Security-related scripts follow the principle of least privilege
## Additional Notes
The `ValidationFunc` dispatcher pattern enables type-specific validation
functions without relying on regex patterns. This approach provides
better accuracy for structured file formats like JSON and can be
extended to other dependency types in the future.
🔧 - Generated by Copilot1 parent c52d6e2 commit ccbdfa3
File tree
6 files changed
+352
-23
lines changed- scripts
- security
- tests
- Fixtures/Npm
- security
6 files changed
+352
-23
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
144 | 138 | | |
145 | 139 | | |
146 | 140 | | |
| |||
211 | 205 | | |
212 | 206 | | |
213 | 207 | | |
214 | | - | |
215 | | - | |
| 208 | + | |
| 209 | + | |
216 | 210 | | |
217 | 211 | | |
218 | 212 | | |
219 | 213 | | |
220 | | - | |
| 214 | + | |
221 | 215 | | |
222 | 216 | | |
| 217 | + | |
| 218 | + | |
223 | 219 | | |
224 | 220 | | |
225 | 221 | | |
| |||
246 | 242 | | |
247 | 243 | | |
248 | 244 | | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
257 | 328 | | |
258 | 329 | | |
259 | 330 | | |
| |||
365 | 436 | | |
366 | 437 | | |
367 | 438 | | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
368 | 474 | | |
369 | 475 | | |
370 | 476 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
Lines changed: 23 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
0 commit comments