Skip to content

feat: add key/value allowlisting to OperationContext#181

Open
arorashivam96 wants to merge 1 commit into
mainfrom
feat/context-allowlisting
Open

feat: add key/value allowlisting to OperationContext#181
arorashivam96 wants to merge 1 commit into
mainfrom
feat/context-allowlisting

Conversation

@arorashivam96
Copy link
Copy Markdown
Contributor

Summary

  • Adds key/value allowlisting to OperationContext.__post_init__ so that only known keys (app, skill, agent) and their respective allowlisted values are accepted
  • Prevents PII from entering the User-Agent header even from standalone callers outside the plugin (e.g., --context "ssn=123-45-6789" is now rejected at the SDK layer)

What's validated

Key Validation Example valid Example rejected
app Must match <name>/<version> format dataverse-skills/1.5.0 noslash
skill Must be one of 7 known skills dv-data not-a-skill
agent Must be one of 5 known agents claude-code not-an-agent
Unknown keys Rejected outright ssn=123-45-6789

Changes

File Change
src/.../core/config.py Added _ALLOWED_KEYS, _ALLOWED_SKILLS, _ALLOWED_AGENTS, _APP_PATTERN; key/value validation loop in __post_init__
tests/unit/test_operation_context.py 6 new tests: unknown key, unknown skill, unknown agent, PII in valid format, invalid app format

Test plan

  • pytest tests/unit/test_operation_context.py -v — 25 passed
  • pytest tests/unit/ -v — 1394 passed, 0 regressions
  • black src tests --check — clean

🤖 Generated with Claude Code

Validate that operation_context keys are from {app, skill, agent} and
values match their respective allowlists. Unknown keys like 'ssn' or
'name' are rejected with ValueError. This prevents PII from entering
the User-Agent header even from standalone callers outside the plugin.

- skill values must be in the 7 known Dataverse skills
- agent values must be in {claude-code, copilot, cursor, codex, unknown}
- app values must match <name>/<version> format

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 13, 2026 20:17
@arorashivam96 arorashivam96 requested a review from a team as a code owner May 13, 2026 20:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a closed allowlist for OperationContext.user_agent_context so only the keys app, skill, and agent are accepted, with values for skill and agent constrained to known identifier sets and app constrained to a <name>/<version> pattern. This hardens the SDK against PII leaking into the User-Agent header from standalone callers, on top of the existing structural validation.

Changes:

  • Introduces _ALLOWED_KEYS, _ALLOWED_SKILLS, _ALLOWED_AGENTS, and _APP_PATTERN constants in core/config.py.
  • Adds a per-pair allowlist validation loop in OperationContext.__post_init__ plus updated docstring.
  • Adds 5 negative unit tests covering unknown keys, unknown skill, unknown agent, PII-shaped input, and malformed app values.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/PowerPlatform/Dataverse/core/config.py Adds allowlist constants, app-value regex, validation loop, and updates docstring/raises notes.
tests/unit/test_operation_context.py Adds 5 tests asserting ValueError for unknown keys/values and invalid app format.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants