Skip to content

Update YAML rule for $APP.UseDeveloperExceptionPage and snapshot file #187

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

Conversation

ESS-ENN
Copy link
Contributor

@ESS-ENN ESS-ENN commented Mar 27, 2025

Summary by CodeRabbit

  • Refactor
    • Enhanced the evaluation logic for developer exception triggers by refining the conditions and improving context sensitivity.
  • Tests
    • Updated the formatting of test examples to include minor punctuation changes, ensuring consistent alignment in output snapshots.

Sakshis and others added 30 commits December 16, 2024 13:09
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ ESS-ENN
❌ Sakshis


Sakshis seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link

coderabbitai bot commented Mar 27, 2025

Walkthrough

This PR revises the YAML rule for $APP.UseDeveloperExceptionPage() by restructuring its definition. The rule now classifies the invocation as a kind_invocation_expression with explicit checks for member_access_expression and argument_list, along with conditions to ensure it is not nested within a disallowed if_statement context. Additionally, a new rule for expression_statement has been added to avoid error outcomes. The associated snapshot file has been updated to include semicolons in the source entries, with corresponding adjustments to the end values.

Changes

File Change Summary
rules/.../stacktrace-disclosure-csharp.yml Restructured the $APP.UseDeveloperExceptionPage() utility to a kind_invocation_expression with new child node conditions and added an expression_statement rule.
tests/.../stacktrace-disclosure-csharp-snapshot.yml Added semicolons to app.UseDeveloperExceptionPage() source entries and incremented end values to reflect the formatting change.

Sequence Diagram(s)

sequenceDiagram
    participant Code as Developer Code
    participant Rule as Rule Engine
    participant Matcher as Pattern Matcher
    Code->>Rule: Invoke $APP.UseDeveloperExceptionPage()
    Rule->>Matcher: Evaluate as kind_invocation_expression
    Matcher->>Rule: Confirm presence of member_access_expression & argument_list
    Rule->>Matcher: Verify not in disallowed if_statement context
    Matcher-->>Rule: Conditions met
    Rule->>Rule: Check expression_statement and error context
    Rule-->>Code: Return validation outcome
Loading

Possibly related PRs

Suggested reviewers

  • ganeshpatro321

Poem

I'm a rabbit with code hops so light,
Revising rules that shine so bright,
Pattern checks and semicolons in line,
In YAML fields the changes align,
Hop along, fellow coders, with delight! 🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d6616fc and 299b036.

📒 Files selected for processing (2)
  • rules/csharp/security/stacktrace-disclosure-csharp.yml (1 hunks)
  • tests/__snapshots__/stacktrace-disclosure-csharp-snapshot.yml (1 hunks)
🔇 Additional comments (9)
tests/__snapshots__/stacktrace-disclosure-csharp-snapshot.yml (6)

5-8: Semicolon Addition & End Value Update in First Snapshot Block

The source field now correctly ends with a semicolon, and the corresponding end value has been updated to reflect the additional character. This change ensures that the snapshot aligns with the updated coding standards and rule definitions.


11-14: Consistent Semicolon Application & End Value Adjustment in Second Snapshot Block

The changes on these lines add the semicolon to the app.UseDeveloperExceptionPage() statement and adjust the end value. This consistency is important for accurate snapshot comparisons against the live rules.


17-20: Uniform Source Formatting in Third Snapshot Block

The semicolon has been appended to the source entry and the end value updated accordingly. Maintaining uniform formatting across snapshot entries will help prevent false positives during test comparisons.


23-26: Updated Snapshot Entry: Semicolon Inclusion & End Value Revision

The addition of the semicolon in the source line, along with the revised end value, ensures that the snapshot precisely mirrors the intended real code output as per the updated rule.


29-32: Snapshot Entry Consistency: Semicolon & End Field Adjustment

These modifications continue the pattern of consistently appending a semicolon to the source field while adjusting the end value. This uniformity supports reliable snapshot testing.


39-42: Final Snapshot Block: Correct Semicolon and End Value

The changes here complete the snapshot updates by ensuring that the source field is formatted with a semicolon, and that the end value is recalibrated. This final update ties the snapshot changes neatly with the updated invocation rules.

rules/csharp/security/stacktrace-disclosure-csharp.yml (3)

17-27: Enhanced kind_invocation_expression Utility Definition

The new structure explicitly defines the invocation expression by requiring its first child to be a member_access_expression (with a check for $ENV.IsDevelopment) and its second child to be an argument_list. These explicit checks improve the precision of pattern matching for the $APP.UseDeveloperExceptionPage() usage.


28-41: Explicit Utility for $APP.UseDeveloperExceptionPage(...)

The updated utility now defines the invocation as an expression_statement with the pattern $APP.UseDeveloperExceptionPage($$$);. Moreover, it introduces constraints ensuring the expression is not nested within a disallowed if_statement that may incorporate an invocation expression. This clear structure aids in targeting only the appropriate contexts.


42-53: Layered Rule Checks to Avoid ERROR Contexts

The rule block now enforces additional validations by ensuring that the $APP.UseDeveloperExceptionPage(...) invocation is not situated in any context containing an ERROR. This layered approach is a robust safeguard against unintentional exposure of detailed stacktrace information in non-development environments.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai bot changed the title @coderabbitai Update YAML rule for $APP.UseDeveloperExceptionPage and snapshot file Mar 27, 2025
@petrisorcoderabbit petrisorcoderabbit merged commit cc2e5aa into coderabbitai:main Mar 27, 2025
1 of 2 checks passed
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.

3 participants