semgrep.yml 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # Usage: semgrep scan -f semgrep.yml
  2. rules:
  3. - id: rule-0
  4. message: "http requests made without *fiber.Ctx"
  5. languages: [go]
  6. severity: WARNING
  7. patterns:
  8. - pattern-either:
  9. - pattern: |
  10. http.UnwrapWebAPIRequest(...)
  11. - pattern: |
  12. http.WebAPIRequest(...)
  13. - pattern-not-inside: |
  14. func $FUNC(c *fiber.Ctx, ...) $RET {
  15. ...
  16. }
  17. # note: the below two rules autofix have slight problems. where `http` is sometimes "net/http". need minor manual tweaking after --autofix.
  18. - id: rule-1-0
  19. message: "find http requests made to Pixiv"
  20. languages: [go]
  21. severity: INFO
  22. patterns:
  23. - pattern: |
  24. http.UnwrapWebAPIRequest($A, $B)
  25. fix: |
  26. http.UnwrapWebAPIRequest(c.Context(), $A, $B)
  27. - id: rule-1-1
  28. message: "find http requests made to Pixiv"
  29. languages: [go]
  30. severity: INFO
  31. patterns:
  32. - pattern: |
  33. http.WebAPIRequest($A, $B)
  34. fix: |
  35. http.WebAPIRequest(c.Context(), $A, $B)
  36. - id: rule-2
  37. message: "gjson.Get without gjson.Valid"
  38. languages: [go]
  39. severity: ERROR
  40. patterns:
  41. # - pattern-inside: |
  42. # func $FUNC(...) $RET {
  43. # ...
  44. # }
  45. - pattern: |
  46. gjson.Get($X, ...)
  47. - pattern-not-inside: |
  48. if !gjson.Valid($X) {
  49. $...DISCARD
  50. }
  51. ...
  52. - id: rule-3
  53. message: "http request without context"
  54. languages: [go]
  55. severity: WARNING
  56. # severity: INVENTORY
  57. patterns:
  58. - pattern-inside: |
  59. $REQ, $ERR := http.NewRequest($...ARGV)
  60. ...
  61. - pattern-not: |
  62. $REQ, $ERR := http.NewRequest($...ARGV)
  63. if $ERR != nil {
  64. ...
  65. }
  66. $REQ = $REQ.WithContext($CTX)
  67. ...
  68. fix: |
  69. $REQ, err := http.NewRequest($...ARGV)
  70. if err != nil {
  71. return err
  72. }
  73. $REQ = $REQ.WithContext(c.Context())
  74. - id: rule-4
  75. message: "fmt.Sprint on string"
  76. languages: [go]
  77. severity: WARNING
  78. pattern: |
  79. fmt.Sprint(($S : string))
  80. - id: rule-5
  81. message: "unhandled error"
  82. languages: [go]
  83. severity: WARNING
  84. pattern: |
  85. (_ : error) = ...
  86. - id: rule-6
  87. message: "raw UserArtCategory string"
  88. languages: [go]
  89. severity: WARNING
  90. pattern-either:
  91. - pattern: |
  92. ($A : UserArtCategory) == "$B"