problem-based-packs.insecure-transport.go-stdlib.grequests-http-request.grequests-http-request

profile photo of semgrepsemgrep
Author
6,272
Download Count*

Checks for requests to http (unencrypted) sites using grequests, a popular HTTP client library. This is dangerous because it could result in plaintext PII being passed around the network.

Run Locally

Run in CI

Defintion

rules:
  - id: grequests-http-request
    message: Checks for requests to http (unencrypted) sites using grequests, a
      popular HTTP client library. This is dangerous because it could result in
      plaintext PII being passed around the network.
    severity: WARNING
    metadata:
      likelihood: MEDIUM
      impact: MEDIUM
      confidence: MEDIUM
      category: security
      cwe: "CWE-319: Cleartext Transmission of Sensitive Information"
      owasp: A03:2017 - Sensitive Data Exposure
      references:
        - https://godoc.org/github.com/levigross/grequests#DoRegularRequest
        - https://github.com/levigross/grequests
      subcategory:
        - vuln
      technology:
        - grequests
      vulnerability: Insecure Transport
      license: Commons Clause License Condition v1.0[LGPL-2.1-only]
      vulnerability_class:
        - Mishandled Sensitive Information
    languages:
      - go
    patterns:
      - pattern-either:
          - pattern: |
              grequests.$FUNC(...,"=~/[hH][tT][tT][pP]://.*/", ...)
          - pattern: |
              $FUNC(...,"=~/[hH][tT][tT][pP]://.*/", ...)
      - metavariable-regex:
          metavariable: $FUNC
          regex: (Get|Head|Post|Put|Delete|Patch|Options|Req|DoRegularRequest)

Examples

grequests-http-request.go

func bad1() {
    // ruleid: grequests-http-request
    resp, err := grequests.Get("http://httpbin.org/get", nil)
    // You can modify the request by passing an optional RequestOptions struct

    if err != nil {
        log.Fatalln("Unable to make request: ", err)
    }

    fmt.Println(resp.String())
}

func bad2() {
    ro := &RequestOptions{
    Params: map[string]string{"Hello": "Goodbye"},
    }

    // ruleid: grequests-http-request
    Get("http://httpbin.org/get?Hello=World", ro)
}

func ok1() {
    // ok: grequests-http-request
    resp, err := grequests.Get("https://httpbin.org/get", nil)
    // You can modify the request by passing an optional RequestOptions struct

    if err != nil {
        log.Fatalln("Unable to make request: ", err)
    }

    fmt.Println(resp.String())
}

func ok2() {
    ro := &RequestOptions{
    Params: map[string]string{"Hello": "Goodbye"},
    }

    // ok: grequests-http-request
    Get("https://httpbin.org/get?Hello=World", ro)
}