-
Notifications
You must be signed in to change notification settings - Fork 750
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
Semgrep rules for adapters #2833
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
It depends on adapter code maintainer whether to use utils for status check or whether to check using custom function. So removing no-content-status and bad-request-not-ok-status rules
languages: | ||
- go | ||
message: > | ||
Scope of `$BUILDER` is limited to this adapter package. Therefore `$BUILDER` can be renamed to `adapter`. Refer following example. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please also add a comment about how using the adapter's actual name for the adapter struct also makes it redundant with the package name. Example, foo.Foo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
03ee138 updates message
languages: | ||
- go | ||
message: > | ||
Scope of `$BUILDER` is limited to this adapter package. Therefore `$BUILDER` can be renamed to `adapter`. Refer following example. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Rewrite as Refer to the following example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
languages: | ||
- go | ||
message: > | ||
Found incorrect assignment made to `Bid` Consider using `seatBids.Bid` loop index as shown below |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will be helpful to give the author some explanation of why their implementation is incorrect. Can you please provide some context in the description about how the loop variable gets overridden and that can cause unexpected behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dc62fff adds the reasoning behind not assigning loop variable pointer value as bid
} | ||
... | ||
} | ||
- pattern: > |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't we need another case here as
- pattern: >
for _, $BID := range ... {
...
... := append(..., &adapters.TypedBid{
$KEY: &$BID,
...
})
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we won't be reinitialising i.e := append
inside loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok! Yeah, you're right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@onkarvhanumante thanks for making the changes. I just have two minor comments about the messages.
Found incorrect assignment made to $KEY. $BID variable receives a new value in each iteration of range loop. Assigning the address of $BID `(&$BID)` to $KEY will result in a pointer that always points to the same memory address with the value of the last iteration. | ||
This can lead to unexpected behavior or incorrect results. Refer https://go.dev/play/p/9ZS1f-5h4qS | ||
|
||
Consider using `seatBids.Bid` loop index as shown below |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Consider rewriting the last sentence as:
Consider using an index variable in the seatBids.Bid loop as shown below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -3,9 +3,22 @@ rules: | |||
languages: | |||
- go | |||
message: > | |||
Scope of `$BUILDER` is limited to this adapter package. Therefore `$BUILDER` can be renamed to `adapter`. Refer to the following example. | |||
Using the adapter name for the struct makes it redundant with the package name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend making this comment a little simpler such as:
You can call this simply "adapter", the $BUILDER identification is already supplied by the package name. As you have it, referencing your adapter from outside the package would be $BUILDER.$BUILDER which looks a little redundant. See example below:
(Stealing these words by Hans from an old adapter PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the updated message
I see that the HTTP response checks were removed from this PR. I agree that the use of utils is optional and should not block the PR from merging. It is upto the author if they want to update the adapter to use the utils or not but it is better to offer them an option. I think we should keep a semgrep rule that will add a comment as optional and let the author make decision. |
@Sonali-More-Xandr I don't have a very strong opinion on this one so if you both think it will be valuable to have that as a warning, I won't fight it :) |
For now lets have 2 semgrep rules. We can add other in new PR |
* Fix: deal tiers no longer ignored due to presence of tid (prebid#2829) * CAPT-787: GPP support for imds bidder. (prebid#2867) Co-authored-by: Timothy M. Ace <[email protected]> * Adsinteractive: change usersync endpoint to https (prebid#2861) Co-authored-by: Balint Vargha <[email protected]> * consumable adapter: add gpp support (prebid#2883) * feat: IX Bid Adapter - gpp support for user sync urls (prebid#2873) Co-authored-by: Chris Corbo <[email protected]> * fix: update links in readme (prebid#2888) authored by @akkapur * New Adapter: AIDEM (prebid#2824) Co-authored-by: AndreaC <[email protected]> Co-authored-by: Andrea Tumbarello <[email protected]> Co-authored-by: darkstar <[email protected]> * Improve Digital adapter: Set currency in bid response (prebid#2886) * Sharethrough: Support multiformat bid request impression (prebid#2866) * Triplelift Bid Adapter: Adding GPP Support (prebid#2887) * YahooAdvertising rebranding to Yahoo Ads. (prebid#2872) Co-authored-by: oath-jac <[email protected]> * IX: MultiImp Implementation (prebid#2779) Co-authored-by: Chris Corbo <[email protected]> Co-authored-by: Oronno Mamun <[email protected]> * Exchange unit test fix (prebid#2868) * Semgrep rules for adapters (prebid#2833) * IX: Remove glog statement (prebid#2909) * Activities framework (prebid#2844) * PWBID: Update Default Endpoint (prebid#2903) * script to run semgrep tests against adapter PRs (prebid#2907) authored by @onkarvhanumante * semgrep rule to detect undesirable package imports in adapter code (prebid#2911) * update package-import message (prebid#2913) authored by @onkarvhanumante * Bump google.golang.org/grpc from 1.46.2 to 1.53.0 (prebid#2905) --------- Co-authored-by: Brian Sardo <[email protected]> Co-authored-by: Timothy Ace <[email protected]> Co-authored-by: Timothy M. Ace <[email protected]> Co-authored-by: balintvargha <[email protected]> Co-authored-by: Balint Vargha <[email protected]> Co-authored-by: Jason Piros <[email protected]> Co-authored-by: ccorbo <[email protected]> Co-authored-by: Chris Corbo <[email protected]> Co-authored-by: Ankush <[email protected]> Co-authored-by: Giovanni Sollazzo <[email protected]> Co-authored-by: AndreaC <[email protected]> Co-authored-by: Andrea Tumbarello <[email protected]> Co-authored-by: darkstar <[email protected]> Co-authored-by: Jozef Bartek <[email protected]> Co-authored-by: Max Dupuis <[email protected]> Co-authored-by: Patrick Loughrey <[email protected]> Co-authored-by: radubarbos <[email protected]> Co-authored-by: oath-jac <[email protected]> Co-authored-by: Oronno Mamun <[email protected]> Co-authored-by: Veronika Solovei <[email protected]> Co-authored-by: Onkar Hanumante <[email protected]> Co-authored-by: Stephen Johnston <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Hey, our gofmt job in our build pipeline started failing due to missing package keyword in some of these files. Is that intended? Shouldn't all go files have a package declaration? |
PR introduces semgrep rules for adapters code. These rules check whether,
typeBid
is assigned correctlyPR also adds unit tests for each semgrep rule. Note that semgrep looks for tests based on the rule filename and the languages specified in the rule. For example, we have rule for
no-content-status.yml
check. For this rule we have addedno-content-status.go
. This file includes patterns to be flagged by semgrep and patterns not to be flagged by semgrep.Note that this is initial step of integrating semgrep with adapter code reviews. As next step plan is to,
message
field in each semgrep rule is written using markup language used for Github comment.Run semgrep unit tests