Skip to content
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 rule to flag undesirable package imports in adapter code #2911

Merged
merged 1 commit into from
Jul 10, 2023

Conversation

onkarvhanumante
Copy link
Contributor

@onkarvhanumante onkarvhanumante commented Jul 7, 2023

Description

PR adds semgrep rule to flag undesirable package imports in adapter code. Plan here is to run this rule as adapter PR checks. Refer #2907 for more details.

Semgrep uses import metavariable to match package imports - https://semgrep.dev/docs/writing-rules/pattern-syntax/#import-metavariables

Testing

  • Sample playground example: https://semgrep.dev/playground/s/QBlo

  • Semgrep unit tests passing

     ~ » semgrep --test ./                              
    3/3: ✓ All tests passed
     No tests for fixes found.
    
  • Found following instances in repo

     ~ » semgrep --config=./.semgrep/adapter/package-import.yml ./adapters/
    
    
     ┌─────────────┐
     │ Scan Status │
     └─────────────┘
       Scanning 2539 files tracked by git with 1 Code rule:
       Scanning 194 files.
       ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00
    
    
     ┌─────────────────┐
     │ 5 Code Findings │
     └─────────────────┘
    
         adapters/adapterstest/test_json.go
            semgrep.adapter.package-import-check
               Importing "github.com/mitchellh/copystructure" package is not recommended in adapter code
    
                13┆ "github.com/mitchellh/copystructure"
    
         adapters/adhese/adhese.go
            semgrep.adapter.package-import-check
               Importing "github.com/golang/glog" package is not recommended in adapter code
    
                13┆ "github.com/golang/glog"
    
         adapters/gamoshi/gamoshi.go
            semgrep.adapter.package-import-check
               Importing "github.com/golang/glog" package is not recommended in adapter code
    
                 9┆ "github.com/golang/glog"
    
         adapters/pubmatic/pubmatic.go
            semgrep.adapter.package-import-check
               Importing "github.com/golang/glog" package is not recommended in adapter code
    
                13┆ "github.com/golang/glog"
    
         adapters/yeahmobi/yeahmobi.go
            semgrep.adapter.package-import-check
               Importing "github.com/golang/glog" package is not recommended in adapter code
    
                10┆ "github.com/golang/glog"
    
    
    
     ┌──────────────┐
     │ Scan Summary │
     └──────────────┘
     Some files were skipped or only partially analyzed.
       Scan was limited to files tracked by git.
       Scan skipped: 325 files matching .semgrepignore patterns
       For a full list of skipped files, run semgrep with the --verbose flag.
    
     Ran 1 rule on 194 files: 5 findings.
    

@onkarvhanumante onkarvhanumante changed the title Detect undesirable package imports in adapter code flag undesirable package imports in adapter code Jul 7, 2023
@onkarvhanumante onkarvhanumante changed the title flag undesirable package imports in adapter code semgrep rule to flag undesirable package imports in adapter code Jul 7, 2023
@@ -0,0 +1,13 @@
rules:
- id: package-import-check
message: Importing "$PKG" package is not recommended in adapter code
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use stronger wording. These packages are not allowed / banned. It's more than a recommendation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apologies. PR got merged. Added #2913 to make this change

@Sonali-More-Xandr Sonali-More-Xandr merged commit 613db40 into master Jul 10, 2023
Peiling-Ding pushed a commit to ParticleMedia/prebid-server that referenced this pull request Jul 14, 2023
Peiling-Ding added a commit to ParticleMedia/prebid-server that referenced this pull request Jul 14, 2023
* 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 <tace@imds.tv>

* Adsinteractive: change usersync endpoint to https (prebid#2861)


Co-authored-by: Balint Vargha <varghabalint@gmail.com>

* consumable adapter: add gpp support (prebid#2883)

* feat: IX Bid Adapter - gpp support for user sync urls (prebid#2873)

Co-authored-by: Chris Corbo <chris.corbo@indexexchange.com>

* fix: update links in readme (prebid#2888)

authored by @akkapur

* New Adapter: AIDEM (prebid#2824)


Co-authored-by: AndreaC <67786179+darkstarac@users.noreply.github.com>
Co-authored-by: Andrea Tumbarello <Wazabit@users.noreply.github.com>
Co-authored-by: darkstar <canazza@wazabit.it>

* 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 <dsp-supply-prebid@verizonmedia.com>

* IX: MultiImp Implementation (prebid#2779)


Co-authored-by: Chris Corbo <chris.corbo@indexexchange.com>
Co-authored-by: Oronno Mamun <oronno.mamun@indexexchange.com>

* 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 <1168933+bsardo@users.noreply.github.com>
Co-authored-by: Timothy Ace <github.com-1@timothyace.com>
Co-authored-by: Timothy M. Ace <tace@imds.tv>
Co-authored-by: balintvargha <122350182+balintvargha@users.noreply.github.com>
Co-authored-by: Balint Vargha <varghabalint@gmail.com>
Co-authored-by: Jason Piros <jasonpiros@gmail.com>
Co-authored-by: ccorbo <ccorbo2013@gmail.com>
Co-authored-by: Chris Corbo <chris.corbo@indexexchange.com>
Co-authored-by: Ankush <ankush.kapur@gmail.com>
Co-authored-by: Giovanni Sollazzo <gs@aidem.com>
Co-authored-by: AndreaC <67786179+darkstarac@users.noreply.github.com>
Co-authored-by: Andrea Tumbarello <Wazabit@users.noreply.github.com>
Co-authored-by: darkstar <canazza@wazabit.it>
Co-authored-by: Jozef Bartek <31618107+jbartek25@users.noreply.github.com>
Co-authored-by: Max Dupuis <118775839+maxime-dupuis@users.noreply.github.com>
Co-authored-by: Patrick Loughrey <ploughrey@triplelift.com>
Co-authored-by: radubarbos <raduiquest79@gmail.com>
Co-authored-by: oath-jac <dsp-supply-prebid@verizonmedia.com>
Co-authored-by: Oronno Mamun <oronno.mamun@indexexchange.com>
Co-authored-by: Veronika Solovei <kalypsonika@gmail.com>
Co-authored-by: Onkar Hanumante <onkar.hanumante@xandr.com>
Co-authored-by: Stephen Johnston <tiquortoo@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@onkarvhanumante onkarvhanumante deleted the semgrepPRs/adapter-pkg-import branch August 1, 2023 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants