Skip to content

πŸ›‘οΈ Sentinel: [MEDIUM] Fail securely on null inputs in Duck<T> API#53

Closed
timonkrebs wants to merge 1 commit into
mainfrom
sentinel/fail-securely-duck-validation-7274913049103684126
Closed

πŸ›‘οΈ Sentinel: [MEDIUM] Fail securely on null inputs in Duck<T> API#53
timonkrebs wants to merge 1 commit into
mainfrom
sentinel/fail-securely-duck-validation-7274913049103684126

Conversation

@timonkrebs

Copy link
Copy Markdown
Owner

🚨 Severity: MEDIUM
πŸ’‘ Vulnerability: The public API Duck<T>(this object instance) did not explicitly validate the instance input for null values. If null was passed, it bypassed the type check and threw a misleading InvalidOperationException originally intended for missing generator proxies.
🎯 Impact: Obscures root causes and fails to securely halt execution early, which could potentially lead to unexpected application state if the incorrect exception type is caught or misdiagnosed downstream.
πŸ”§ Fix: Added explicit input validation (ArgumentNullException.ThrowIfNull(instance)) at the start of the Duck<T> method to enforce failing securely and fast. Documented the learning in .jules/sentinel.md.
βœ… Verification: Ran NTypeForge.Generator.Tests to verify no regressions. Manually verified in a test project that Duck<T> correctly throws ArgumentNullException securely on null input. Code review successfully approved.


PR created automatically by Jules for task 7274913049103684126 started by @timonkrebs

Co-authored-by: timonkrebs <11026852+timonkrebs@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 8, 2026 09:54
@google-labs-jules

Copy link
Copy Markdown
Contributor

πŸ‘‹ Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a πŸ‘€ emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens the NTypeForge public duck-typing API by failing fast and accurately when Duck<T> is invoked with a null receiver, aligning runtime behavior with secure input-validation expectations and documenting the lesson in the Sentinel log.

Changes:

  • Added ArgumentNullException.ThrowIfNull(instance) to Duck<T>(this object instance) to explicitly reject null inputs.
  • Updated .jules/sentinel.md with a new entry documenting the null-input validation lesson and prevention guidance.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/NTypeForge/DuckExtensions.cs Adds explicit null-guard to Duck<T> to throw ArgumentNullException instead of a misleading InvalidOperationException.
.jules/sentinel.md Documents the vulnerability, learning, and prevention steps related to null input validation on public APIs.

πŸ’‘ Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

/// </exception>
public static T Duck<T>(this object instance) where T : class
{
ArgumentNullException.ThrowIfNull(instance);

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

πŸ’‘ Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8cb219e20a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with πŸ‘.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

/// </exception>
public static T Duck<T>(this object instance) where T : class
{
ArgumentNullException.ThrowIfNull(instance);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Add the same null guard to generated Duck methods

This guard only runs in the runtime fallback, but the common source-generated Duck<T> path emitted by ProxyEmitter.EmitDuckMethod bypasses this method entirely. For a nullable concrete receiver that structurally matches an interface (for example Adder? a = null; a.Duck<ICalc>()), the generated extension still wraps the null receiver and returns a proxy that later fails with a NullReferenceException, so the public API does not consistently fail fast on null inputs unless the generator emits the same check.

Useful? React with πŸ‘Β / πŸ‘Ž.

@timonkrebs timonkrebs closed this Jul 20, 2026
@timonkrebs
timonkrebs deleted the sentinel/fail-securely-duck-validation-7274913049103684126 branch July 20, 2026 20:32
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