From 780e74974f16a5220a5776969fcf7ca7897d29ae Mon Sep 17 00:00:00 2001 From: Aman Ullah Date: Mon, 27 Apr 2026 17:37:13 +0500 Subject: [PATCH 1/4] enable errcheck and staticcheck for golangci-lint v2 and resolve all issues --- .github/workflows/lint.yml | 2 +- hack/checksecretparts/main.go | 6 +- hack/snifftest/main.go | 2 +- main.go | 4 +- pkg/analyzer/analyzers/airbrake/airbrake.go | 7 +-- .../airtable/airtablepat/airtable.go | 4 +- .../airtable/airtablepat/requests.go | 4 +- .../analyzers/airtable/common/common.go | 6 +- pkg/analyzer/analyzers/analyzers.go | 2 +- pkg/analyzer/analyzers/asana/asana.go | 6 +- pkg/analyzer/analyzers/bitbucket/bitbucket.go | 4 +- pkg/analyzer/analyzers/client.go | 2 +- pkg/analyzer/analyzers/datadog/requests.go | 2 +- .../analyzers/digitalocean/digitalocean.go | 10 ++- .../analyzers/elevenlabs/elevenlabs.go | 11 ++-- pkg/analyzer/analyzers/figma/figma.go | 2 +- .../github/finegrained/finegrained.go | 6 +- pkg/analyzer/analyzers/gitlab/gitlab.go | 12 ++-- .../analyzers/huggingface/huggingface.go | 32 +++++----- pkg/analyzer/analyzers/jira/requests.go | 9 ++- pkg/analyzer/analyzers/mailchimp/mailchimp.go | 6 +- pkg/analyzer/analyzers/mailgun/requests.go | 4 +- pkg/analyzer/analyzers/mux/models.go | 5 +- pkg/analyzer/analyzers/mysql/mysql.go | 12 ++-- pkg/analyzer/analyzers/notion/notion.go | 12 ++-- pkg/analyzer/analyzers/openai/openai.go | 5 +- pkg/analyzer/analyzers/opsgenie/opsgenie.go | 10 ++- pkg/analyzer/analyzers/plaid/plaid.go | 2 +- .../analyzers/planetscale/planetscale.go | 4 +- pkg/analyzer/analyzers/postgres/postgres.go | 16 ++--- pkg/analyzer/analyzers/posthog/posthog.go | 14 ++--- pkg/analyzer/analyzers/postman/postman.go | 12 ++-- pkg/analyzer/analyzers/shopify/shopify.go | 4 +- pkg/analyzer/analyzers/slack/slack.go | 2 +- .../analyzers/sourcegraph/sourcegraph.go | 10 ++- pkg/analyzer/analyzers/square/square.go | 4 +- pkg/analyzer/analyzers/stripe/stripe.go | 16 ++--- pkg/analyzer/analyzers/twilio/twilio.go | 16 ++--- .../generate_permissions.go | 4 +- pkg/buffers/buffer/buffer.go | 4 +- pkg/cleantemp/cleantemp.go | 2 +- pkg/common/filter_test.go | 4 +- pkg/common/http_test.go | 6 +- pkg/common/secrets.go | 2 +- pkg/decoders/html_test.go | 34 +++++----- pkg/detectors/abstract/abstract.go | 5 +- pkg/detectors/abuseipdb/abuseipdb.go | 2 +- pkg/detectors/abyssale/abyssale.go | 2 +- pkg/detectors/accuweather/v1/accuweather.go | 2 +- pkg/detectors/adafruitio/adafruitio.go | 2 +- pkg/detectors/adzuna/adzuna.go | 2 +- pkg/detectors/aeroworkflow/aeroworkflow.go | 2 +- pkg/detectors/agora/agora.go | 2 +- pkg/detectors/aha/aha.go | 2 +- pkg/detectors/alibaba/alibaba.go | 8 +-- pkg/detectors/anthropic/anthropic.go | 2 +- pkg/detectors/apacta/apacta_test.go | 4 +- pkg/detectors/appoptics/appoptics.go | 5 +- pkg/detectors/audd/audd.go | 2 +- pkg/detectors/autodesk/autodesk.go | 2 +- pkg/detectors/autopilot/autopilot.go | 5 +- pkg/detectors/aws/session_keys/sessionkey.go | 2 +- pkg/detectors/azure_batch/azurebatch.go | 2 +- .../repositorykey/repositorykey.go | 6 +- .../azureapimanagementsubscriptionkey.go | 6 +- .../azureappconfigconnectionstring.go | 2 +- .../azurecontainerregistry.go | 6 +- .../azuredevopspersonalaccesstoken.go | 2 +- .../azuredirectmanagementkey.go | 6 +- .../azurefunctionkey/azurefunctionkey.go | 2 +- pkg/detectors/azuresastoken/azuresastoken.go | 8 +-- .../azuresearchadminkey.go | 2 +- .../azuresearchquerykey.go | 2 +- .../bannerbear/v1/bannerbear_test.go | 4 +- .../bannerbear/v2/bannerbear_test.go | 4 +- pkg/detectors/baremetrics/baremetrics_test.go | 4 +- pkg/detectors/beamer/beamer_test.go | 4 +- pkg/detectors/beebole/beebole_test.go | 4 +- pkg/detectors/besnappy/besnappy_test.go | 4 +- pkg/detectors/besttime/besttime_test.go | 4 +- pkg/detectors/betterstack/betterstack_test.go | 4 +- pkg/detectors/billomat/billomat_test.go | 2 +- .../bingsubscriptionkey_test.go | 4 +- pkg/detectors/bitbar/bitbar_test.go | 4 +- .../bitcoinaverage/bitcoinaverage_test.go | 4 +- .../bitlyaccesstoken/bitlyaccesstoken_test.go | 4 +- pkg/detectors/bitmex/bitmex_test.go | 4 +- pkg/detectors/blazemeter/blazemeter_test.go | 4 +- pkg/detectors/blitapp/blitapp_test.go | 4 +- pkg/detectors/blocknative/blocknative_test.go | 4 +- pkg/detectors/blogger/blogger_test.go | 4 +- pkg/detectors/boostnote/boostnote_test.go | 4 +- pkg/detectors/borgbase/borgbase_test.go | 4 +- .../braintreepayments/braintreepayments.go | 2 +- .../braintreepayments_test.go | 4 +- .../brandfetch/v1/brandfetch_test.go | 4 +- pkg/detectors/brandfetch/v2/brandfetch.go | 2 +- .../brandfetch/v2/brandfetch_test.go | 4 +- pkg/detectors/browserstack/browserstack.go | 2 +- .../browserstack/browserstack_test.go | 4 +- pkg/detectors/browshot/browshot_test.go | 4 +- pkg/detectors/bscscan/bscscan_test.go | 4 +- pkg/detectors/buddyns/buddyns_test.go | 4 +- pkg/detectors/budibase/budibase_test.go | 4 +- pkg/detectors/bugherd/bugherd_test.go | 4 +- pkg/detectors/bugsnag/bugsnag_test.go | 4 +- pkg/detectors/buildkite/v1/buildkite_test.go | 4 +- pkg/detectors/buildkite/v2/buildkite_test.go | 4 +- pkg/detectors/bulbul/bulbul_test.go | 4 +- pkg/detectors/bulksms/bulksms_test.go | 4 +- pkg/detectors/buttercms/buttercms_test.go | 4 +- pkg/detectors/calendarific/calendarific.go | 2 +- .../calendlyapikey/calendlyapikey.go | 2 +- pkg/detectors/calorieninja/calorieninja.go | 2 +- pkg/detectors/campayn/campayn.go | 2 +- pkg/detectors/cannyio/cannyio.go | 2 +- pkg/detectors/capsulecrm/capsulecrm.go | 2 +- pkg/detectors/captaindata/v1/captaindata.go | 2 +- .../carboninterface/carboninterface.go | 2 +- pkg/detectors/cashboard/cashboard.go | 2 +- pkg/detectors/caspio/caspio.go | 2 +- pkg/detectors/censys/censys.go | 2 +- .../centralstationcrm/centralstationcrm.go | 2 +- pkg/detectors/cexio/cexio.go | 2 +- pkg/detectors/chartmogul/chartmogul.go | 2 +- pkg/detectors/chatbot/chatbot.go | 2 +- pkg/detectors/chatfule/chatfule.go | 2 +- pkg/detectors/checio/checio.go | 2 +- pkg/detectors/checklyhq/checklyhq.go | 2 +- pkg/detectors/checkout/checkout.go | 2 +- pkg/detectors/checkvist/checkvist.go | 2 +- pkg/detectors/cicero/cicero.go | 2 +- pkg/detectors/clarifai/clarifai.go | 4 +- pkg/detectors/clearbit/clearbit.go | 2 +- pkg/detectors/clicksendsms/clicksendsms.go | 2 +- pkg/detectors/cliengo/cliengo.go | 2 +- pkg/detectors/clinchpad/clinchpad.go | 2 +- pkg/detectors/clockify/clockify.go | 2 +- pkg/detectors/clockworksms/clockworksms.go | 2 +- pkg/detectors/closecrm/close.go | 2 +- pkg/detectors/cloudconvert/cloudconvert.go | 2 +- pkg/detectors/cloudelements/cloudelements.go | 2 +- .../cloudflareapitoken/cloudflareapitoken.go | 2 +- .../cloudflareglobalapikey.go | 2 +- pkg/detectors/cloudimage/cloudimage.go | 2 +- pkg/detectors/cloudmersive/cloudmersive.go | 2 +- pkg/detectors/cloudplan/cloudplan.go | 2 +- pkg/detectors/cloudsmith/cloudsmith.go | 2 +- pkg/detectors/cloverly/cloverly.go | 2 +- pkg/detectors/cloze/cloze.go | 2 +- pkg/detectors/clustdoc/clustdoc.go | 2 +- pkg/detectors/coda/coda.go | 2 +- pkg/detectors/codacy/codacy.go | 2 +- pkg/detectors/codeclimate/codeclimate.go | 2 +- pkg/detectors/codemagic/codemagic.go | 2 +- pkg/detectors/codequiry/codequiry.go | 2 +- pkg/detectors/coinapi/coinapi.go | 2 +- pkg/detectors/coinlayer/coinlayer.go | 2 +- pkg/detectors/coinlib/coinlib.go | 2 +- pkg/detectors/collect2/collect2.go | 2 +- pkg/detectors/column/column.go | 2 +- pkg/detectors/commercejs/commercejs.go | 2 +- pkg/detectors/commodities/commodities.go | 2 +- pkg/detectors/companyhub/companyhub.go | 2 +- pkg/detectors/confluent/confluent.go | 2 +- .../contentfulpersonalaccesstoken.go | 2 +- .../conversiontools/conversiontools.go | 2 +- pkg/detectors/convertapi/convertapi.go | 2 +- pkg/detectors/convertkit/convertkit.go | 2 +- pkg/detectors/convier/convier.go | 2 +- pkg/detectors/countrylayer/countrylayer.go | 2 +- pkg/detectors/courier/courier.go | 2 +- pkg/detectors/coveralls/coveralls.go | 2 +- pkg/detectors/craftmypdf/craftmypdf.go | 2 +- pkg/detectors/crowdin/crowdin.go | 2 +- pkg/detectors/cryptocompare/cryptocompare.go | 2 +- pkg/detectors/currencycloud/currencycloud.go | 2 +- .../currencyfreaks/currencyfreaks.go | 2 +- pkg/detectors/currencylayer/currencylayer.go | 2 +- pkg/detectors/currencyscoop/currencyscoop.go | 2 +- pkg/detectors/customerguru/customerguru.go | 2 +- pkg/detectors/customerio/customerio.go | 2 +- pkg/detectors/d7network/d7network.go | 2 +- pkg/detectors/dailyco/dailyco.go | 2 +- pkg/detectors/dandelion/dandelion.go | 2 +- pkg/detectors/dareboost/dareboost.go | 2 +- pkg/detectors/databox/databox.go | 2 +- pkg/detectors/datadogtoken/datadogtoken.go | 2 +- pkg/detectors/datagov/datagov.go | 2 +- pkg/detectors/debounce/debounce.go | 2 +- pkg/detectors/deepai/deepai.go | 4 +- pkg/detectors/deepgram/deepgram.go | 2 +- pkg/detectors/delighted/delighted.go | 2 +- pkg/detectors/demio/demio.go | 2 +- pkg/detectors/deno/denodeploy.go | 9 +-- pkg/detectors/deputy/deputy.go | 2 +- pkg/detectors/detectify/detectify.go | 2 +- .../detectlanguage/detectlanguage.go | 2 +- pkg/detectors/dfuse/dfuse.go | 2 +- pkg/detectors/diffbot/diffbot.go | 2 +- pkg/detectors/diggernaut/diggernaut.go | 2 +- .../digitaloceantoken/digitaloceantoken.go | 2 +- .../digitaloceanv2/digitaloceanv2.go | 24 +++---- .../discordbottoken/discordbottoken.go | 2 +- .../discordwebhook/discordwebhook.go | 2 +- pkg/detectors/disqus/disqus.go | 2 +- pkg/detectors/ditto/ditto.go | 2 +- pkg/detectors/dnscheck/dnscheck.go | 2 +- pkg/detectors/dockerhub/v1/dockerhub.go | 9 +-- pkg/detectors/dockerhub/v2/dockerhub.go | 9 +-- pkg/detectors/docparser/docparser.go | 2 +- pkg/detectors/documo/documo.go | 2 +- pkg/detectors/docusign/docusign.go | 2 +- pkg/detectors/doppler/doppler.go | 2 +- pkg/detectors/dronahq/dronahq.go | 2 +- pkg/detectors/droneci/droneci.go | 2 +- pkg/detectors/duply/duply.go | 2 +- pkg/detectors/dynalist/dynalist.go | 2 +- pkg/detectors/dyspatch/dyspatch.go | 2 +- .../eagleeyenetworks/eagleeyenetworks.go | 2 +- pkg/detectors/ecostruxureit/ecostruxureit.go | 2 +- pkg/detectors/edamam/edamam.go | 2 +- pkg/detectors/edenai/edenai.go | 2 +- pkg/detectors/eightxeight/eightxeight.go | 2 +- pkg/detectors/elasticemail/elasticemail.go | 2 +- pkg/detectors/enablex/enablex.go | 2 +- pkg/detectors/enigma/enigma.go | 2 +- pkg/detectors/envoyapikey/envoyapikey.go | 2 +- pkg/detectors/etherscan/etherscan.go | 2 +- pkg/detectors/ethplorer/ethplorer.go | 2 +- pkg/detectors/everhour/everhour.go | 2 +- .../exchangeratesapi/exchangeratesapi.go | 2 +- pkg/detectors/exportsdk/exportsdk.go | 2 +- pkg/detectors/extractorapi/extractorapi.go | 2 +- pkg/detectors/facebookoauth/facebookoauth.go | 2 +- pkg/detectors/faceplusplus/faceplusplus.go | 2 +- pkg/detectors/fastforex/fastforex.go | 2 +- pkg/detectors/feedier/feedier.go | 2 +- .../v1/figmapersonalaccesstoken.go | 2 +- .../v2/figmapersonalaccesstoken_v2.go | 2 +- pkg/detectors/fileio/fileio.go | 2 +- pkg/detectors/finage/finage.go | 2 +- .../financialmodelingprep.go | 2 +- pkg/detectors/findl/findl.go | 2 +- pkg/detectors/finnhub/finnhub.go | 2 +- pkg/detectors/fixerio/fixerio.go | 4 +- pkg/detectors/flatio/flatio.go | 2 +- pkg/detectors/fleetbase/fleetbase.go | 2 +- pkg/detectors/flickr/flickr.go | 2 +- pkg/detectors/flightapi/flightapi.go | 2 +- pkg/detectors/flightstats/flightstats.go | 2 +- pkg/detectors/float/float.go | 2 +- pkg/detectors/flowflu/flowflu.go | 2 +- pkg/detectors/flutterwave/flutterwave.go | 2 +- pkg/detectors/fmfw/fmfw.go | 2 +- pkg/detectors/formbucket/formbucket.go | 4 +- pkg/detectors/formcraft/formcraft.go | 2 +- pkg/detectors/formio/formio.go | 2 +- pkg/detectors/formsite/formsite.go | 2 +- pkg/detectors/foursquare/foursquare.go | 2 +- pkg/detectors/frameio/frameio.go | 2 +- pkg/detectors/freshbooks/freshbooks.go | 2 +- pkg/detectors/freshdesk/freshdesk.go | 2 +- pkg/detectors/front/front.go | 2 +- pkg/detectors/ftp/ftp.go | 4 +- pkg/detectors/fulcrum/fulcrum.go | 2 +- pkg/detectors/fullstory/v1/fullstory.go | 2 +- pkg/detectors/fullstory/v2/fullstory_v2.go | 2 +- pkg/detectors/fxmarket/fxmarket.go | 2 +- pkg/detectors/gcp/gcp.go | 4 +- pkg/detectors/geckoboard/geckoboard.go | 2 +- pkg/detectors/gemini/gemini.go | 2 +- pkg/detectors/gengo/gengo.go | 2 +- pkg/detectors/geoapify/geoapify.go | 2 +- pkg/detectors/geocode/geocode.go | 2 +- pkg/detectors/geocodify/geocodify.go | 2 +- pkg/detectors/geocodio/geocodio.go | 2 +- pkg/detectors/geoipifi/geoipifi.go | 2 +- pkg/detectors/getemail/getemail.go | 2 +- pkg/detectors/getemails/getemails.go | 2 +- pkg/detectors/getgeoapi/getgeoapi.go | 2 +- pkg/detectors/getgist/getgist.go | 2 +- pkg/detectors/getresponse/getresponse.go | 2 +- pkg/detectors/getsandbox/getsandbox.go | 2 +- pkg/detectors/github/v1/github_old.go | 2 +- pkg/detectors/githubapp/githubapp.go | 2 +- pkg/detectors/gitlab/v1/gitlab.go | 2 +- pkg/detectors/gitter/gitter.go | 2 +- pkg/detectors/glassnode/glassnode.go | 2 +- pkg/detectors/gocanvas/gocanvas.go | 2 +- pkg/detectors/gocardless/gocardless.go | 2 +- pkg/detectors/goodday/goodday.go | 2 +- .../googleoauth2/googleoauth2_access_token.go | 7 ++- .../grafanaserviceaccount.go | 2 +- pkg/detectors/graphcms/graphcms.go | 2 +- pkg/detectors/graphhopper/graphhopper.go | 2 +- pkg/detectors/groovehq/groovehq.go | 2 +- pkg/detectors/gtmetrix/gtmetrix.go | 2 +- pkg/detectors/guardianapi/guardianapi.go | 2 +- pkg/detectors/gumroad/gumroad.go | 2 +- pkg/detectors/guru/guru.go | 2 +- pkg/detectors/gyazo/gyazo.go | 2 +- pkg/detectors/happyscribe/happyscribe.go | 2 +- pkg/detectors/harvest/harvest.go | 2 +- pkg/detectors/hellosign/hellosign.go | 2 +- pkg/detectors/helpcrunch/helpcrunch.go | 2 +- pkg/detectors/helpscout/helpscout.go | 2 +- pkg/detectors/hereapi/hereapi.go | 2 +- pkg/detectors/hive/hive.go | 2 +- pkg/detectors/hiveage/hiveage.go | 2 +- pkg/detectors/holidayapi/holidayapi.go | 2 +- pkg/detectors/holistic/holistic.go | 2 +- pkg/detectors/honeycomb/honeycomb.go | 2 +- pkg/detectors/host/host.go | 2 +- pkg/detectors/html2pdf/html2pdf.go | 2 +- pkg/detectors/http_test.go | 4 +- pkg/detectors/huggingface/huggingface.go | 2 +- pkg/detectors/humanity/humanity.go | 2 +- pkg/detectors/hunter/hunter.go | 2 +- pkg/detectors/hybiscus/hybiscus.go | 2 +- pkg/detectors/hypertrack/hypertrack.go | 2 +- .../ibmclouduserkey/ibmclouduserkey.go | 2 +- pkg/detectors/iconfinder/iconfinder.go | 5 +- pkg/detectors/iexapis/iexapis.go | 5 +- pkg/detectors/iexcloud/iexcloud.go | 5 +- pkg/detectors/imagekit/imagekit.go | 5 +- pkg/detectors/imagga/imagga.go | 5 +- pkg/detectors/impala/impala.go | 5 +- pkg/detectors/infura/infura.go | 5 +- pkg/detectors/insightly/insightly.go | 5 +- pkg/detectors/instabot/instabot.go | 5 +- pkg/detectors/instamojo/instamojo.go | 2 +- pkg/detectors/intercom/intercom.go | 5 +- pkg/detectors/interseller/interseller.go | 2 +- pkg/detectors/intra42/intra42.go | 2 +- pkg/detectors/intrinio/intrinio.go | 5 +- pkg/detectors/invoiceocean/invoiceocean.go | 2 +- pkg/detectors/ip2location/ip2location.go | 2 +- pkg/detectors/ipapi/ipapi.go | 5 +- pkg/detectors/ipgeolocation/ipgeolocation.go | 5 +- pkg/detectors/ipinfo/ipinfo.go | 2 +- pkg/detectors/ipinfodb/ipinfodb.go | 2 +- pkg/detectors/ipstack/ipstack.go | 5 +- pkg/detectors/jdbc/jdbc.go | 2 +- pkg/detectors/jotform/jotform.go | 5 +- pkg/detectors/jumpcloud/jumpcloud.go | 5 +- pkg/detectors/jupiterone/jupiterone.go | 9 +-- pkg/detectors/juro/juro.go | 5 +- pkg/detectors/jwt/jwt.go | 4 +- pkg/detectors/kanban/kanban.go | 2 +- pkg/detectors/kanbantool/kanbantool.go | 2 +- pkg/detectors/karmacrm/karmacrm.go | 5 +- pkg/detectors/keenio/keenio.go | 5 +- pkg/detectors/kickbox/kickbox.go | 5 +- pkg/detectors/klaviyo/klaviyo.go | 5 +- pkg/detectors/klipfolio/klipfolio.go | 5 +- pkg/detectors/knapsackpro/knapsackpro.go | 5 +- pkg/detectors/kraken/kraken.go | 2 +- pkg/detectors/kucoin/kucoin.go | 5 +- pkg/detectors/kylas/kylas.go | 5 +- pkg/detectors/languagelayer/languagelayer.go | 5 +- .../larksuiteapikey/larksuiteapikey.go | 2 +- pkg/detectors/leadfeeder/leadfeeder.go | 5 +- pkg/detectors/lemlist/lemlist.go | 5 +- pkg/detectors/lemonsqueezy/lemonsqueezy.go | 2 +- pkg/detectors/lendflow/lendflow.go | 2 +- .../lessannoyingcrm/lessannoyingcrm.go | 2 +- pkg/detectors/lexigram/lexigram.go | 5 +- pkg/detectors/linearapi/linearapi.go | 5 +- pkg/detectors/linemessaging/linemessaging.go | 5 +- pkg/detectors/linenotify/linenotify.go | 5 +- pkg/detectors/linkpreview/linkpreview.go | 5 +- pkg/detectors/liveagent/liveagent.go | 2 +- pkg/detectors/livestorm/livestorm.go | 5 +- pkg/detectors/loadmill/loadmill.go | 5 +- pkg/detectors/lob/lob.go | 5 +- pkg/detectors/locationiq/locationiq.go | 5 +- pkg/detectors/loggly/loggly.go | 2 +- pkg/detectors/loginradius/loginradius.go | 2 +- pkg/detectors/logzio/logzio.go | 5 +- pkg/detectors/loyverse/loyverse.go | 5 +- pkg/detectors/lunchmoney/lunchmoney.go | 5 +- pkg/detectors/luno/luno.go | 5 +- pkg/detectors/m3o/m3o.go | 5 +- pkg/detectors/madkudu/madkudu.go | 5 +- pkg/detectors/magicbell/magicbell.go | 2 +- pkg/detectors/magnetic/magnetic.go | 5 +- pkg/detectors/mailboxlayer/mailboxlayer.go | 2 +- pkg/detectors/mailchimp/mailchimp.go | 2 +- pkg/detectors/mailerlite/mailerlite.go | 5 +- pkg/detectors/mailgun/mailgun.go | 7 ++- .../mailjetbasicauth/mailjetbasicauth.go | 2 +- pkg/detectors/mailjetsms/mailjetsms.go | 5 +- pkg/detectors/mailmodo/mailmodo.go | 2 +- pkg/detectors/mailsac/mailsac.go | 5 +- pkg/detectors/mandrill/mandrill.go | 5 +- pkg/detectors/manifest/manifest.go | 5 +- pkg/detectors/mapbox/mapbox.go | 2 +- pkg/detectors/mapquest/mapquest.go | 5 +- pkg/detectors/marketstack/marketstack.go | 5 +- .../mattermostpersonaltoken.go | 2 +- pkg/detectors/mavenlink/mavenlink.go | 5 +- .../maxmindlicense/v1/maxmindlicense.go | 2 +- pkg/detectors/meaningcloud/meaningcloud.go | 7 ++- pkg/detectors/mediastack/mediastack.go | 5 +- pkg/detectors/meistertask/meistertask.go | 5 +- pkg/detectors/mesibo/mesibo.go | 2 +- pkg/detectors/messagebird/messagebird.go | 5 +- pkg/detectors/metaapi/metaapi.go | 5 +- pkg/detectors/metabase/metabase.go | 2 +- pkg/detectors/metrilo/metrilo.go | 5 +- .../microsoftteamswebhook.go | 2 +- pkg/detectors/mindmeister/mindmeister.go | 5 +- pkg/detectors/miro/miro.go | 5 +- pkg/detectors/mite/mite.go | 2 +- pkg/detectors/mixmax/mixmax.go | 5 +- pkg/detectors/mixpanel/mixpanel.go | 5 +- pkg/detectors/mockaroo/mockaroo.go | 2 +- pkg/detectors/moderation/moderation.go | 2 +- pkg/detectors/mongodb/mongodb.go | 2 +- pkg/detectors/monkeylearn/monkeylearn.go | 5 +- pkg/detectors/moonclerk/moonclerk.go | 5 +- pkg/detectors/moosend/moosend.go | 5 +- pkg/detectors/moralis/moralis.go | 5 +- pkg/detectors/mrticktock/mrticktock.go | 2 +- pkg/detectors/mux/mux.go | 2 +- pkg/detectors/myfreshworks/myfreshworks.go | 7 ++- pkg/detectors/myintervals/myintervals.go | 5 +- .../nasdaqdatalink/nasdaqdatalink.go | 5 +- pkg/detectors/nethunt/nethunt.go | 5 +- pkg/detectors/netsuite/netsuite.go | 4 +- pkg/detectors/neutrinoapi/neutrinoapi.go | 7 ++- .../newrelicpersonalapikey.go | 4 +- pkg/detectors/newsapi/newsapi.go | 5 +- pkg/detectors/newscatcher/newscatcher.go | 5 +- pkg/detectors/nexmoapikey/nexmoapikey.go | 5 +- pkg/detectors/nftport/nftport.go | 5 +- pkg/detectors/ngc/ngc.go | 5 +- pkg/detectors/nicereply/nicereply.go | 5 +- pkg/detectors/nightfall/nightfall.go | 5 +- pkg/detectors/nimble/nimble.go | 5 +- pkg/detectors/noticeable/noticeable.go | 5 +- pkg/detectors/notion/notion.go | 2 +- pkg/detectors/nozbeteams/nozbeteams.go | 2 +- pkg/detectors/npmtoken/npmtoken.go | 2 +- pkg/detectors/npmtokenv2/npmtokenv2.go | 2 +- pkg/detectors/nugetapikey/nugetapikey.go | 5 +- pkg/detectors/numverify/numverify.go | 5 +- pkg/detectors/nutritionix/nutritionix.go | 5 +- pkg/detectors/nylas/nylas.go | 5 +- pkg/detectors/oanda/oanda.go | 5 +- pkg/detectors/okta/okta.go | 2 +- pkg/detectors/omnisend/omnisend.go | 5 +- pkg/detectors/onedesk/onedesk.go | 2 +- pkg/detectors/onelogin/onelogin.go | 5 +- pkg/detectors/onepagecrm/onepagecrm.go | 5 +- pkg/detectors/onesignal/onesignal.go | 5 +- pkg/detectors/oopspam/oopspam.go | 5 +- pkg/detectors/opencagedata/opencagedata.go | 5 +- pkg/detectors/openuv/openuv.go | 5 +- pkg/detectors/openvpn/openvpn.go | 2 +- pkg/detectors/openweather/openweather.go | 5 +- pkg/detectors/optimizely/optimizely.go | 5 +- pkg/detectors/overloop/overloop.go | 2 +- pkg/detectors/owlbot/owlbot.go | 5 +- pkg/detectors/packagecloud/packagecloud.go | 5 +- .../pagerdutyapikey/pagerdutyapikey.go | 2 +- pkg/detectors/pandadoc/pandadoc.go | 5 +- pkg/detectors/pandascore/pandascore.go | 5 +- pkg/detectors/paperform/paperform.go | 5 +- pkg/detectors/paralleldots/paralleldots.go | 7 ++- pkg/detectors/parsehub/parsehub.go | 5 +- pkg/detectors/parsers/parsers.go | 5 +- pkg/detectors/parseur/parseur.go | 2 +- pkg/detectors/partnerstack/partnerstack.go | 5 +- pkg/detectors/pastebin/pastebin.go | 7 ++- pkg/detectors/paydirtapp/paydirtapp.go | 5 +- pkg/detectors/paymoapp/paymoapp.go | 5 +- pkg/detectors/paymongo/paymongo.go | 2 +- pkg/detectors/paypaloauth/paypaloauth.go | 5 +- pkg/detectors/paystack/paystack.go | 5 +- pkg/detectors/pdflayer/pdflayer.go | 5 +- pkg/detectors/pdfshift/pdfshift.go | 5 +- .../peopledatalabs/peopledatalabs.go | 5 +- pkg/detectors/pepipost/pepipost.go | 5 +- pkg/detectors/percy/percy.go | 5 +- pkg/detectors/pinata/pinata.go | 5 +- pkg/detectors/pipedream/pipedream.go | 5 +- pkg/detectors/pipedrive/pipedrive.go | 5 +- .../pivotaltracker/pivotaltracker.go | 5 +- pkg/detectors/pixabay/pixabay.go | 5 +- pkg/detectors/plaidkey/plaidkey.go | 2 +- pkg/detectors/planetscale/planetscale.go | 2 +- pkg/detectors/planetscaledb/planetscaledb.go | 2 +- .../planviewleankit/planviewleankit.go | 2 +- pkg/detectors/planyo/planyo.go | 2 +- pkg/detectors/plivo/plivo.go | 5 +- pkg/detectors/podio/podio.go | 5 +- pkg/detectors/pollsapi/pollsapi.go | 2 +- pkg/detectors/poloniex/poloniex.go | 5 +- pkg/detectors/polygon/polygon.go | 5 +- pkg/detectors/portainer/portainer.go | 2 +- .../portainertoken/portainertoken.go | 2 +- pkg/detectors/positionstack/positionstack.go | 5 +- pkg/detectors/postageapp/postageapp.go | 5 +- pkg/detectors/postbacks/postbacks.go | 5 +- pkg/detectors/postgres/postgres.go | 2 +- pkg/detectors/posthog/posthog.go | 4 +- pkg/detectors/postman/postman.go | 2 +- pkg/detectors/powrbot/powrbot.go | 5 +- pkg/detectors/prefect/prefect.go | 5 +- pkg/detectors/privacy/privacy.go | 2 +- pkg/detectors/privatekey/privatekey.go | 2 +- pkg/detectors/privatekey/ssh_integration.go | 6 +- pkg/detectors/prodpad/prodpad.go | 5 +- pkg/detectors/prospectcrm/prospectcrm.go | 2 +- pkg/detectors/protocolsio/protocolsio.go | 5 +- pkg/detectors/proxycrawl/proxycrawl.go | 5 +- .../pubnubpublishkey/pubnubpublishkey.go | 4 +- pkg/detectors/pulumi/pulumi.go | 5 +- pkg/detectors/purestake/purestake.go | 5 +- .../pushbulletapikey/pushbulletapikey.go | 2 +- pkg/detectors/pypi/pypi.go | 7 ++- pkg/detectors/rabbitmq/rabbitmq.go | 2 +- pkg/detectors/railwayapp/railwayapp.go | 2 +- pkg/detectors/ramp/ramp.go | 2 +- pkg/detectors/rapidapi/rapidapi.go | 5 +- pkg/detectors/raven/raven.go | 5 +- pkg/detectors/rawg/rawg.go | 5 +- pkg/detectors/razorpay/razorpay.go | 2 +- pkg/detectors/reachmail/reachmail.go | 5 +- pkg/detectors/readme/readme.go | 5 +- .../reallysimplesystems.go | 2 +- pkg/detectors/rebrandly/rebrandly.go | 5 +- .../rechargepayments/rechargepayments.go | 5 +- pkg/detectors/redis/redis.go | 4 +- pkg/detectors/refiner/refiner.go | 5 +- pkg/detectors/rentman/rentman.go | 5 +- pkg/detectors/repairshopr/repairshopr.go | 2 +- pkg/detectors/replicate/replicate.go | 5 +- pkg/detectors/replyio/replyio.go | 5 +- .../requestfinance/requestfinance.go | 2 +- .../restpackhtmltopdfapi.go | 2 +- .../restpackscreenshotapi.go | 2 +- pkg/detectors/rev/rev.go | 2 +- pkg/detectors/revampcrm/revampcrm.go | 5 +- pkg/detectors/ringcentral/ringcentral.go | 2 +- pkg/detectors/ritekit/ritekit.go | 5 +- pkg/detectors/roaring/roaring.go | 5 +- pkg/detectors/rocketreach/rocketreach.go | 5 +- pkg/detectors/rootly/rootly.go | 2 +- pkg/detectors/route4me/route4me.go | 5 +- pkg/detectors/rownd/rownd.go | 5 +- pkg/detectors/rubygems/rubygems.go | 5 +- pkg/detectors/runrunit/runrunit.go | 5 +- pkg/detectors/salesblink/salesblink.go | 5 +- pkg/detectors/salescookie/salescookie.go | 5 +- pkg/detectors/salesflare/salesflare.go | 5 +- pkg/detectors/salesforce/salesforce.go | 2 +- pkg/detectors/salesmate/salesmate.go | 2 +- .../satismeterwritekey_test.go | 2 +- pkg/detectors/scalewaykey/scalewaykey.go | 5 +- pkg/detectors/scalr/scalr.go | 5 +- pkg/detectors/scrapeowl/scrapeowl.go | 2 +- pkg/detectors/scraperapi/scraperapi.go | 5 +- pkg/detectors/scraperbox/scraperbox.go | 5 +- pkg/detectors/scrapestack/scrapestack.go | 5 +- pkg/detectors/scrapfly/scrapfly.go | 5 +- pkg/detectors/scrapingant/scrapingant.go | 7 ++- pkg/detectors/screenshotapi/screenshotapi.go | 5 +- .../screenshotlayer/screenshotlayer.go | 5 +- pkg/detectors/scrutinizerci/scrutinizerci.go | 5 +- .../securitytrails/securitytrails.go | 5 +- pkg/detectors/segmentapikey/segmentapikey.go | 5 +- pkg/detectors/selectpdf/selectpdf.go | 5 +- pkg/detectors/semaphore/semaphore.go | 5 +- pkg/detectors/sendbird/sendbird.go | 5 +- .../sendbirdorganizationapi.go | 2 +- pkg/detectors/sendinbluev2/sendinbluev2.go | 5 +- pkg/detectors/serphouse/serphouse.go | 5 +- pkg/detectors/serpstack/serpstack.go | 2 +- pkg/detectors/sheety/sheety.go | 2 +- pkg/detectors/sherpadesk/sherpadesk.go | 5 +- pkg/detectors/shipday/shipday.go | 5 +- pkg/detectors/shodankey/shodankey.go | 5 +- pkg/detectors/shopify/shopify.go | 2 +- pkg/detectors/shotstack/shotstack.go | 5 +- pkg/detectors/shutterstock/shutterstock.go | 5 +- .../shutterstockoauth/shutterstockoauth.go | 2 +- pkg/detectors/signable/signable.go | 2 +- pkg/detectors/signalwire/signalwire.go | 2 +- pkg/detectors/signaturit/signaturit.go | 5 +- pkg/detectors/signupgenius/signupgenius.go | 5 +- pkg/detectors/sigopt/sigopt.go | 2 +- pkg/detectors/simfin/simfin.go | 2 +- pkg/detectors/simplesat/simplesat.go | 5 +- pkg/detectors/simplynoted/simplynoted.go | 5 +- pkg/detectors/simvoly/simvoly.go | 5 +- pkg/detectors/sinchmessage/sinchmessage.go | 5 +- pkg/detectors/sirv/sirv.go | 5 +- pkg/detectors/siteleaf/siteleaf.go | 5 +- pkg/detectors/skrappio/skrappio.go | 5 +- pkg/detectors/slack/slack.go | 2 +- pkg/detectors/slackwebhook/slackwebhook.go | 4 +- pkg/detectors/smartystreets/smartystreets.go | 5 +- pkg/detectors/smooch/smooch.go | 5 +- pkg/detectors/snipcart/snipcart.go | 5 +- pkg/detectors/snowflake/snowflake.go | 2 +- pkg/detectors/snykkey/snykkey.go | 7 ++- pkg/detectors/sourcegraph/sourcegraph.go | 2 +- .../sourcegraphcody/sourcegraphcody.go | 2 +- pkg/detectors/sparkpost/sparkpost.go | 5 +- pkg/detectors/speechtextai/speechtextai.go | 5 +- .../splunkobservabilitytoken.go | 2 +- pkg/detectors/spoonacular/spoonacular.go | 5 +- pkg/detectors/sportsmonk/sportsmonk.go | 5 +- pkg/detectors/sqlserver/sqlserver.go | 2 +- pkg/detectors/square/square.go | 2 +- pkg/detectors/squarespace/squarespace.go | 5 +- pkg/detectors/sslmate/sslmate.go | 5 +- pkg/detectors/statuscake/statuscake.go | 5 +- pkg/detectors/statuspage/statuspage.go | 5 +- pkg/detectors/statuspal/statuspal.go | 5 +- pkg/detectors/stitchdata/stitchdata.go | 5 +- pkg/detectors/stockdata/stockdata.go | 5 +- pkg/detectors/storecove/storecove.go | 5 +- pkg/detectors/stormboard/stormboard.go | 5 +- pkg/detectors/stormglass/stormglass.go | 5 +- pkg/detectors/storychief/storychief.go | 5 +- pkg/detectors/strava/strava.go | 5 +- pkg/detectors/streak/streak.go | 5 +- pkg/detectors/stripe/stripe.go | 2 +- pkg/detectors/stripo/stripo.go | 5 +- pkg/detectors/stytch/stytch.go | 5 +- pkg/detectors/sugester/sugester.go | 2 +- pkg/detectors/supabasetoken/supabasetoken.go | 5 +- pkg/detectors/supernotesapi/supernotesapi.go | 2 +- .../surveyanyplace/surveyanyplace.go | 5 +- pkg/detectors/surveybot/surveybot.go | 5 +- pkg/detectors/surveysparrow/surveysparrow.go | 5 +- pkg/detectors/survicate/survicate.go | 5 +- pkg/detectors/swell/swell.go | 5 +- pkg/detectors/swiftype/swiftype.go | 5 +- pkg/detectors/tailscale/tailscale.go | 5 +- pkg/detectors/tallyfy/tallyfy.go | 2 +- pkg/detectors/tatumio/tatumio.go | 5 +- pkg/detectors/taxjar/taxjar.go | 5 +- pkg/detectors/teamgate/teamgate.go | 5 +- pkg/detectors/teamworkcrm/teamworkcrm.go | 5 +- pkg/detectors/teamworkdesk/teamworkdesk.go | 5 +- .../teamworkspaces/teamworkspaces.go | 5 +- .../technicalanalysisapi.go | 5 +- pkg/detectors/tefter/tefter.go | 5 +- .../telegrambottoken/telegrambottoken.go | 2 +- pkg/detectors/teletype/teletype.go | 5 +- pkg/detectors/telnyx/telnyx.go | 5 +- .../terraformcloudpersonaltoken.go | 2 +- pkg/detectors/textmagic/textmagic.go | 5 +- pkg/detectors/theoddsapi/theoddsapi.go | 5 +- pkg/detectors/thinkific/thinkific.go | 2 +- pkg/detectors/thousandeyes/thousandeyes.go | 5 +- pkg/detectors/ticketmaster/ticketmaster.go | 5 +- pkg/detectors/tiingo/tiingo.go | 5 +- pkg/detectors/timecamp/timecamp.go | 5 +- pkg/detectors/timezoneapi/timezoneapi.go | 5 +- pkg/detectors/tineswebhook/tineswebhook.go | 2 +- pkg/detectors/tly/tly.go | 5 +- pkg/detectors/tmetric/tmetric.go | 5 +- pkg/detectors/todoist/todoist.go | 2 +- pkg/detectors/toggltrack/toggltrack.go | 5 +- pkg/detectors/tokeet/tokeet.go | 5 +- pkg/detectors/tomorrowio/tomorrowio.go | 5 +- pkg/detectors/tomtom/tomtom.go | 2 +- pkg/detectors/tradier/tradier.go | 5 +- pkg/detectors/transferwise/transferwise.go | 5 +- pkg/detectors/travelpayouts/travelpayouts.go | 5 +- pkg/detectors/travisci/travisci.go | 5 +- pkg/detectors/trelloapikey/trelloapikey.go | 5 +- pkg/detectors/tru/tru.go | 5 +- .../trufflehogenterprise.go | 5 +- pkg/detectors/twelvedata/twelvedata.go | 5 +- pkg/detectors/twist/twist.go | 5 +- pkg/detectors/twitch/twitch.go | 2 +- pkg/detectors/twitter/v1/twitter_v1.go | 2 +- .../twitterconsumerkey/twitterconsumerkey.go | 4 +- pkg/detectors/tyntec/tyntec.go | 5 +- pkg/detectors/typeform/v2/typeform.go | 7 ++- pkg/detectors/typetalk/typetalk.go | 5 +- pkg/detectors/ubidots/ubidots.go | 5 +- pkg/detectors/uclassify/uclassify.go | 5 +- pkg/detectors/unifyid/unifyid.go | 5 +- pkg/detectors/unplugg/unplugg.go | 5 +- pkg/detectors/unsplash/unsplash.go | 5 +- pkg/detectors/upcdatabase/upcdatabase.go | 5 +- pkg/detectors/uplead/uplead.go | 5 +- pkg/detectors/uploadcare/uploadcare.go | 5 +- pkg/detectors/uptimerobot/uptimerobot.go | 2 +- pkg/detectors/upwave/upwave.go | 5 +- pkg/detectors/urlscan/urlscan.go | 5 +- pkg/detectors/user/user.go | 2 +- pkg/detectors/userflow/userflow.go | 5 +- pkg/detectors/userstack/userstack.go | 5 +- .../vagrantcloudpersonaltoken.go | 2 +- pkg/detectors/vatlayer/vatlayer.go | 5 +- pkg/detectors/vbout/vbout.go | 5 +- pkg/detectors/vercel/vercel.go | 5 +- pkg/detectors/verifier/verifier.go | 2 +- pkg/detectors/verimail/verimail.go | 2 +- pkg/detectors/veriphone/veriphone.go | 2 +- pkg/detectors/versioneye/versioneye.go | 5 +- pkg/detectors/viewneo/viewneo.go | 2 +- pkg/detectors/virustotal/virustotal.go | 5 +- .../visualcrossing/visualcrossing.go | 2 +- pkg/detectors/voiceflow/voiceflow.go | 7 ++- pkg/detectors/voicegain/voicegain.go | 5 +- pkg/detectors/voodoosms/voodoosms.go | 5 +- pkg/detectors/vouchery/vouchery.go | 5 +- pkg/detectors/vpnapi/vpnapi.go | 5 +- pkg/detectors/vultrapikey/vultrapikey.go | 5 +- pkg/detectors/vyte/vyte.go | 5 +- pkg/detectors/walkscore/walkscore.go | 5 +- pkg/detectors/weatherbit/weatherbit.go | 5 +- pkg/detectors/weatherstack/weatherstack.go | 5 +- pkg/detectors/web3storage/web3storage.go | 5 +- pkg/detectors/webex/webex.go | 5 +- pkg/detectors/webflow/webflow.go | 5 +- pkg/detectors/webscraper/webscraper.go | 2 +- pkg/detectors/webscraping/webscraping.go | 5 +- pkg/detectors/websitepulse/websitepulse.go | 5 +- pkg/detectors/wepay/wepay.go | 5 +- pkg/detectors/whoxy/whoxy.go | 5 +- pkg/detectors/wistia/wistia.go | 5 +- pkg/detectors/wit/wit.go | 5 +- pkg/detectors/worksnaps/worksnaps.go | 5 +- pkg/detectors/workstack/workstack.go | 5 +- .../worldcoinindex/worldcoinindex.go | 2 +- pkg/detectors/worldweather/worldweather.go | 5 +- pkg/detectors/wrike/wrike.go | 5 +- pkg/detectors/yandex/yandex.go | 5 +- pkg/detectors/yelp/yelp.go | 2 +- .../youneedabudget/youneedabudget.go | 5 +- pkg/detectors/yousign/yousign.go | 4 +- pkg/detectors/youtubeapikey/youtubeapikey.go | 5 +- pkg/engine/engine.go | 18 +++--- pkg/engine/engine_test.go | 18 +++--- pkg/engine/git_test.go | 4 +- pkg/gitparse/gitparse.go | 63 +++++++++---------- pkg/giturl/giturl.go | 6 +- pkg/handlers/apk.go | 6 +- pkg/handlers/apk_test.go | 10 +-- pkg/handlers/ar_test.go | 4 +- pkg/handlers/archive.go | 8 +-- pkg/handlers/archive_test.go | 6 +- pkg/handlers/default_test.go | 4 +- pkg/handlers/handlers_test.go | 28 ++++----- pkg/handlers/rpm_test.go | 4 +- pkg/iobuf/bufferedreaderseeker.go | 2 +- pkg/output/github_actions.go | 6 +- pkg/output/legacy_json.go | 4 +- pkg/output/plain.go | 50 +++++++-------- pkg/roundtripper/roundtripper.go | 6 +- pkg/sanitizer/utf8.go | 2 +- pkg/sources/chunker_test.go | 2 +- pkg/sources/docker/docker.go | 4 +- pkg/sources/docker/docker_test.go | 2 +- pkg/sources/elasticsearch/api.go | 12 ++-- .../elasticsearch_integration_test.go | 6 +- pkg/sources/errors_test.go | 10 +-- pkg/sources/filesystem/filesystem.go | 2 +- pkg/sources/filesystem/filesystem_test.go | 14 ++--- pkg/sources/gcs/gcs.go | 14 ++--- pkg/sources/gcs/gcs_test.go | 18 +++--- pkg/sources/git/git.go | 12 ++-- pkg/sources/git/git_test.go | 8 +-- pkg/sources/github/github.go | 14 ++--- .../github_experimental/object_discovery.go | 6 +- pkg/sources/gitlab/gitlab.go | 4 +- pkg/sources/huggingface/client.go | 2 +- pkg/sources/huggingface/huggingface.go | 2 +- pkg/sources/jenkins/jenkins.go | 6 +- pkg/sources/jenkins/jenkins_test.go | 12 ++-- .../json_enumerator/json_enumerator.go | 2 +- pkg/sources/postman/postman.go | 8 +-- pkg/sources/postman/postman_client.go | 2 +- pkg/sources/s3/s3.go | 10 +-- pkg/sources/source_manager.go | 2 +- pkg/sources/syslog/syslog.go | 10 +-- pkg/sources/test_helpers.go | 4 +- pkg/tui/common/style.go | 2 +- pkg/tui/components/selector/selector.go | 18 +++--- pkg/tui/components/viewport/viewport.go | 4 +- pkg/tui/pages/analyze_form/analyze_form.go | 2 +- pkg/tui/pages/analyze_keys/analyze_keys.go | 4 +- pkg/tui/pages/wizard_intro/item.go | 2 +- pkg/tui/pages/wizard_intro/wizard_intro.go | 4 +- pkg/updater/updater.go | 4 +- .../bufferedfilewriter.go | 4 +- .../bufferedfilewriter_test.go | 20 +++--- scripts/lint.sh | 3 +- 799 files changed, 1819 insertions(+), 1529 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 81183974787e..25bfcfb7845e 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -24,7 +24,7 @@ jobs: with: # NOTE: Version and args must match scripts/lint.sh version: v2.11.4 - args: --disable errcheck,staticcheck --enable bodyclose,copyloopvar,misspell --timeout 10m + args: --enable bodyclose,copyloopvar,misspell --timeout 10m man-page-staleness: name: man-page-staleness runs-on: ubuntu-latest diff --git a/hack/checksecretparts/main.go b/hack/checksecretparts/main.go index 209decce9973..7fbcc245cc2b 100644 --- a/hack/checksecretparts/main.go +++ b/hack/checksecretparts/main.go @@ -33,9 +33,9 @@ func main() { flag.BoolVar(&failOnFindings, "fail", false, "exit 1 if any findings are reported (default: warning-only)") flag.BoolVar(&quiet, "quiet", false, "suppress the summary line when no findings are reported") flag.Usage = func() { - fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [flags] [dir ...]\n", os.Args[0]) - fmt.Fprintln(flag.CommandLine.Output(), "\nFinds detector packages that construct detectors.Result without setting SecretParts.") - fmt.Fprintln(flag.CommandLine.Output(), "\nFlags:") + _, _ = fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [flags] [dir ...]\n", os.Args[0]) + _, _ = fmt.Fprintln(flag.CommandLine.Output(), "\nFinds detector packages that construct detectors.Result without setting SecretParts.") + _, _ = fmt.Fprintln(flag.CommandLine.Output(), "\nFlags:") flag.PrintDefaults() } flag.Parse() diff --git a/hack/snifftest/main.go b/hack/snifftest/main.go index fe401aa9e991..b2c46eec898c 100644 --- a/hack/snifftest/main.go +++ b/hack/snifftest/main.go @@ -219,7 +219,7 @@ func main() { logFatal(err, "error scanning repo") } logger.Info("scanned repo", "repo", r) - defer os.RemoveAll(path) + defer func() { _ = os.RemoveAll(path) }() }(repo) } diff --git a/main.go b/main.go index a73df6c0bc73..4f5532425083 100644 --- a/main.go +++ b/main.go @@ -465,7 +465,7 @@ func run(state overseer.State, logSync func() error) { if *githubScanToken != "" { // NOTE: this kludge is here to do an authenticated shallow commit // TODO: refactor to better pass credentials - os.Setenv("GITHUB_TOKEN", *githubScanToken) + _ = os.Setenv("GITHUB_TOKEN", *githubScanToken) } if *concurrency <= 0 { @@ -725,7 +725,7 @@ func runSingleScan(ctx context.Context, cmd string, cfg engine.Config) (metrics, handleFinishedMetrics := func(ctx context.Context, finishedMetrics <-chan sources.UnitMetrics, jobReportWriter io.WriteCloser) { go func() { defer func() { - jobReportWriter.Close() + _ = jobReportWriter.Close() if namer, ok := jobReportWriter.(interface{ Name() string }); ok { ctx.Logger().Info("report written", "path", namer.Name()) } else { diff --git a/pkg/analyzer/analyzers/airbrake/airbrake.go b/pkg/analyzer/analyzers/airbrake/airbrake.go index eba06658f2a0..494639e354b3 100644 --- a/pkg/analyzer/analyzers/airbrake/airbrake.go +++ b/pkg/analyzer/analyzers/airbrake/airbrake.go @@ -25,8 +25,7 @@ func (Analyzer) Type() analyzers.AnalyzerType { return analyzers.AnalyzerTypeAir func (a Analyzer) Analyze(_ context.Context, credInfo map[string]string) (*analyzers.AnalyzerResult, error) { info, err := AnalyzePermissions(a.Cfg, credInfo["key"]) if err != nil { - return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationAnalyzePermissions, analyzers.ServiceAPI, "", err, - ) + return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationAnalyzePermissions, analyzers.ServiceAPI, "", err) } return secretInfoToAnalyzerResult(info), nil } @@ -109,7 +108,7 @@ func validateKey(cfg *config.Config, key string) (bool, []Project, error) { } // read response - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // if status code is 200, decode response if resp.StatusCode == 200 { @@ -150,7 +149,7 @@ func AnalyzePermissions(cfg *config.Config, key string) (*SecretInfo, error) { return nil, err } if !valid { - return nil, fmt.Errorf("Invalid Airbrake User API Key") + return nil, fmt.Errorf("invalid Airbrake User API Key") } info := &SecretInfo{ diff --git a/pkg/analyzer/analyzers/airtable/airtablepat/airtable.go b/pkg/analyzer/analyzers/airtable/airtablepat/airtable.go index 2a87417991b5..97ca4f0fa8c5 100644 --- a/pkg/analyzer/analyzers/airtable/airtablepat/airtable.go +++ b/pkg/analyzer/analyzers/airtable/airtablepat/airtable.go @@ -119,7 +119,7 @@ func determineScope(token string, perm common.Permission, requiredIDs map[string if requiredIDs != nil { for _, key := range endpoint.RequiredIDs { if value, ok := requiredIDs[key]; ok { - url = strings.Replace(url, fmt.Sprintf("{%s}", key), value, -1) + url = strings.ReplaceAll(url, fmt.Sprintf("{%s}", key), value) } } } @@ -128,7 +128,7 @@ func determineScope(token string, perm common.Permission, requiredIDs map[string if err != nil { return false, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode == endpoint.ExpectedSuccessStatus { scopeStatusMap[scopeString] = true diff --git a/pkg/analyzer/analyzers/airtable/airtablepat/requests.go b/pkg/analyzer/analyzers/airtable/airtablepat/requests.go index 2afac070e646..88766832eea7 100644 --- a/pkg/analyzer/analyzers/airtable/airtablepat/requests.go +++ b/pkg/analyzer/analyzers/airtable/airtablepat/requests.go @@ -18,12 +18,12 @@ func fetchAirtableRecords(token string, baseID string, tableID string) ([]common if !exists { return nil, fmt.Errorf("endpoint for ListRecordsEndpoint does not exist") } - url := strings.Replace(strings.Replace(endpoint.URL, "{baseID}", baseID, -1), "{tableID}", tableID, -1) + url := strings.ReplaceAll(strings.ReplaceAll(endpoint.URL, "{baseID}", baseID), "{tableID}", tableID) resp, err := common.CallAirtableAPI(token, "GET", url) if err != nil { return nil, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("failed to fetch Airtable records, status: %d", resp.StatusCode) diff --git a/pkg/analyzer/analyzers/airtable/common/common.go b/pkg/analyzer/analyzers/airtable/common/common.go index cf989ca84fe0..6c9b7941d727 100644 --- a/pkg/analyzer/analyzers/airtable/common/common.go +++ b/pkg/analyzer/analyzers/airtable/common/common.go @@ -39,7 +39,7 @@ func FetchAirtableUserInfo(token string) (*AirtableUserInfo, error) { if err != nil { return nil, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("failed to fetch Airtable user info, status: %d", resp.StatusCode) @@ -62,7 +62,7 @@ func FetchAirtableBases(token string) (*AirtableBases, error) { if err != nil { return nil, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("failed to fetch Airtable bases, status: %d", resp.StatusCode) @@ -96,7 +96,7 @@ func fetchBaseSchema(token string, baseID string) (*Schema, error) { if err != nil { return nil, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("failed to fetch schema for base %s, status: %d", baseID, resp.StatusCode) diff --git a/pkg/analyzer/analyzers/analyzers.go b/pkg/analyzer/analyzers/analyzers.go index be2ad171de05..261bf95e219a 100644 --- a/pkg/analyzer/analyzers/analyzers.go +++ b/pkg/analyzer/analyzers/analyzers.go @@ -227,7 +227,7 @@ func (h *HttpStatusTest) RunTest(headers map[string]string) error { if err != nil { return err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // Check response status code switch { diff --git a/pkg/analyzer/analyzers/asana/asana.go b/pkg/analyzer/analyzers/asana/asana.go index a25158ab282b..d3c277ce5278 100644 --- a/pkg/analyzer/analyzers/asana/asana.go +++ b/pkg/analyzer/analyzers/asana/asana.go @@ -116,10 +116,10 @@ func AnalyzePermissions(cfg *config.Config, key string) (*SecretInfo, error) { } if resp.StatusCode != 200 { - return nil, fmt.Errorf("Invalid Asana API Key") + return nil, fmt.Errorf("invalid Asana API Key") } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() err = json.NewDecoder(resp.Body).Decode(&me) if err != nil { @@ -127,7 +127,7 @@ func AnalyzePermissions(cfg *config.Config, key string) (*SecretInfo, error) { } if me.Data.Email == "" { - return nil, fmt.Errorf("Invalid Asana API Key") + return nil, fmt.Errorf("invalid Asana API Key") } return &me, nil } diff --git a/pkg/analyzer/analyzers/bitbucket/bitbucket.go b/pkg/analyzer/analyzers/bitbucket/bitbucket.go index fd8471998df3..59d0b211e466 100644 --- a/pkg/analyzer/analyzers/bitbucket/bitbucket.go +++ b/pkg/analyzer/analyzers/bitbucket/bitbucket.go @@ -146,7 +146,7 @@ func getScopesAndType(cfg *config.Config, key string) (string, []string, error) if err != nil { return "", nil, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // parse response headers credentialType := resp.Header.Get("x-credential-type") @@ -198,7 +198,7 @@ func getRepositories(cfg *config.Config, key string, role string) (RepoJSON, err if err != nil { return repos, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // parse response body err = json.NewDecoder(resp.Body).Decode(&repos) diff --git a/pkg/analyzer/analyzers/client.go b/pkg/analyzer/analyzers/client.go index 1bd9818676c8..0d16d50dea7c 100644 --- a/pkg/analyzer/analyzers/client.go +++ b/pkg/analyzer/analyzers/client.go @@ -107,7 +107,7 @@ func (r LoggingRoundTripper) RoundTrip(req *http.Request) (*http.Response, error if err != nil { return resp, fmt.Errorf("failed to open log file: %w", err) } - defer file.Close() + defer func() { _ = file.Close() }() // Write log entry to file. if _, err := file.WriteString(logEntry); err != nil { diff --git a/pkg/analyzer/analyzers/datadog/requests.go b/pkg/analyzer/analyzers/datadog/requests.go index 9a9f7fd92b95..a4919607a694 100644 --- a/pkg/analyzer/analyzers/datadog/requests.go +++ b/pkg/analyzer/analyzers/datadog/requests.go @@ -216,7 +216,7 @@ func ValidateApiKey(client *http.Client, baseURL, apiKey string) (bool, error) { case http.StatusForbidden: return false, nil default: - return false, fmt.Errorf("Unable to validate api key with status code: %d", resp.StatusCode) + return false, fmt.Errorf("unable to validate api key with status code: %d", resp.StatusCode) } } diff --git a/pkg/analyzer/analyzers/digitalocean/digitalocean.go b/pkg/analyzer/analyzers/digitalocean/digitalocean.go index e2266deb9504..0b870046b0c1 100644 --- a/pkg/analyzer/analyzers/digitalocean/digitalocean.go +++ b/pkg/analyzer/analyzers/digitalocean/digitalocean.go @@ -34,13 +34,11 @@ func (Analyzer) Type() analyzers.AnalyzerType { return analyzers.AnalyzerTypeDig func (a Analyzer) Analyze(_ context.Context, credInfo map[string]string) (*analyzers.AnalyzerResult, error) { key, ok := credInfo["key"] if !ok { - return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationValidateCredentials, analyzers.ServiceConfig, "", errors.New("missing key in credInfo"), - ) + return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationValidateCredentials, analyzers.ServiceConfig, "", errors.New("missing key in credInfo")) } info, err := AnalyzePermissions(a.Cfg, key) if err != nil { - return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationAnalyzePermissions, analyzers.ServiceAPI, "", err, - ) + return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationAnalyzePermissions, analyzers.ServiceAPI, "", err) } return secretInfoToAnalyzerResult(info), nil } @@ -125,7 +123,7 @@ func (h *HttpStatusTest) RunTest(cfg *config.Config, headers map[string]string) if err != nil { return false, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // Check response status code switch { @@ -232,7 +230,7 @@ func getUser(cfg *config.Config, token string) (*user, error) { if err != nil { return nil, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() switch resp.StatusCode { case http.StatusOK: diff --git a/pkg/analyzer/analyzers/elevenlabs/elevenlabs.go b/pkg/analyzer/analyzers/elevenlabs/elevenlabs.go index 7cb07b578fca..1234a092cb5c 100644 --- a/pkg/analyzer/analyzers/elevenlabs/elevenlabs.go +++ b/pkg/analyzer/analyzers/elevenlabs/elevenlabs.go @@ -86,14 +86,12 @@ func (a Analyzer) Analyze(_ context.Context, credInfo map[string]string) (*analy // check if the `key` exist in the credentials info key, exist := credInfo["key"] if !exist { - return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationValidateCredentials, analyzers.ServiceConfig, "", errors.New("key not found in credentials info"), - ) + return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationValidateCredentials, analyzers.ServiceConfig, "", errors.New("key not found in credentials info")) } info, err := AnalyzePermissions(a.Cfg, key) if err != nil { - return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationAnalyzePermissions, analyzers.ServiceAPI, "", err, - ) + return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationAnalyzePermissions, analyzers.ServiceAPI, "", err) } return secretInfoToAnalyzerResult(info), nil @@ -242,9 +240,10 @@ func fetchUser(client *http.Client, key string) (*User, error) { return nil, err } - if errorResp.Detail.Status == InvalidAPIKey || errorResp.Detail.Status == NotVerifiable { + switch errorResp.Detail.Status { + case InvalidAPIKey, NotVerifiable: return nil, errors.New("invalid api key") - } else if errorResp.Detail.Status == MissingPermissions { + case MissingPermissions: // key is missing user read permissions but is valid return nil, nil } diff --git a/pkg/analyzer/analyzers/figma/figma.go b/pkg/analyzer/analyzers/figma/figma.go index fc381bedebe2..a96f3435ee1c 100644 --- a/pkg/analyzer/analyzers/figma/figma.go +++ b/pkg/analyzer/analyzers/figma/figma.go @@ -83,7 +83,7 @@ func AnalyzePermissions(cfg *config.Config, token string) (*secretInfo, error) { if err != nil { return nil, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() body, err := io.ReadAll(resp.Body) if err != nil { return nil, err diff --git a/pkg/analyzer/analyzers/github/finegrained/finegrained.go b/pkg/analyzer/analyzers/github/finegrained/finegrained.go index d796a3001779..2a0a94c17c38 100644 --- a/pkg/analyzer/analyzers/github/finegrained/finegrained.go +++ b/pkg/analyzer/analyzers/github/finegrained/finegrained.go @@ -78,7 +78,7 @@ func permissionFormatter(key, val any) (string, string) { if perm, ok := val.(Permission); ok { permStr, err := perm.ToString() if err != nil { - log.Fatal(fmt.Errorf("Error converting permission to string: %v", err)) + log.Fatal(fmt.Errorf("error converting permission to string: %v", err)) } var permissionStr string switch { @@ -217,7 +217,7 @@ func getCodeScanningAlertsPermission(client *gh.Client, repo *gh.Repository, cur // Risk: Extremely Low // -> GET request to /repos/{owner}/{repo}/code-scanning/alerts _, resp, err := client.CodeScanning.ListAlertsForRepo(context.Background(), *repo.Owner.Login, *repo.Name, nil) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() switch { case resp.StatusCode == 403: @@ -427,7 +427,7 @@ func getDependabotAlertsPermission(client *gh.Client, repo *gh.Repository, curre // Risk: Extremely Low // GET /repos/{owner}/{repo}/dependabot/alerts _, resp, err := client.Dependabot.ListRepoAlerts(context.Background(), *repo.Owner.Login, *repo.Name, &gh.ListAlertsOptions{}) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() switch resp.StatusCode { case 403: diff --git a/pkg/analyzer/analyzers/gitlab/gitlab.go b/pkg/analyzer/analyzers/gitlab/gitlab.go index 62ab2a587fa4..4fb26058376d 100644 --- a/pkg/analyzer/analyzers/gitlab/gitlab.go +++ b/pkg/analyzer/analyzers/gitlab/gitlab.go @@ -155,7 +155,7 @@ func getPersonalAccessToken(cfg *config.Config, key, host string) (AccessTokenJS return tokens, resp.StatusCode, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if err := json.NewDecoder(resp.Body).Decode(&tokens); err != nil { return tokens, resp.StatusCode, err } @@ -183,7 +183,7 @@ func getAccessibleProjects(cfg *config.Config, key, host string) ([]ProjectsJSON return projects, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() bodyBytes, err := io.ReadAll(resp.Body) if err != nil { @@ -197,7 +197,7 @@ func getAccessibleProjects(cfg *config.Config, key, host string) ([]ProjectsJSON if err := json.NewDecoder(newBody()).Decode(&projects); err != nil { var e ErrorJSON if err := json.NewDecoder(newBody()).Decode(&e); err == nil { - return projects, fmt.Errorf("Insufficient Scope to query for projects. We need api or read_api permissions.") + return projects, errors.New("insufficient scope to query for projects: we need api or read_api permissions") } return projects, err } @@ -219,7 +219,7 @@ func getMetadata(cfg *config.Config, key, host string) (MetadataJSON, error) { return metadata, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() bodyBytes, err := io.ReadAll(resp.Body) if err != nil { @@ -239,7 +239,7 @@ func getMetadata(cfg *config.Config, key, host string) (MetadataJSON, error) { if err := json.NewDecoder(newBody()).Decode(&e); err != nil { return metadata, err } - return metadata, fmt.Errorf("Insufficient Scope to query for metadata. We need read_user, ai_features, api or read_api permissions.") + return metadata, errors.New("insufficient scope to query for metadata: we need read_user, ai_features, api or read_api permissions") } return metadata, nil @@ -258,7 +258,7 @@ func AnalyzePermissions(cfg *config.Config, key string, host string) (*SecretInf return nil, err } if statusCode != http.StatusOK { - return nil, fmt.Errorf("Invalid GitLab Access Token") + return nil, errors.New("invalid GitLab access token") } meta, err := getMetadata(cfg, key, host) diff --git a/pkg/analyzer/analyzers/huggingface/huggingface.go b/pkg/analyzer/analyzers/huggingface/huggingface.go index b7ca38fc7a38..73bf9b1a9636 100644 --- a/pkg/analyzer/analyzers/huggingface/huggingface.go +++ b/pkg/analyzer/analyzers/huggingface/huggingface.go @@ -33,14 +33,12 @@ func (Analyzer) Type() analyzers.AnalyzerType { return analyzers.AnalyzerTypeHug func (a Analyzer) Analyze(_ context.Context, credInfo map[string]string) (*analyzers.AnalyzerResult, error) { key, ok := credInfo["key"] if !ok || key == "" { - return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationValidateCredentials, analyzers.ServiceConfig, "", fmt.Errorf("key not found in credentialInfo"), - ) + return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationValidateCredentials, analyzers.ServiceConfig, "", fmt.Errorf("key not found in credentialInfo")) } info, err := AnalyzePermissions(a.Cfg, key) if err != nil { - return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationAnalyzePermissions, analyzers.ServiceAPI, "", err, - ) + return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationAnalyzePermissions, analyzers.ServiceAPI, "", err) } return secretInfoToAnalyzerResult(info), nil } @@ -99,15 +97,17 @@ func bakefineGrainedBindings(allModels []Model, tokenJSON HFTokenJSON) []analyze Value: string(analyzers.NONE), } for _, perm := range permission.Permissions { - if perm == "repo.content.read" { + switch perm { + case "repo.content.read": privs.Value = string(analyzers.READ) - } else if perm == "repo.write" { + case "repo.write": privs.Value = string(analyzers.WRITE) } } - if permission.Entity.Type == "user" || permission.Entity.Type == "org" { + switch permission.Entity.Type { + case "user", "org": nameToPermissions[permission.Entity.Name] = privs - } else if permission.Entity.Type == "model" { + case "model": nameToPermissions[modelNameLookup(allModels, permission.Entity.ID)] = privs } } @@ -334,7 +334,7 @@ func getModelsByAuthor(cfg *config.Config, key string, author string) ([]Model, } // defer the response body closing - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // read response if err := json.NewDecoder(resp.Body).Decode(&modelsJSON); err != nil { @@ -370,7 +370,7 @@ func getTokenInfo(cfg *config.Config, key string) (HFTokenJSON, bool, error) { } // defer the response body closing - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // read response if err := json.NewDecoder(resp.Body).Decode(&tokenJSON); err != nil { @@ -392,7 +392,7 @@ func AnalyzePermissions(cfg *config.Config, key string) (*SecretInfo, error) { } if !success { - return nil, fmt.Errorf("Invalid HuggingFace Access Token") + return nil, fmt.Errorf("invalid HuggingFace Access Token") } // get all models by username @@ -609,15 +609,17 @@ func printAccessibleModels(allModels []Model, tokenJSON HFTokenJSON) { read := false write := false for _, perm := range permission.Permissions { - if perm == "repo.content.read" { + switch perm { + case "repo.content.read": read = true - } else if perm == "repo.write" { + case "repo.write": write = true } } - if permission.Entity.Type == "user" || permission.Entity.Type == "org" { + switch permission.Entity.Type { + case "user", "org": nameToPermissions[permission.Entity.Name] = Permissions{Read: read, Write: write} - } else if permission.Entity.Type == "model" { + case "model": nameToPermissions[modelNameLookup(allModels, permission.Entity.ID)] = Permissions{Read: read, Write: write} } } diff --git a/pkg/analyzer/analyzers/jira/requests.go b/pkg/analyzer/analyzers/jira/requests.go index bac24b9133e7..43bb6edc8e20 100644 --- a/pkg/analyzer/analyzers/jira/requests.go +++ b/pkg/analyzer/analyzers/jira/requests.go @@ -428,13 +428,12 @@ func captureAuditLogs(client *http.Client, domain, email, token string, secretIn } func handleStatusCode(statusCode int, endpoint string) error { - switch { - case statusCode == http.StatusOK: + switch statusCode { + case http.StatusOK: return nil - case statusCode == http.StatusBadRequest: + case http.StatusBadRequest: return fmt.Errorf("bad request for API: %s", endpoint) - case statusCode == http.StatusUnauthorized, statusCode == http.StatusForbidden, - statusCode == http.StatusNotFound, statusCode == http.StatusConflict: + case http.StatusUnauthorized, http.StatusForbidden, http.StatusNotFound, http.StatusConflict: return nil default: return fmt.Errorf("unexpected status code: %d for API: %s", statusCode, endpoint) diff --git a/pkg/analyzer/analyzers/mailchimp/mailchimp.go b/pkg/analyzer/analyzers/mailchimp/mailchimp.go index 514f25d3d565..316c232d8149 100644 --- a/pkg/analyzer/analyzers/mailchimp/mailchimp.go +++ b/pkg/analyzer/analyzers/mailchimp/mailchimp.go @@ -146,7 +146,7 @@ func getMetadata(cfg *config.Config, key string) (MetadataJSON, error) { return metadata, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if err := json.NewDecoder(resp.Body).Decode(&metadata); err != nil { return metadata, err @@ -177,7 +177,7 @@ func getDomains(cfg *config.Config, key string) (DomainsJSON, error) { return domains, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if err := json.NewDecoder(resp.Body).Decode(&domains); err != nil { return domains, err @@ -198,7 +198,7 @@ func AnalyzePermissions(cfg *config.Config, key string) (*SecretInfo, error) { return nil, err } if metadata.AccountID == "" { - return nil, fmt.Errorf("Invalid Mailchimp API key") + return nil, fmt.Errorf("invalid Mailchimp API key") } // get sending domains diff --git a/pkg/analyzer/analyzers/mailgun/requests.go b/pkg/analyzer/analyzers/mailgun/requests.go index ab7da22da167..8f9f653333fd 100644 --- a/pkg/analyzer/analyzers/mailgun/requests.go +++ b/pkg/analyzer/analyzers/mailgun/requests.go @@ -53,7 +53,7 @@ func getDomains(client *http.Client, apiKey string, secretInfo *SecretInfo) erro if err != nil { return err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode != 200 { return fmt.Errorf("invalid Mailgun API key") @@ -83,7 +83,7 @@ func getKeys(client *http.Client, apiKey string, secretInfo *SecretInfo) error { if err != nil { return err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode != 200 { return fmt.Errorf("invalid Mailgun API key") diff --git a/pkg/analyzer/analyzers/mux/models.go b/pkg/analyzer/analyzers/mux/models.go index e7d3b52afa93..87e978dd1ec3 100644 --- a/pkg/analyzer/analyzers/mux/models.go +++ b/pkg/analyzer/analyzers/mux/models.go @@ -56,9 +56,10 @@ func (info *secretInfo) addPermission(resourceType ResourceType, permission stri return } - if permission == "read" { + switch permission { + case "read": info.Permissions[resourceType] = Read - } else if permission == "write" { + case "write": info.Permissions[resourceType] = FullAccess } } diff --git a/pkg/analyzer/analyzers/mysql/mysql.go b/pkg/analyzer/analyzers/mysql/mysql.go index 213ed6757cf1..131634911f87 100644 --- a/pkg/analyzer/analyzers/mysql/mysql.go +++ b/pkg/analyzer/analyzers/mysql/mysql.go @@ -292,7 +292,7 @@ func AnalyzePermissions(cfg *config.Config, connectionStr string) (*SecretInfo, if err != nil { return nil, fmt.Errorf("connecting to the MySQL database: %w", err) } - defer db.Close() + defer func() { _ = db.Close() }() // Get the current user user, err := getUser(db) @@ -434,7 +434,7 @@ func getDatabases(db *sql.DB, databases map[string]*Database) error { if err != nil { return err } - defer rows.Close() + defer func() { _ = rows.Close() }() for rows.Next() { var dbName string @@ -462,7 +462,7 @@ func getTables(db *sql.DB, databases map[string]*Database) error { if err != nil { return err } - defer rows.Close() + defer func() { _ = rows.Close() }() for rows.Next() { var dbName string @@ -486,7 +486,7 @@ func getRoutines(db *sql.DB, databases map[string]*Database) error { if err != nil { return err } - defer rows.Close() + defer func() { _ = rows.Close() }() for rows.Next() { var dbName string @@ -513,7 +513,7 @@ func getGrants(db *sql.DB) ([]string, error) { if err != nil { return nil, err } - defer rows.Close() + defer func() { _ = rows.Close() }() var grants []string for rows.Next() { @@ -568,7 +568,7 @@ func processGrant(grant string, databases map[string]*Database, globalPrivs *Glo // Split on " ON " parts := strings.Split(grant, " ON ") if len(parts) < 2 { - return fmt.Errorf("Error processing grant: %s", grant) + return fmt.Errorf("error processing grant: %s", grant) } // Put privs in a slice diff --git a/pkg/analyzer/analyzers/notion/notion.go b/pkg/analyzer/analyzers/notion/notion.go index 35c7e0c1d718..fe78cc20c733 100644 --- a/pkg/analyzer/analyzers/notion/notion.go +++ b/pkg/analyzer/analyzers/notion/notion.go @@ -30,13 +30,11 @@ func (Analyzer) Type() analyzers.AnalyzerType { return analyzers.AnalyzerTypeNot func (a Analyzer) Analyze(_ context.Context, credInfo map[string]string) (*analyzers.AnalyzerResult, error) { key, ok := credInfo["key"] if !ok { - return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationValidateCredentials, analyzers.ServiceConfig, "", errors.New("missing key in credInfo"), - ) + return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationValidateCredentials, analyzers.ServiceConfig, "", errors.New("missing key in credInfo")) } info, err := AnalyzePermissions(a.Cfg, key) if err != nil { - return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationAnalyzePermissions, analyzers.ServiceAPI, "", err, - ) + return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationAnalyzePermissions, analyzers.ServiceAPI, "", err) } return secretInfoToAnalyzerResult(info), nil } @@ -143,7 +141,7 @@ func (h *HttpStatusTest) RunTest(cfg *config.Config, headers map[string]string) if err != nil { return false, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // Check response status code switch { @@ -330,7 +328,7 @@ func getBotInfo(client *http.Client, key string) (*bot, error) { if err != nil { return nil, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() switch resp.StatusCode { case http.StatusOK: @@ -368,7 +366,7 @@ func getWorkspaceUsers(client *http.Client, key string) ([]user, error) { if err != nil { return nil, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() switch resp.StatusCode { case http.StatusOK: diff --git a/pkg/analyzer/analyzers/openai/openai.go b/pkg/analyzer/analyzers/openai/openai.go index d7057db0546c..69c4410a585f 100644 --- a/pkg/analyzer/analyzers/openai/openai.go +++ b/pkg/analyzer/analyzers/openai/openai.go @@ -31,8 +31,7 @@ func (Analyzer) Type() analyzers.AnalyzerType { return analyzers.AnalyzerTypeOpe func (a Analyzer) Analyze(_ context.Context, credInfo map[string]string) (*analyzers.AnalyzerResult, error) { info, err := AnalyzePermissions(a.Cfg, credInfo["key"]) if err != nil { - return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationAnalyzePermissions, analyzers.ServiceAPI, "", err, - ) + return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationAnalyzePermissions, analyzers.ServiceAPI, "", err) } return secretInfoToAnalyzerResult(info), nil } @@ -214,7 +213,7 @@ func openAIRequest(cfg *config.Config, method string, url string, key string, da return nil, nil, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() outBody, err := io.ReadAll(resp.Body) if err != nil { diff --git a/pkg/analyzer/analyzers/opsgenie/opsgenie.go b/pkg/analyzer/analyzers/opsgenie/opsgenie.go index 6c13a92ef4a6..90c3bea580a8 100644 --- a/pkg/analyzer/analyzers/opsgenie/opsgenie.go +++ b/pkg/analyzer/analyzers/opsgenie/opsgenie.go @@ -30,13 +30,11 @@ func (Analyzer) Type() analyzers.AnalyzerType { return analyzers.AnalyzerTypeOps func (a Analyzer) Analyze(_ context.Context, credInfo map[string]string) (*analyzers.AnalyzerResult, error) { key, ok := credInfo["key"] if !ok { - return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationValidateCredentials, analyzers.ServiceConfig, "", errors.New("missing key in credInfo"), - ) + return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationValidateCredentials, analyzers.ServiceConfig, "", errors.New("missing key in credInfo")) } info, err := AnalyzePermissions(a.Cfg, key) if err != nil { - return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationAnalyzePermissions, analyzers.ServiceAPI, "", err, - ) + return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationAnalyzePermissions, analyzers.ServiceAPI, "", err) } return secretInfoToAnalyzerResult(info), nil } @@ -159,7 +157,7 @@ func (h *HttpStatusTest) RunTest(cfg *config.Config, headers map[string]string) if err != nil { return false, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // Check response status code switch { @@ -231,7 +229,7 @@ func getUserList(cfg *config.Config, key string) ([]User, error) { if err != nil { return nil, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // Decode response body var userList UsersJSON diff --git a/pkg/analyzer/analyzers/plaid/plaid.go b/pkg/analyzer/analyzers/plaid/plaid.go index fc44e98100c5..5b2f936c2992 100644 --- a/pkg/analyzer/analyzers/plaid/plaid.go +++ b/pkg/analyzer/analyzers/plaid/plaid.go @@ -108,7 +108,7 @@ func getPlaidAccounts(client *http.Client, clientID string, secret string, acces if err != nil { return nil, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("received non-OK HTTP status: %d", resp.StatusCode) diff --git a/pkg/analyzer/analyzers/planetscale/planetscale.go b/pkg/analyzer/analyzers/planetscale/planetscale.go index 9d356be9c63a..ddbbd395302a 100644 --- a/pkg/analyzer/analyzers/planetscale/planetscale.go +++ b/pkg/analyzer/analyzers/planetscale/planetscale.go @@ -137,7 +137,7 @@ func (h *HttpStatusTest) RunTest(cfg *config.Config, headers map[string]string, if err != nil { return false, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // Check response status code switch { @@ -539,7 +539,7 @@ func sendGetRequest(cfg *config.Config, id, key, url string, responseObj interfa if err != nil { return err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // Check response status code switch resp.StatusCode { diff --git a/pkg/analyzer/analyzers/postgres/postgres.go b/pkg/analyzer/analyzers/postgres/postgres.go index 3d5a8265ae46..313c46ada028 100644 --- a/pkg/analyzer/analyzers/postgres/postgres.go +++ b/pkg/analyzer/analyzers/postgres/postgres.go @@ -278,7 +278,7 @@ func AnalyzePermissions(cfg *config.Config, connectionStr string) (*SecretInfo, if err != nil { return nil, fmt.Errorf("failed to connect to Postgres database: %w", err) } - defer db.Close() + defer func() { _ = db.Close() }() role, privs, err := getUserPrivs(db) if err != nil { @@ -372,7 +372,7 @@ func getUserPrivs(db *sql.DB) (string, map[string]bool, error) { if err != nil { return "", nil, err } - defer rows.Close() + defer func() { _ = rows.Close() }() var roleName string var isSuperuser, canInherit, canCreateRole, canCreateDB, canLogin, isReplicationRole, bypassesRLS bool @@ -389,7 +389,7 @@ func getUserPrivs(db *sql.DB) (string, map[string]bool, error) { } // Map roles to privileges - var mapRoles map[string]bool = map[string]bool{ + var mapRoles = map[string]bool{ "Superuser": isSuperuser, "Inheritance of Privs": canInherit, "Create Role": canCreateRole, @@ -427,7 +427,7 @@ func getDBPrivs(db *sql.DB) (string, []DB, error) { if err != nil { return "", nil, err } - defer rows.Close() + defer func() { _ = rows.Close() }() dbs := make([]DB, 0) @@ -501,7 +501,7 @@ func getDBWriter(db DB, current_user string) func(a ...interface{}) string { func buildSliceDBNames(dbs []DB) []string { var dbNames []string for _, db := range dbs { - if db.DBPrivs.Connect { + if db.Connect { dbNames = append(dbNames, db.DatabaseName) } } @@ -519,7 +519,7 @@ func getTablePrivs(params map[string]string, databases []string) (map[string]map // color.Red("[x] Failed to connect to Postgres database: %s", dbase) continue } - defer db.Close() + defer func() { _ = db.Close() }() // Get table privs query := ` @@ -543,7 +543,7 @@ func getTablePrivs(params map[string]string, databases []string) (map[string]map if err != nil { return nil, err } - defer rows.Close() + defer func() { _ = rows.Close() }() // Iterate through the result set for rows.Next() { @@ -589,7 +589,7 @@ func getTablePrivs(params map[string]string, databases []string) (map[string]map if err = rows.Err(); err != nil { return nil, err } - db.Close() + _ = db.Close() } return tablePrivileges, nil diff --git a/pkg/analyzer/analyzers/posthog/posthog.go b/pkg/analyzer/analyzers/posthog/posthog.go index 2706e988c863..81399e47ffff 100644 --- a/pkg/analyzer/analyzers/posthog/posthog.go +++ b/pkg/analyzer/analyzers/posthog/posthog.go @@ -37,13 +37,11 @@ func (Analyzer) Type() analyzers.AnalyzerType { return analyzers.AnalyzerTypePos func (a Analyzer) Analyze(_ context.Context, credInfo map[string]string) (*analyzers.AnalyzerResult, error) { key, ok := credInfo["key"] if !ok { - return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationValidateCredentials, analyzers.ServiceConfig, "", errors.New("missing key in credInfo"), - ) + return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationValidateCredentials, analyzers.ServiceConfig, "", errors.New("missing key in credInfo")) } info, err := AnalyzePermissions(a.Cfg, key) if err != nil { - return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationAnalyzePermissions, analyzers.ServiceAPI, "", err, - ) + return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationAnalyzePermissions, analyzers.ServiceAPI, "", err) } return secretInfoToAnalyzerResult(info), nil } @@ -166,7 +164,7 @@ func (h *HttpStatusTest) RunTest(cfg *config.Config, client *http.Client, domain if err != nil { return false, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // Check response status code switch { @@ -302,7 +300,7 @@ func AnalyzePermissions(cfg *config.Config, key string) (*SecretInfo, error) { // we need to determine if the key is for US or EU domain domain, user, err := resolveDomainAndUser(cfg, client, key) if err != nil { - return nil, fmt.Errorf("Invalid API Key: %w", err) + return nil, fmt.Errorf("invalid API key: %w", err) } info.user = user @@ -439,7 +437,7 @@ func resolveDomainAndUser(cfg *config.Config, client *http.Client, key string) ( if err != nil { return "", nil, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() switch resp.StatusCode { case http.StatusOK: @@ -476,7 +474,7 @@ func getOrganization(cfg *config.Config, client *http.Client, domain string, key if err != nil { return nil, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() switch resp.StatusCode { case http.StatusOK: diff --git a/pkg/analyzer/analyzers/postman/postman.go b/pkg/analyzer/analyzers/postman/postman.go index 93a09ffca9d4..b3291be888a7 100644 --- a/pkg/analyzer/analyzers/postman/postman.go +++ b/pkg/analyzer/analyzers/postman/postman.go @@ -26,13 +26,11 @@ func (Analyzer) Type() analyzers.AnalyzerType { return analyzers.AnalyzerTypePos func (a Analyzer) Analyze(_ context.Context, credInfo map[string]string) (*analyzers.AnalyzerResult, error) { key, ok := credInfo["key"] if !ok { - return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationValidateCredentials, analyzers.ServiceConfig, "", fmt.Errorf("missing key in credInfo"), - ) + return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationValidateCredentials, analyzers.ServiceConfig, "", fmt.Errorf("missing key in credInfo")) } info, err := AnalyzePermissions(a.Cfg, key) if err != nil { - return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationAnalyzePermissions, analyzers.ServiceAPI, "", err, - ) + return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationAnalyzePermissions, analyzers.ServiceAPI, "", err) } return secretInfoToAnalyzerResult(info), nil } @@ -148,7 +146,7 @@ func getUserInfo(cfg *config.Config, key string) (UserInfoJSON, error) { } // read response - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // if status code is 200, decode response if resp.StatusCode == 200 { @@ -175,7 +173,7 @@ func getWorkspaces(cfg *config.Config, key string) (WorkspaceJSON, error) { } // read response - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // if status code is 200, decode response if resp.StatusCode == 200 { @@ -224,7 +222,7 @@ func AnalyzePermissions(cfg *config.Config, key string) (*SecretInfo, error) { } if me.User.Username == "" { - return nil, fmt.Errorf("Invalid Postman API Key") + return nil, fmt.Errorf("invalid Postman API Key") } // get workspaces, if there is error user with empty workspaces will be returned diff --git a/pkg/analyzer/analyzers/shopify/shopify.go b/pkg/analyzer/analyzers/shopify/shopify.go index ad1cafa92887..dd26bf38a686 100644 --- a/pkg/analyzer/analyzers/shopify/shopify.go +++ b/pkg/analyzer/analyzers/shopify/shopify.go @@ -213,7 +213,7 @@ func getShopInfo(cfg *config.Config, key string, store string) (ShopInfoJSON, er return shopInfo, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() err = json.NewDecoder(resp.Body).Decode(&shopInfo) if err != nil { @@ -252,7 +252,7 @@ func getAccessScopes(cfg *config.Config, key string, store string) (AccessScopes return accessScopes, resp.StatusCode, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() err = json.NewDecoder(resp.Body).Decode(&accessScopes) if err != nil { diff --git a/pkg/analyzer/analyzers/slack/slack.go b/pkg/analyzer/analyzers/slack/slack.go index a8d55f6e2b19..62a6b2893b32 100644 --- a/pkg/analyzer/analyzers/slack/slack.go +++ b/pkg/analyzer/analyzers/slack/slack.go @@ -141,7 +141,7 @@ func getSlackOAuthScopes(cfg *config.Config, key string) (scopes string, userDat if err != nil { return scopes, userData, err } - defer resp.Body.Close() // Close the response body when the function returns + defer func() { _ = resp.Body.Close() }() // Close the response body when the function returns // print body body, err := io.ReadAll(resp.Body) diff --git a/pkg/analyzer/analyzers/sourcegraph/sourcegraph.go b/pkg/analyzer/analyzers/sourcegraph/sourcegraph.go index 609d3aee0b77..9c8033797832 100644 --- a/pkg/analyzer/analyzers/sourcegraph/sourcegraph.go +++ b/pkg/analyzer/analyzers/sourcegraph/sourcegraph.go @@ -26,13 +26,11 @@ func (Analyzer) Type() analyzers.AnalyzerType { return analyzers.AnalyzerTypeSou func (a Analyzer) Analyze(_ context.Context, credInfo map[string]string) (*analyzers.AnalyzerResult, error) { key, ok := credInfo["key"] if !ok { - return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationValidateCredentials, analyzers.ServiceConfig, "", fmt.Errorf("missing key in credInfo"), - ) + return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationValidateCredentials, analyzers.ServiceConfig, "", fmt.Errorf("missing key in credInfo")) } info, err := AnalyzePermissions(a.Cfg, key) if err != nil { - return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationAnalyzePermissions, analyzers.ServiceAPI, "", err, - ) + return nil, analyzers.NewAnalysisError(a.Type().String(), analyzers.OperationAnalyzePermissions, analyzers.ServiceAPI, "", err) } return secretInfoToAnalyzerResult(info), nil } @@ -116,7 +114,7 @@ func getUserInfo(cfg *config.Config, key string) (UserInfoJSON, error) { return userInfo, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() err = json.NewDecoder(resp.Body).Decode(&userInfo) if err != nil { @@ -151,7 +149,7 @@ func checkSiteAdmin(cfg *config.Config, key string) (bool, error) { return false, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() var response GraphQLResponse diff --git a/pkg/analyzer/analyzers/square/square.go b/pkg/analyzer/analyzers/square/square.go index 104b2119020a..bb0a26a6dd32 100644 --- a/pkg/analyzer/analyzers/square/square.go +++ b/pkg/analyzer/analyzers/square/square.go @@ -173,7 +173,7 @@ func getPermissions(cfg *config.Config, key string) (PermissionsJSON, error) { return permissions, nil } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() err = json.NewDecoder(resp.Body).Decode(&permissions) if err != nil { @@ -210,7 +210,7 @@ func getUsers(cfg *config.Config, key string) (TeamJSON, error) { return team, nil } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() err = json.NewDecoder(resp.Body).Decode(&team) if err != nil { diff --git a/pkg/analyzer/analyzers/stripe/stripe.go b/pkg/analyzer/analyzers/stripe/stripe.go index 65325406ecab..d100182e589e 100644 --- a/pkg/analyzer/analyzers/stripe/stripe.go +++ b/pkg/analyzer/analyzers/stripe/stripe.go @@ -162,7 +162,7 @@ func (h *HttpStatusTest) RunTest(cfg *config.Config, headers map[string]string) if err != nil { return false, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // Check response status code switch { @@ -195,7 +195,7 @@ func checkKeyType(key string) (string, error) { } else if strings.HasPrefix(key, RESTRICTED_PREFIX) { return RESTRICTED, nil } - return "", errors.New("Invalid Stripe key format") + return "", errors.New("invalid Stripe key format") } func checkKeyEnv(key string) (string, error) { @@ -226,7 +226,7 @@ func checkValidity(cfg *config.Config, key string) (bool, error) { if err != nil { return false, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // Check the response. Valid is 200 (secret/restricted) or 403 (restricted) if resp.StatusCode == 200 || resp.StatusCode == 403 { @@ -290,15 +290,17 @@ func AnalyzeAndPrintPermissions(cfg *config.Config, key string) { color.Green("[!] Valid Stripe API Key\n\n") - if info.KeyType == SECRET { + switch info.KeyType { + case SECRET: color.Green("[i] Key Type: %s", info.KeyType) - } else if info.KeyType == RESTRICTED { + case RESTRICTED: color.Yellow("[i] Key Type: %s", info.KeyType) } - if info.KeyEnv == LIVE { + switch info.KeyEnv { + case LIVE: color.Green("[i] Key Environment: %s", info.KeyEnv) - } else if info.KeyEnv == TEST { + case TEST: color.Red("[i] Key Environment: %s", info.KeyEnv) } diff --git a/pkg/analyzer/analyzers/twilio/twilio.go b/pkg/analyzer/analyzers/twilio/twilio.go index 87229f662bd8..3a92d2bc0ed2 100644 --- a/pkg/analyzer/analyzers/twilio/twilio.go +++ b/pkg/analyzer/analyzers/twilio/twilio.go @@ -49,7 +49,8 @@ func (a *Analyzer) Analyze(ctx context.Context, credentialInfo map[string]string } var permissions []Permission - if info.AccountStatusCode == 200 { + switch info.AccountStatusCode { + case 200: permissions = []Permission{ AccountManagementRead, AccountManagementWrite, @@ -68,7 +69,7 @@ func (a *Analyzer) Analyze(ctx context.Context, credentialInfo map[string]string CallManagementRead, CallManagementWrite, } - } else if info.AccountStatusCode == 401 { + case 401: permissions = []Permission{ ServiceVerificationRead, ServiceVerificationWrite, @@ -159,7 +160,7 @@ func getAccountsStatusCode(cfg *config.Config, sid string, secret string) (int, if err != nil { return 0, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() return resp.StatusCode, nil } @@ -196,7 +197,7 @@ func getVerifyServicesStatusCode(cfg *config.Config, sid string, secret string) if err != nil { return serviceRes, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // read response if err := json.NewDecoder(resp.Body).Decode(&serviceRes); err != nil { @@ -224,7 +225,7 @@ func listTwilioAccounts(cfg *config.Config, sid, secret string) ([]service, erro if err != nil { return nil, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() var result struct { Accounts []service `json:"accounts"` @@ -287,11 +288,12 @@ func printPermissions(statusCode int) { color.Green("[!] Valid Twilio API Key\n") color.Green("[i] Expires: Never") - if statusCode == 401 { + switch statusCode { + case 401: color.Yellow("[i] Key type: Standard") color.Yellow("[i] Permissions: All EXCEPT key management and account/subaccount configuration.") - } else if statusCode == 200 { + case 200: color.Green("[i] Key type: Main (aka Admin)") color.Green("[i] Permissions: All") } diff --git a/pkg/analyzer/generate_permissions/generate_permissions.go b/pkg/analyzer/generate_permissions/generate_permissions.go index c26b61e41f93..c541670e34f0 100644 --- a/pkg/analyzer/generate_permissions/generate_permissions.go +++ b/pkg/analyzer/generate_permissions/generate_permissions.go @@ -111,7 +111,7 @@ func main() { if err != nil { log.Fatalf("Failed to open YAML file: %v", err) } - defer file.Close() + defer func() { _ = file.Close() }() var data PermissionsData decoder := yaml.NewDecoder(file) @@ -135,7 +135,7 @@ func main() { if err != nil { log.Fatalf("Failed to create output file: %v", err) } - defer outputFile.Close() + defer func() { _ = outputFile.Close() }() err = tmpl.Execute(outputFile, data) if err != nil { diff --git a/pkg/buffers/buffer/buffer.go b/pkg/buffers/buffer/buffer.go index b3bd17749d6c..b25b9507c5a4 100644 --- a/pkg/buffers/buffer/buffer.go +++ b/pkg/buffers/buffer/buffer.go @@ -47,11 +47,11 @@ func (b *Buffer) Write(data []byte) (int, error) { } size := len(data) - bufferLength := b.Buffer.Len() + bufferLength := b.Len() totalSizeNeeded := bufferLength + size // If the total size is within the threshold, write to the buffer. - availableSpace := b.Buffer.Cap() - bufferLength + availableSpace := b.Cap() - bufferLength growSize := totalSizeNeeded - bufferLength if growSize > availableSpace { // We are manually growing the buffer so we can track the growth via metrics. diff --git a/pkg/cleantemp/cleantemp.go b/pkg/cleantemp/cleantemp.go index 8a9d39e48219..5a2fedc28ed4 100644 --- a/pkg/cleantemp/cleantemp.go +++ b/pkg/cleantemp/cleantemp.go @@ -73,7 +73,7 @@ func CleanTempArtifacts(ctx logContext.Context) error { if err != nil { return fmt.Errorf("error opening temp dir: %w", err) } - defer dir.Close() + defer func() { _ = dir.Close() }() for { entries, err := dir.ReadDir(1) // read only one entry diff --git a/pkg/common/filter_test.go b/pkg/common/filter_test.go index a4df8db62265..29bf6e9a2bef 100644 --- a/pkg/common/filter_test.go +++ b/pkg/common/filter_test.go @@ -144,14 +144,14 @@ func TestFilterFromFile(t *testing.T) { if err := testFilterWriteFile(includeTestFile, []byte(test.includeFileContents)); err != nil { t.Fatalf("failed to create include rules file: %s", err) } - defer os.Remove(includeTestFile) + defer func() { _ = os.Remove(includeTestFile) }() } if test.excludeFile { excludeTestFile = "/tmp/trufflehog_test_xfilter.txt" if err := testFilterWriteFile(excludeTestFile, []byte(test.excludeFileContents)); err != nil { t.Fatalf("failed to create include rules file: %s", err) } - defer os.Remove(excludeTestFile) + defer func() { _ = os.Remove(excludeTestFile) }() } filter, err := FilterFromFiles(includeTestFile, excludeTestFile) diff --git a/pkg/common/http_test.go b/pkg/common/http_test.go index 34d6028865ce..55e37e48de66 100644 --- a/pkg/common/http_test.go +++ b/pkg/common/http_test.go @@ -395,7 +395,7 @@ func TestSaneHttpClientMetrics(t *testing.T) { resp, err := client.Get(requestURL) require.NoError(t, err) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() assert.Equal(t, tc.expectedStatusCode, resp.StatusCode) // Check that request counter was incremented @@ -462,7 +462,7 @@ func TestRetryableHttpClientMetrics(t *testing.T) { resp, err := client.Get(requestURL) require.NoError(t, err) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() assert.Equal(t, tc.expectedStatusCode, resp.StatusCode) // Check that request counter was incremented @@ -494,7 +494,7 @@ func TestInstrumentedTransport(t *testing.T) { // Make a request resp, err := client.Get(server.URL) require.NoError(t, err) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // Verify the request was successful assert.Equal(t, http.StatusOK, resp.StatusCode) diff --git a/pkg/common/secrets.go b/pkg/common/secrets.go index cc759248eed8..0dc444e17cae 100644 --- a/pkg/common/secrets.go +++ b/pkg/common/secrets.go @@ -54,7 +54,7 @@ func GetSecret(ctx context.Context, gcpProject, name string) (secret *Secret, er if err != nil { return nil, errors.Errorf("failed to create secretmanager client: %v", err) } - defer client.Close() + defer func() { _ = client.Close() }() req := &secretmanagerpb.AccessSecretVersionRequest{ Name: parent, diff --git a/pkg/decoders/html_test.go b/pkg/decoders/html_test.go index 403ebdb2f93a..296d7ae44d33 100644 --- a/pkg/decoders/html_test.go +++ b/pkg/decoders/html_test.go @@ -208,7 +208,7 @@ func TestHTML_FromChunk(t *testing.T) { { // Block elements (

) produce newline boundaries so adjacent // paragraphs don't merge tokens. - name: "block elements produce newlines", + name: "block elements produce newlines", chunk: &sources.Chunk{Data: []byte(`

first

second

`)}, want: "first\nsecond", }, @@ -336,39 +336,39 @@ func TestHTML_FromChunk(t *testing.T) { { // Zero-width spaces inserted between characters by rich text editors // are stripped so detector regexes can match the full token. - name: "zero-width space stripped from secret", + name: "zero-width space stripped from secret", chunk: &sources.Chunk{Data: []byte("

TOKEN_\u200BABCDEF_1234

")}, - want: "TOKEN_ABCDEF_1234", + want: "TOKEN_ABCDEF_1234", }, { // Multiple invisible codepoint types mixed into a single token. - name: "multiple invisible character types stripped", + name: "multiple invisible character types stripped", chunk: &sources.Chunk{Data: []byte("

SECRET\u200C_VALUE\u00AD_HERE\u2060_END\uFEFF

")}, - want: "SECRET_VALUE_HERE_END", + want: "SECRET_VALUE_HERE_END", }, // --- SVG xlink:href attribute extraction --- { // SVG elements use xlink:href for URLs which may contain tokens. - name: "xlink:href extracted from SVG element", + name: "xlink:href extracted from SVG element", chunk: &sources.Chunk{Data: []byte(`icon`)}, - want: "https://api.example.com?token=secret_value_123\nicon", + want: "https://api.example.com?token=secret_value_123\nicon", }, // --- Double-encoded HTML entity decoding --- { // Content double-encoded as &amp; becomes & after the parser's // first pass; the residual entity replacer decodes it to &. - name: "double-encoded ampersand decoded", + name: "double-encoded ampersand decoded", chunk: &sources.Chunk{Data: []byte(`

key=abc&amp;secret=val

`)}, - want: "key=abc&secret=val", + want: "key=abc&secret=val", }, { // Single-encoded entities are handled by the parser; verify the // residual replacer does not corrupt already-decoded content. - name: "single-encoded entities not double-decoded", + name: "single-encoded entities not double-decoded", chunk: &sources.Chunk{Data: []byte(`

5 > 3 & 2 < 4

`)}, - want: "5 > 3 & 2 < 4", + want: "5 > 3 & 2 < 4", }, // --- Integration: all extraction types in one chunk --- @@ -398,7 +398,7 @@ func TestHTML_FromChunk(t *testing.T) { if tt.wantNil { if got != nil { - t.Errorf("FromChunk() = %q, want nil", string(got.Chunk.Data)) + t.Errorf("FromChunk() = %q, want nil", string(got.Data)) } return } @@ -409,8 +409,8 @@ func TestHTML_FromChunk(t *testing.T) { if got.DecoderType != detectorspb.DecoderType_HTML { t.Errorf("DecoderType = %v, want %v", got.DecoderType, detectorspb.DecoderType_HTML) } - if string(got.Chunk.Data) != tt.want { - t.Errorf("FromChunk() data =\n%q\nwant:\n%q", string(got.Chunk.Data), tt.want) + if string(got.Data) != tt.want { + t.Errorf("FromChunk() data =\n%q\nwant:\n%q", string(got.Data), tt.want) } }) } @@ -423,7 +423,7 @@ func TestHTML_FeatureFlagDisabled(t *testing.T) { d := &HTML{} chunk := &sources.Chunk{Data: []byte(`

secret: hunter2

`)} if got := d.FromChunk(chunk); got != nil { - t.Errorf("FromChunk() should return nil when disabled, got %q", string(got.Chunk.Data)) + t.Errorf("FromChunk() should return nil when disabled, got %q", string(got.Data)) } } @@ -439,8 +439,8 @@ func TestHTML_FeatureFlagEnabled(t *testing.T) { if got == nil { t.Fatal("FromChunk() returned nil, want decoded chunk") } - if string(got.Chunk.Data) != "secret: hunter2" { - t.Errorf("FromChunk() data = %q, want %q", string(got.Chunk.Data), "secret: hunter2") + if string(got.Data) != "secret: hunter2" { + t.Errorf("FromChunk() data = %q, want %q", string(got.Data), "secret: hunter2") } } diff --git a/pkg/detectors/abstract/abstract.go b/pkg/detectors/abstract/abstract.go index cd2b63bdfe2c..620571b5217c 100644 --- a/pkg/detectors/abstract/abstract.go +++ b/pkg/detectors/abstract/abstract.go @@ -3,10 +3,11 @@ package abstract import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -80,7 +81,7 @@ func verifyAbstract(ctx context.Context, client *http.Client, resMatch string) ( if err != nil { return false, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() // https://docs.abstractapi.com/exchange-rates#response-and-error-codes switch res.StatusCode { diff --git a/pkg/detectors/abuseipdb/abuseipdb.go b/pkg/detectors/abuseipdb/abuseipdb.go index 906a614af37f..685f931d8e4d 100644 --- a/pkg/detectors/abuseipdb/abuseipdb.go +++ b/pkg/detectors/abuseipdb/abuseipdb.go @@ -83,7 +83,7 @@ func verifyAbuseIPDB(ctx context.Context, client *http.Client, resMatch string) if err != nil { return false, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() switch res.StatusCode { case http.StatusOK: diff --git a/pkg/detectors/abyssale/abyssale.go b/pkg/detectors/abyssale/abyssale.go index 6865f811a35c..3ff29716a089 100644 --- a/pkg/detectors/abyssale/abyssale.go +++ b/pkg/detectors/abyssale/abyssale.go @@ -81,7 +81,7 @@ func verifyAbyssale(ctx context.Context, client *http.Client, resMatch string) ( if err != nil { return false, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() switch res.StatusCode { case http.StatusOK: diff --git a/pkg/detectors/accuweather/v1/accuweather.go b/pkg/detectors/accuweather/v1/accuweather.go index e2f61563d77e..32a167ea3b94 100644 --- a/pkg/detectors/accuweather/v1/accuweather.go +++ b/pkg/detectors/accuweather/v1/accuweather.go @@ -93,7 +93,7 @@ func verifyAccuweather(ctx context.Context, client *http.Client, key string) (bo if err != nil { return false, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() // https://developer.accuweather.com/accuweather-locations-api/apis/get/locations/v1/cities/autocomplete switch res.StatusCode { diff --git a/pkg/detectors/adafruitio/adafruitio.go b/pkg/detectors/adafruitio/adafruitio.go index 95145920b46c..b7c3555d7c9b 100644 --- a/pkg/detectors/adafruitio/adafruitio.go +++ b/pkg/detectors/adafruitio/adafruitio.go @@ -79,7 +79,7 @@ func verifyAdafruitIO(ctx context.Context, client *http.Client, resMatch string) if err != nil { return false, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() // https://learn.adafruit.com/adafruit-io/http-status-codes switch res.StatusCode { diff --git a/pkg/detectors/adzuna/adzuna.go b/pkg/detectors/adzuna/adzuna.go index 0cdb23b34009..f662049c650f 100644 --- a/pkg/detectors/adzuna/adzuna.go +++ b/pkg/detectors/adzuna/adzuna.go @@ -91,7 +91,7 @@ func verifyAdzuna(ctx context.Context, client *http.Client, resMatch, resIdMatch if err != nil { return false, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() // https://developer.adzuna.com/overview switch res.StatusCode { diff --git a/pkg/detectors/aeroworkflow/aeroworkflow.go b/pkg/detectors/aeroworkflow/aeroworkflow.go index 10e1c63015f8..2c798a56d3b5 100644 --- a/pkg/detectors/aeroworkflow/aeroworkflow.go +++ b/pkg/detectors/aeroworkflow/aeroworkflow.go @@ -93,7 +93,7 @@ func verifyAeroworkflow(ctx context.Context, client *http.Client, resMatch, resI if err != nil { return false, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() // https://api.aeroworkflow.com/swagger/index.html switch res.StatusCode { diff --git a/pkg/detectors/agora/agora.go b/pkg/detectors/agora/agora.go index a2284b4ce91a..328497a0be0c 100644 --- a/pkg/detectors/agora/agora.go +++ b/pkg/detectors/agora/agora.go @@ -99,7 +99,7 @@ func verifyAgora(ctx context.Context, client *http.Client, resMatch, resSecret s if err != nil { return false, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() // https://docs.agora.io/en/voice-calling/reference/agora-console-rest-api#get-all-projects switch res.StatusCode { diff --git a/pkg/detectors/aha/aha.go b/pkg/detectors/aha/aha.go index b17bb82bb3d6..27fc01e46424 100644 --- a/pkg/detectors/aha/aha.go +++ b/pkg/detectors/aha/aha.go @@ -106,7 +106,7 @@ func verifyAha(ctx context.Context, client *http.Client, resMatch, resURLMatch s if err != nil { return false, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() // https://www.aha.io/api switch res.StatusCode { diff --git a/pkg/detectors/alibaba/alibaba.go b/pkg/detectors/alibaba/alibaba.go index 91417aae6c09..bc8a7bb1663a 100644 --- a/pkg/detectors/alibaba/alibaba.go +++ b/pkg/detectors/alibaba/alibaba.go @@ -75,9 +75,9 @@ func GetSignature(input, key string) string { } func buildStringToSign(method, input string) string { - filter := strings.Replace(input, "+", "%20", -1) - filter = strings.Replace(filter, "%7E", "~", -1) - filter = strings.Replace(filter, "*", "%2A", -1) + filter := strings.ReplaceAll(input, "+", "%20") + filter = strings.ReplaceAll(filter, "%7E", "~") + filter = strings.ReplaceAll(filter, "*", "%2A") filter = method + "&%2F&" + url.QueryEscape(filter) return filter } @@ -155,7 +155,7 @@ func verifyAlibaba(ctx context.Context, client *http.Client, resIdMatch, resMatc if err != nil { return false, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() var alibabaResp alibabaResp if err = json.NewDecoder(res.Body).Decode(&alibabaResp); err != nil { diff --git a/pkg/detectors/anthropic/anthropic.go b/pkg/detectors/anthropic/anthropic.go index bcd09c32e0ee..ab4e59d0b766 100644 --- a/pkg/detectors/anthropic/anthropic.go +++ b/pkg/detectors/anthropic/anthropic.go @@ -111,7 +111,7 @@ func verifyAnthropicKey(ctx context.Context, client *http.Client, endpoint, key if err != nil { return false, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() switch res.StatusCode { case http.StatusOK: diff --git a/pkg/detectors/apacta/apacta_test.go b/pkg/detectors/apacta/apacta_test.go index b03975ac3e0d..35ef67642c90 100644 --- a/pkg/detectors/apacta/apacta_test.go +++ b/pkg/detectors/apacta/apacta_test.go @@ -37,7 +37,7 @@ func TestApacta_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"abcd1234-ef56-gh78-ij90-klmn1234opqr"}, @@ -73,7 +73,7 @@ func TestApacta_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/appoptics/appoptics.go b/pkg/detectors/appoptics/appoptics.go index fdd1805e0d67..7db69ac67ab3 100644 --- a/pkg/detectors/appoptics/appoptics.go +++ b/pkg/detectors/appoptics/appoptics.go @@ -4,10 +4,11 @@ import ( "context" b64 "encoding/base64" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -65,7 +66,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode == 401 { diff --git a/pkg/detectors/audd/audd.go b/pkg/detectors/audd/audd.go index 6cf65ed74e68..313191a69205 100644 --- a/pkg/detectors/audd/audd.go +++ b/pkg/detectors/audd/audd.go @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err == nil { bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `"status":"success"`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { s1.Verified = true diff --git a/pkg/detectors/autodesk/autodesk.go b/pkg/detectors/autodesk/autodesk.go index 368943ff7902..0ae61b471085 100644 --- a/pkg/detectors/autodesk/autodesk.go +++ b/pkg/detectors/autodesk/autodesk.go @@ -65,7 +65,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/x-www-form-urlencoded") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/autopilot/autopilot.go b/pkg/detectors/autopilot/autopilot.go index c893af85b4d3..53d79c6c2880 100644 --- a/pkg/detectors/autopilot/autopilot.go +++ b/pkg/detectors/autopilot/autopilot.go @@ -2,10 +2,11 @@ package autopilot import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("autopilotapikey", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/aws/session_keys/sessionkey.go b/pkg/detectors/aws/session_keys/sessionkey.go index 2fe5bb5c90a9..03f13fd1917a 100644 --- a/pkg/detectors/aws/session_keys/sessionkey.go +++ b/pkg/detectors/aws/session_keys/sessionkey.go @@ -336,7 +336,7 @@ func (s scanner) CleanResults(results []detectors.Result) []detectors.Result { // Reference: https://nitter.poast.org/TalBeerySec/status/1816449053841838223#m func checkSessionToken(sessionToken string, secret string) bool { - if !(strings.Contains(sessionToken, "YXdz") || strings.Contains(sessionToken, "Jb3JpZ2luX2Vj")) || + if (!strings.Contains(sessionToken, "YXdz") && !strings.Contains(sessionToken, "Jb3JpZ2luX2Vj")) || strings.Contains(sessionToken, secret) { // Handle error if the sessionToken is not a valid base64 string return false diff --git a/pkg/detectors/azure_batch/azurebatch.go b/pkg/detectors/azure_batch/azurebatch.go index 56df04edbba5..32d3f803711f 100644 --- a/pkg/detectors/azure_batch/azurebatch.go +++ b/pkg/detectors/azure_batch/azurebatch.go @@ -116,7 +116,7 @@ func verifyMatch(ctx context.Context, client *http.Client, endpoint, accountName } return false, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() switch resp.StatusCode { case http.StatusOK: diff --git a/pkg/detectors/azureapimanagement/repositorykey/repositorykey.go b/pkg/detectors/azureapimanagement/repositorykey/repositorykey.go index 403a519c8526..62864cbac481 100644 --- a/pkg/detectors/azureapimanagement/repositorykey/repositorykey.go +++ b/pkg/detectors/azureapimanagement/repositorykey/repositorykey.go @@ -30,7 +30,7 @@ var ( passwordPat = regexp.MustCompile(detectors.PrefixRegex([]string{"azure", "password"}) + `\b(git&[0-9]{12}&[a-zA-Z0-9\/+]{85}[a-zA-Z0-9]==)`) invalidHosts = simple.NewCache[struct{}]() - noSuchHostErr = errors.New("Could not resolve host") + errNoSuchHost = errors.New("could not resolve host") ) const ( @@ -82,7 +82,7 @@ EndpointLoop: isVerified, err := verifyUrlPassword(ctx, urlMatch, azureGitUsername, passwordMatch) s1.Verified = isVerified if err != nil { - if errors.Is(err, noSuchHostErr) { + if errors.Is(err, errNoSuchHost) { invalidHosts.Set(urlMatch, struct{}{}) continue EndpointLoop } @@ -156,7 +156,7 @@ func verifyUrlPassword(_ context.Context, repoUrl, user, password string) (bool, if strings.Contains(outputString, "Authentication failed") { return false, nil } else if strings.Contains(outputString, "Could not resolve host") { - return false, noSuchHostErr + return false, errNoSuchHost } return false, err } diff --git a/pkg/detectors/azureapimanagementsubscriptionkey/azureapimanagementsubscriptionkey.go b/pkg/detectors/azureapimanagementsubscriptionkey/azureapimanagementsubscriptionkey.go index 97841c92a33f..2a2795d9a1fa 100644 --- a/pkg/detectors/azureapimanagementsubscriptionkey/azureapimanagementsubscriptionkey.go +++ b/pkg/detectors/azureapimanagementsubscriptionkey/azureapimanagementsubscriptionkey.go @@ -31,7 +31,7 @@ var ( keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"azure", ".azure-api.net", "subscription", "key"}) + `([a-zA-Z-0-9]{32})`) // pattern for both Primary and secondary key invalidHosts = simple.NewCache[struct{}]() - noSuchHostErr = errors.New("no such host") + errNoSuchHost = errors.New("no such host") ) // Keywords are used for efficiently pre-filtering chunks. @@ -81,7 +81,7 @@ EndpointLoop: isVerified, verificationErr := s.verifyMatch(ctx, client, baseUrl, key) s1.Verified = isVerified if verificationErr != nil { - if errors.Is(verificationErr, noSuchHostErr) { + if errors.Is(verificationErr, errNoSuchHost) { invalidHosts.Set(baseUrl, struct{}{}) continue EndpointLoop } @@ -120,7 +120,7 @@ func (s Scanner) verifyMatch(ctx context.Context, client *http.Client, baseUrl, if err != nil { return false, nil } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() switch resp.StatusCode { case http.StatusOK: diff --git a/pkg/detectors/azureappconfigconnectionstring/azureappconfigconnectionstring.go b/pkg/detectors/azureappconfigconnectionstring/azureappconfigconnectionstring.go index 0beecd260590..bce5cbb6fb09 100644 --- a/pkg/detectors/azureappconfigconnectionstring/azureappconfigconnectionstring.go +++ b/pkg/detectors/azureappconfigconnectionstring/azureappconfigconnectionstring.go @@ -153,7 +153,7 @@ func (s Scanner) verifyMatch(ctx context.Context, client *http.Client, endpoint, if err != nil { return false, fmt.Errorf("request failed: %w", err) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // Check the response status switch resp.StatusCode { diff --git a/pkg/detectors/azurecontainerregistry/azurecontainerregistry.go b/pkg/detectors/azurecontainerregistry/azurecontainerregistry.go index e2556eeb8858..2e585736dfe1 100644 --- a/pkg/detectors/azurecontainerregistry/azurecontainerregistry.go +++ b/pkg/detectors/azurecontainerregistry/azurecontainerregistry.go @@ -104,7 +104,7 @@ EndpointLoop: r.Verified = true } if verificationErr != nil { - if errors.Is(verificationErr, noSuchHostErr) { + if errors.Is(verificationErr, errNoSuchHost) { invalidHosts.Set(username, struct{}{}) continue EndpointLoop } @@ -126,7 +126,7 @@ func (s Scanner) IsFalsePositive(_ detectors.Result) (bool, string) { return false, "" } -var noSuchHostErr = errors.New("no such host") +var errNoSuchHost = errors.New("no such host") func verifyMatch(ctx context.Context, client *http.Client, username string, password string) (bool, error) { req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("https://%s.azurecr.io/v2/", username), nil) @@ -139,7 +139,7 @@ func verifyMatch(ctx context.Context, client *http.Client, username string, pass if err != nil { // lookup foo.azurecr.io: no such host if strings.Contains(err.Error(), "no such host") { - return false, noSuchHostErr + return false, errNoSuchHost } return false, err } diff --git a/pkg/detectors/azuredevopspersonalaccesstoken/azuredevopspersonalaccesstoken.go b/pkg/detectors/azuredevopspersonalaccesstoken/azuredevopspersonalaccesstoken.go index b020c72dce37..edf1b03e125f 100644 --- a/pkg/detectors/azuredevopspersonalaccesstoken/azuredevopspersonalaccesstoken.go +++ b/pkg/detectors/azuredevopspersonalaccesstoken/azuredevopspersonalaccesstoken.go @@ -68,7 +68,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.SetBasicAuth("", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() hasVerifiedRes, _ := common.ResponseContainsSubstring(res.Body, "lastUpdateTime") if res.StatusCode >= 200 && res.StatusCode < 300 && hasVerifiedRes { s1.Verified = true diff --git a/pkg/detectors/azuredirectmanagementkey/azuredirectmanagementkey.go b/pkg/detectors/azuredirectmanagementkey/azuredirectmanagementkey.go index b03481486b53..66af785f00e7 100644 --- a/pkg/detectors/azuredirectmanagementkey/azuredirectmanagementkey.go +++ b/pkg/detectors/azuredirectmanagementkey/azuredirectmanagementkey.go @@ -37,7 +37,7 @@ var ( keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"azure", ".management.azure-api.net"}) + `([a-zA-Z0-9+\/]{83,85}[a-zA-Z0-9]==)`) // pattern for both Primary and secondary key invalidHosts = simple.NewCache[struct{}]() - noSuchHostErr = errors.New("no such host") + errNoSuchHost = errors.New("no such host") ) // Keywords are used for efficiently pre-filtering chunks. @@ -87,7 +87,7 @@ EndpointLoop: isVerified, verificationErr := s.verifyMatch(ctx, client, baseUrl, serviceName, key) s1.Verified = isVerified if verificationErr != nil { - if errors.Is(verificationErr, noSuchHostErr) { + if errors.Is(verificationErr, errNoSuchHost) { invalidHosts.Set(baseUrl, struct{}{}) continue EndpointLoop } @@ -133,7 +133,7 @@ func (s Scanner) verifyMatch(ctx context.Context, client *http.Client, baseUrl, if err != nil { return false, nil } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() switch resp.StatusCode { case http.StatusOK: diff --git a/pkg/detectors/azurefunctionkey/azurefunctionkey.go b/pkg/detectors/azurefunctionkey/azurefunctionkey.go index 9a93494b1eb5..2bf02b877a03 100644 --- a/pkg/detectors/azurefunctionkey/azurefunctionkey.go +++ b/pkg/detectors/azurefunctionkey/azurefunctionkey.go @@ -64,7 +64,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode == 401 { diff --git a/pkg/detectors/azuresastoken/azuresastoken.go b/pkg/detectors/azuresastoken/azuresastoken.go index a887a9ed3150..e5a74327afc7 100644 --- a/pkg/detectors/azuresastoken/azuresastoken.go +++ b/pkg/detectors/azuresastoken/azuresastoken.go @@ -37,7 +37,7 @@ var ( invalidStorageAccounts = simple.NewCache[struct{}]() - noSuchHostErr = errors.New("no such host") + errNoSuchHost = errors.New("no such host") ) func (s Scanner) Keywords() []string { @@ -101,7 +101,7 @@ UrlLoop: s1.Verified = isVerified if verificationErr != nil { - if errors.Is(verificationErr, noSuchHostErr) { + if errors.Is(verificationErr, errNoSuchHost) { invalidStorageAccounts.Set(storageAccount, struct{}{}) continue UrlLoop } @@ -131,11 +131,11 @@ func verifyMatch(ctx context.Context, client *http.Client, url, key string, retr res, err := client.Do(req) if err != nil { if strings.Contains(err.Error(), "no such host") { - return false, noSuchHostErr + return false, errNoSuchHost } return false, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { diff --git a/pkg/detectors/azuresearchadminkey/azuresearchadminkey.go b/pkg/detectors/azuresearchadminkey/azuresearchadminkey.go index bf76892f9f80..65af1b9d3482 100644 --- a/pkg/detectors/azuresearchadminkey/azuresearchadminkey.go +++ b/pkg/detectors/azuresearchadminkey/azuresearchadminkey.go @@ -69,7 +69,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode == 401 || res.StatusCode == 403 { diff --git a/pkg/detectors/azuresearchquerykey/azuresearchquerykey.go b/pkg/detectors/azuresearchquerykey/azuresearchquerykey.go index 25a68e744344..e15905fcea29 100644 --- a/pkg/detectors/azuresearchquerykey/azuresearchquerykey.go +++ b/pkg/detectors/azuresearchquerykey/azuresearchquerykey.go @@ -69,7 +69,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode == 401 || res.StatusCode == 403 { diff --git a/pkg/detectors/bannerbear/v1/bannerbear_test.go b/pkg/detectors/bannerbear/v1/bannerbear_test.go index 009862310559..ffd623e7a7d3 100644 --- a/pkg/detectors/bannerbear/v1/bannerbear_test.go +++ b/pkg/detectors/bannerbear/v1/bannerbear_test.go @@ -39,7 +39,7 @@ func TestBannerBear_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"yvxpthLIcYpZweFpPOVeCOtt"}, @@ -77,7 +77,7 @@ func TestBannerBear_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/bannerbear/v2/bannerbear_test.go b/pkg/detectors/bannerbear/v2/bannerbear_test.go index f75714a71753..b8ccbac0ecb1 100644 --- a/pkg/detectors/bannerbear/v2/bannerbear_test.go +++ b/pkg/detectors/bannerbear/v2/bannerbear_test.go @@ -39,7 +39,7 @@ func TestBannerBear_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"bb_pr_abcdc2b40ef44abcd8cbf3739aabcd"}, @@ -77,7 +77,7 @@ func TestBannerBear_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/baremetrics/baremetrics_test.go b/pkg/detectors/baremetrics/baremetrics_test.go index 71ae28b90411..aca628dcd4df 100644 --- a/pkg/detectors/baremetrics/baremetrics_test.go +++ b/pkg/detectors/baremetrics/baremetrics_test.go @@ -39,7 +39,7 @@ func TestBareMetrics_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"sk_nGDJWCkPiFAKE5XFTzUUA"}, @@ -77,7 +77,7 @@ func TestBareMetrics_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/beamer/beamer_test.go b/pkg/detectors/beamer/beamer_test.go index 2a9b710f05c6..d59867ccdc00 100644 --- a/pkg/detectors/beamer/beamer_test.go +++ b/pkg/detectors/beamer/beamer_test.go @@ -38,7 +38,7 @@ func TestBeamer_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"DyVdf7+cAXw4MH9gT1CPotU31RMl__aLKbrABRWvT7TyO="}, @@ -75,7 +75,7 @@ func TestBeamer_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/beebole/beebole_test.go b/pkg/detectors/beebole/beebole_test.go index b9f668f06ecb..8ea8ba05b835 100644 --- a/pkg/detectors/beebole/beebole_test.go +++ b/pkg/detectors/beebole/beebole_test.go @@ -39,7 +39,7 @@ func TestBeeBole_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"bn6htprmfpukfalts4muwalxh9j15ucvnrfdme8t"}, @@ -77,7 +77,7 @@ func TestBeeBole_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/besnappy/besnappy_test.go b/pkg/detectors/besnappy/besnappy_test.go index 0ad2393210c1..0528d29259f7 100644 --- a/pkg/detectors/besnappy/besnappy_test.go +++ b/pkg/detectors/besnappy/besnappy_test.go @@ -39,7 +39,7 @@ func TestBeSnappy_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"f58c5d37d7876d32cfdd823f8fe4ded364a8d483b5dbfadcc55ad801b3be8523"}, @@ -77,7 +77,7 @@ func TestBeSnappy_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/besttime/besttime_test.go b/pkg/detectors/besttime/besttime_test.go index 3af4f58f1faa..06f4d71eb652 100644 --- a/pkg/detectors/besttime/besttime_test.go +++ b/pkg/detectors/besttime/besttime_test.go @@ -36,7 +36,7 @@ func TestBestTime_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"pri_099889f14d114dfaae476569b395eade"}, @@ -71,7 +71,7 @@ func TestBestTime_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/betterstack/betterstack_test.go b/pkg/detectors/betterstack/betterstack_test.go index 45ff9579bff9..b5d7e35b5e96 100644 --- a/pkg/detectors/betterstack/betterstack_test.go +++ b/pkg/detectors/betterstack/betterstack_test.go @@ -38,7 +38,7 @@ func TestBetterStack_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } func getBetterStackToken() string{ return "ntJD0ER8QpuT0O1WqsclApO2" } `, @@ -76,7 +76,7 @@ func TestBetterStack_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } func getBetterStackToken() string{ return "DyntJD0ER8QpuT0O1WqsclApO2" } `, diff --git a/pkg/detectors/billomat/billomat_test.go b/pkg/detectors/billomat/billomat_test.go index 0aa00263df0d..587e289ce55a 100644 --- a/pkg/detectors/billomat/billomat_test.go +++ b/pkg/detectors/billomat/billomat_test.go @@ -38,7 +38,7 @@ func TestBilloMat_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // Check response status if resp.StatusCode == http.StatusOK { diff --git a/pkg/detectors/bingsubscriptionkey/bingsubscriptionkey_test.go b/pkg/detectors/bingsubscriptionkey/bingsubscriptionkey_test.go index 52a8a61d1751..2122f6a0a5e2 100644 --- a/pkg/detectors/bingsubscriptionkey/bingsubscriptionkey_test.go +++ b/pkg/detectors/bingsubscriptionkey/bingsubscriptionkey_test.go @@ -39,7 +39,7 @@ func TestBingsubscriptionkey_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() }`, want: []string{"89017d414ed64edb9c776d4a52102b9a"}, }, @@ -77,7 +77,7 @@ func TestBingsubscriptionkey_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() }`, want: []string{}, }, diff --git a/pkg/detectors/bitbar/bitbar_test.go b/pkg/detectors/bitbar/bitbar_test.go index a598ef4aaf6d..6b643a7332ab 100644 --- a/pkg/detectors/bitbar/bitbar_test.go +++ b/pkg/detectors/bitbar/bitbar_test.go @@ -42,7 +42,7 @@ func TestBitBar_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"64pq66z15thg8fh3acd00l35lpyg7c82"}, @@ -83,7 +83,7 @@ func TestBitBar_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/bitcoinaverage/bitcoinaverage_test.go b/pkg/detectors/bitcoinaverage/bitcoinaverage_test.go index d92960ca6355..9f2499802e01 100644 --- a/pkg/detectors/bitcoinaverage/bitcoinaverage_test.go +++ b/pkg/detectors/bitcoinaverage/bitcoinaverage_test.go @@ -43,7 +43,7 @@ func TestBitCoinAverage_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"WZizqeWvRnhZmFlpc5pMc92NP1Du19wxxpd5zjsYY8F"}, @@ -85,7 +85,7 @@ func TestBitCoinAverage_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/bitlyaccesstoken/bitlyaccesstoken_test.go b/pkg/detectors/bitlyaccesstoken/bitlyaccesstoken_test.go index a79913f78481..4a17e192d977 100644 --- a/pkg/detectors/bitlyaccesstoken/bitlyaccesstoken_test.go +++ b/pkg/detectors/bitlyaccesstoken/bitlyaccesstoken_test.go @@ -39,7 +39,7 @@ func TestBitlyAccessToken_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"2xN7puShxzNf5fZleQthTg305lKr7KrbW95D3gSD"}, @@ -77,7 +77,7 @@ func TestBitlyAccessToken_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/bitmex/bitmex_test.go b/pkg/detectors/bitmex/bitmex_test.go index 209e1afd253b..9e90b3bfc4e7 100644 --- a/pkg/detectors/bitmex/bitmex_test.go +++ b/pkg/detectors/bitmex/bitmex_test.go @@ -46,7 +46,7 @@ func TestBitmex_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"EPwUIxOIveS463D_2O9LFgkzW_HlMtrmELzXm4bSlWv49JLcgvg5hvu467WbbnpmoEA-RjrY"}, @@ -91,7 +91,7 @@ func TestBitmex_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/blazemeter/blazemeter_test.go b/pkg/detectors/blazemeter/blazemeter_test.go index 2f5d6f45d381..61362cd85d4c 100644 --- a/pkg/detectors/blazemeter/blazemeter_test.go +++ b/pkg/detectors/blazemeter/blazemeter_test.go @@ -39,7 +39,7 @@ func TestBlazeMeter_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"sjbuxa3m-vs4n-ykl8-8jpv-i09hdidciolp"}, @@ -77,7 +77,7 @@ func TestBlazeMeter_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/blitapp/blitapp_test.go b/pkg/detectors/blitapp/blitapp_test.go index a759f7949e69..fe0a86aac375 100644 --- a/pkg/detectors/blitapp/blitapp_test.go +++ b/pkg/detectors/blitapp/blitapp_test.go @@ -39,7 +39,7 @@ func TestBlitApp_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"I_MncTA8nlFcqlBCakI5vwkwFD4_zRUYZKt8hyd"}, @@ -77,7 +77,7 @@ func TestBlitApp_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/blocknative/blocknative_test.go b/pkg/detectors/blocknative/blocknative_test.go index 406bacafc1d9..6b34453c1e20 100644 --- a/pkg/detectors/blocknative/blocknative_test.go +++ b/pkg/detectors/blocknative/blocknative_test.go @@ -39,7 +39,7 @@ func TestBlockNative_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"76e50995-059f-3d1a-af8e-cc85fc05eb03"}, @@ -77,7 +77,7 @@ func TestBlockNative_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/blogger/blogger_test.go b/pkg/detectors/blogger/blogger_test.go index c7586c90f6e1..dce3c7a1c2ea 100644 --- a/pkg/detectors/blogger/blogger_test.go +++ b/pkg/detectors/blogger/blogger_test.go @@ -34,7 +34,7 @@ func TestBlogger_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // Check response status if resp.StatusCode == http.StatusOK { @@ -74,7 +74,7 @@ func TestBlogger_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // Check response status if resp.StatusCode == http.StatusOK { diff --git a/pkg/detectors/boostnote/boostnote_test.go b/pkg/detectors/boostnote/boostnote_test.go index 871e2cabf674..223a85312b2a 100644 --- a/pkg/detectors/boostnote/boostnote_test.go +++ b/pkg/detectors/boostnote/boostnote_test.go @@ -39,7 +39,7 @@ func TestBoostNote_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"fb1026ac5994e3ad01799fe040289317ba2594a20e9e45307a143be82b49d213"}, @@ -77,7 +77,7 @@ func TestBoostNote_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/borgbase/borgbase_test.go b/pkg/detectors/borgbase/borgbase_test.go index 603979627532..628f54991862 100644 --- a/pkg/detectors/borgbase/borgbase_test.go +++ b/pkg/detectors/borgbase/borgbase_test.go @@ -40,7 +40,7 @@ func TestBorgBase_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"FoHclCFSi_aV09jowJQ4RUF_MiqW6ioqq6_OcyB0PFlV-mQ1yoFjk5JLlxbzRUzKTA6vsfR8wq6TNc83rtNKlkD092Sj1c9CbPVBXlHksy.sT2I/so6bMGdPcqxzbjrxYgAUiORgqJDeTet4gKOQlZpt"}, @@ -79,7 +79,7 @@ func TestBorgBase_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/braintreepayments/braintreepayments.go b/pkg/detectors/braintreepayments/braintreepayments.go index 74578caec888..9704331bd9a8 100644 --- a/pkg/detectors/braintreepayments/braintreepayments.go +++ b/pkg/detectors/braintreepayments/braintreepayments.go @@ -113,7 +113,7 @@ func verifyBraintree(ctx context.Context, client *http.Client, url, pubKey, priv }() bodyString := string(bodyBytes) - if !(res.StatusCode == http.StatusOK) { + if res.StatusCode != http.StatusOK { return false, fmt.Errorf("unexpected HTTP response status %d", res.StatusCode) } diff --git a/pkg/detectors/braintreepayments/braintreepayments_test.go b/pkg/detectors/braintreepayments/braintreepayments_test.go index 6c5ea244dfa5..281fc62187a9 100644 --- a/pkg/detectors/braintreepayments/braintreepayments_test.go +++ b/pkg/detectors/braintreepayments/braintreepayments_test.go @@ -40,7 +40,7 @@ func TestBrainTreePayments_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"f7b3cb83a7fdb915a71ce17ab8a903cc"}, @@ -79,7 +79,7 @@ func TestBrainTreePayments_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/brandfetch/v1/brandfetch_test.go b/pkg/detectors/brandfetch/v1/brandfetch_test.go index b06e6ea82586..f2846dd35a85 100644 --- a/pkg/detectors/brandfetch/v1/brandfetch_test.go +++ b/pkg/detectors/brandfetch/v1/brandfetch_test.go @@ -39,7 +39,7 @@ func TestBrandFetch_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"uHOAdwfQ7sD2yOpur72UqyUeIqnFwILOIlEPyBtJ"}, @@ -77,7 +77,7 @@ func TestBrandFetch_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/brandfetch/v2/brandfetch.go b/pkg/detectors/brandfetch/v2/brandfetch.go index 2dacb7ddd4d1..ed9ff4828634 100644 --- a/pkg/detectors/brandfetch/v2/brandfetch.go +++ b/pkg/detectors/brandfetch/v2/brandfetch.go @@ -95,7 +95,7 @@ func VerifyMatch(ctx context.Context, client *http.Client, token string) (bool, if err != nil { return false, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() switch resp.StatusCode { case http.StatusOK: diff --git a/pkg/detectors/brandfetch/v2/brandfetch_test.go b/pkg/detectors/brandfetch/v2/brandfetch_test.go index e991b6c929cb..b6c22fb3e54f 100644 --- a/pkg/detectors/brandfetch/v2/brandfetch_test.go +++ b/pkg/detectors/brandfetch/v2/brandfetch_test.go @@ -49,7 +49,7 @@ func TestBrandFetch_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // Check response status if resp.StatusCode == http.StatusOK { @@ -104,7 +104,7 @@ func TestBrandFetch_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/browserstack/browserstack.go b/pkg/detectors/browserstack/browserstack.go index 0804cbb630a0..1bae92601d08 100644 --- a/pkg/detectors/browserstack/browserstack.go +++ b/pkg/detectors/browserstack/browserstack.go @@ -106,7 +106,7 @@ func verifyBrowserStackCredentials(ctx context.Context, client *http.Client, use if err != nil { return false, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode == http.StatusOK { return true, nil diff --git a/pkg/detectors/browserstack/browserstack_test.go b/pkg/detectors/browserstack/browserstack_test.go index 97478c7509ea..2493bb8d0a28 100644 --- a/pkg/detectors/browserstack/browserstack_test.go +++ b/pkg/detectors/browserstack/browserstack_test.go @@ -44,7 +44,7 @@ func TestBrowserStack_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{ @@ -92,7 +92,7 @@ func TestBrowserStack_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/browshot/browshot_test.go b/pkg/detectors/browshot/browshot_test.go index 16ba249ba819..6fae5960d3a9 100644 --- a/pkg/detectors/browshot/browshot_test.go +++ b/pkg/detectors/browshot/browshot_test.go @@ -36,7 +36,7 @@ func TestBrowShot_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // Check response status if resp.StatusCode == http.StatusOK { @@ -78,7 +78,7 @@ func TestBrowShot_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/bscscan/bscscan_test.go b/pkg/detectors/bscscan/bscscan_test.go index e5649eab933a..1614a61a419a 100644 --- a/pkg/detectors/bscscan/bscscan_test.go +++ b/pkg/detectors/bscscan/bscscan_test.go @@ -36,7 +36,7 @@ func TestBscScan_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"HYZHPP4PBYXCOZAVK4FH55W4MRHYLALPU1"}, @@ -71,7 +71,7 @@ func TestBscScan_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/buddyns/buddyns_test.go b/pkg/detectors/buddyns/buddyns_test.go index 078d9f7d6644..014df7627d2d 100644 --- a/pkg/detectors/buddyns/buddyns_test.go +++ b/pkg/detectors/buddyns/buddyns_test.go @@ -39,7 +39,7 @@ func TestBuddyNs_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"kkmvdiolccw4v0tue4lu7l7kmnnb4ao8z25ezink"}, @@ -77,7 +77,7 @@ func TestBuddyNs_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/budibase/budibase_test.go b/pkg/detectors/budibase/budibase_test.go index e5aa858a833c..130e757b5046 100644 --- a/pkg/detectors/budibase/budibase_test.go +++ b/pkg/detectors/budibase/budibase_test.go @@ -38,7 +38,7 @@ func TestBudiBase_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"b256def166fcdf4a429a1e83175105d5-fd36f3da1e934bf533cd0e68dbb80ed6a42e1178bd4200428d83e876e7d05e40b21e3a68888f826d"}, @@ -75,7 +75,7 @@ func TestBudiBase_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/bugherd/bugherd_test.go b/pkg/detectors/bugherd/bugherd_test.go index c6088709adde..756a934cb41d 100644 --- a/pkg/detectors/bugherd/bugherd_test.go +++ b/pkg/detectors/bugherd/bugherd_test.go @@ -39,7 +39,7 @@ func TestBugHerd_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"fisy6bbu6il4x96bekx587"}, @@ -77,7 +77,7 @@ func TestBugHerd_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/bugsnag/bugsnag_test.go b/pkg/detectors/bugsnag/bugsnag_test.go index 7b31971b201c..0b31beabca12 100644 --- a/pkg/detectors/bugsnag/bugsnag_test.go +++ b/pkg/detectors/bugsnag/bugsnag_test.go @@ -39,7 +39,7 @@ func TestBugSnag_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"wz9450iu-iewm-jonx-eab8-0ibxwadddm8i"}, @@ -77,7 +77,7 @@ func TestBugSnag_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/buildkite/v1/buildkite_test.go b/pkg/detectors/buildkite/v1/buildkite_test.go index e4aa9d298040..7137736c9b7a 100644 --- a/pkg/detectors/buildkite/v1/buildkite_test.go +++ b/pkg/detectors/buildkite/v1/buildkite_test.go @@ -39,7 +39,7 @@ func TestBuildKite_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"kimu4axq3jxxdj8un0kpo3ua2ucr05zmhh4de0r6"}, @@ -77,7 +77,7 @@ func TestBuildKite_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/buildkite/v2/buildkite_test.go b/pkg/detectors/buildkite/v2/buildkite_test.go index c7eeb19f6ca2..5f2b466a76f3 100644 --- a/pkg/detectors/buildkite/v2/buildkite_test.go +++ b/pkg/detectors/buildkite/v2/buildkite_test.go @@ -39,7 +39,7 @@ func TestBuildKiteV2_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"bkua_hqlh73m51jtho0jh12wcf2758c8fcdbv05z023ly"}, @@ -77,7 +77,7 @@ func TestBuildKiteV2_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/bulbul/bulbul_test.go b/pkg/detectors/bulbul/bulbul_test.go index e9f4ced115f8..013ba9998e85 100644 --- a/pkg/detectors/bulbul/bulbul_test.go +++ b/pkg/detectors/bulbul/bulbul_test.go @@ -36,7 +36,7 @@ func TestBulBul_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"3kx19qpx748ldb75lsjicbs6ipit6ssm"}, @@ -71,7 +71,7 @@ func TestBulBul_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/bulksms/bulksms_test.go b/pkg/detectors/bulksms/bulksms_test.go index 792b8cfcc077..a33b5c2d5f7b 100644 --- a/pkg/detectors/bulksms/bulksms_test.go +++ b/pkg/detectors/bulksms/bulksms_test.go @@ -41,7 +41,7 @@ func TestBulkSMS_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"QGxPqRyzvt%xEKcV&#ePJGn)k0d9a381A26C47380B85F2DB572314-ACBDC267B-8"}, @@ -81,7 +81,7 @@ func TestBulkSMS_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/buttercms/buttercms_test.go b/pkg/detectors/buttercms/buttercms_test.go index 9fbd036921ac..b66c7f350c12 100644 --- a/pkg/detectors/buttercms/buttercms_test.go +++ b/pkg/detectors/buttercms/buttercms_test.go @@ -36,7 +36,7 @@ func TestButterCMS_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: []string{"l7psk7wkedkpiyp4jrx5fjdnno8c89243of6yde8"}, @@ -71,7 +71,7 @@ func TestButterCMS_Pattern(t *testing.T) { // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } `, want: nil, diff --git a/pkg/detectors/calendarific/calendarific.go b/pkg/detectors/calendarific/calendarific.go index 6aaa64cf2f00..7fbd77760a9c 100644 --- a/pkg/detectors/calendarific/calendarific.go +++ b/pkg/detectors/calendarific/calendarific.go @@ -52,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/calendlyapikey/calendlyapikey.go b/pkg/detectors/calendlyapikey/calendlyapikey.go index 8323f930fcd3..5a4684b69f47 100644 --- a/pkg/detectors/calendlyapikey/calendlyapikey.go +++ b/pkg/detectors/calendlyapikey/calendlyapikey.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/calorieninja/calorieninja.go b/pkg/detectors/calorieninja/calorieninja.go index fd93a5689581..81c4f0201cd7 100644 --- a/pkg/detectors/calorieninja/calorieninja.go +++ b/pkg/detectors/calorieninja/calorieninja.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-Api-Key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/campayn/campayn.go b/pkg/detectors/campayn/campayn.go index 9ea5e75b64da..8a4360eb11ef 100644 --- a/pkg/detectors/campayn/campayn.go +++ b/pkg/detectors/campayn/campayn.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", "TRUEREST apikey="+resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/cannyio/cannyio.go b/pkg/detectors/cannyio/cannyio.go index 2bbcc490843b..aa74f9f95f9d 100644 --- a/pkg/detectors/cannyio/cannyio.go +++ b/pkg/detectors/cannyio/cannyio.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/x-www-form-urlencoded") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/capsulecrm/capsulecrm.go b/pkg/detectors/capsulecrm/capsulecrm.go index 645d35820f6e..faf21d95d02e 100644 --- a/pkg/detectors/capsulecrm/capsulecrm.go +++ b/pkg/detectors/capsulecrm/capsulecrm.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/captaindata/v1/captaindata.go b/pkg/detectors/captaindata/v1/captaindata.go index 55b0316a463f..43881832322b 100644 --- a/pkg/detectors/captaindata/v1/captaindata.go +++ b/pkg/detectors/captaindata/v1/captaindata.go @@ -67,7 +67,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("x-api-key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/carboninterface/carboninterface.go b/pkg/detectors/carboninterface/carboninterface.go index 848b545917df..e02d76b092bf 100644 --- a/pkg/detectors/carboninterface/carboninterface.go +++ b/pkg/detectors/carboninterface/carboninterface.go @@ -56,7 +56,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/cashboard/cashboard.go b/pkg/detectors/cashboard/cashboard.go index 2fda6ef13904..8e7b08da1bc2 100644 --- a/pkg/detectors/cashboard/cashboard.go +++ b/pkg/detectors/cashboard/cashboard.go @@ -69,7 +69,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/caspio/caspio.go b/pkg/detectors/caspio/caspio.go index 3ae65f4d26be..137a490b3dc5 100644 --- a/pkg/detectors/caspio/caspio.go +++ b/pkg/detectors/caspio/caspio.go @@ -73,7 +73,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "text/plain") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/censys/censys.go b/pkg/detectors/censys/censys.go index 3db0f273c10f..3c311f2c6c32 100644 --- a/pkg/detectors/censys/censys.go +++ b/pkg/detectors/censys/censys.go @@ -63,7 +63,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.SetBasicAuth(userPatMatch, tokenPatMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/centralstationcrm/centralstationcrm.go b/pkg/detectors/centralstationcrm/centralstationcrm.go index 46127f3b715d..f5e22530e42c 100644 --- a/pkg/detectors/centralstationcrm/centralstationcrm.go +++ b/pkg/detectors/centralstationcrm/centralstationcrm.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-apikey", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/cexio/cexio.go b/pkg/detectors/cexio/cexio.go index 1cb92a6108eb..750fa854af73 100644 --- a/pkg/detectors/cexio/cexio.go +++ b/pkg/detectors/cexio/cexio.go @@ -88,7 +88,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/x-www-form-urlencoded") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() body, err := io.ReadAll(res.Body) if err != nil { diff --git a/pkg/detectors/chartmogul/chartmogul.go b/pkg/detectors/chartmogul/chartmogul.go index d8f612a58689..a4a52ea05478 100644 --- a/pkg/detectors/chartmogul/chartmogul.go +++ b/pkg/detectors/chartmogul/chartmogul.go @@ -57,7 +57,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", sEnc)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/chatbot/chatbot.go b/pkg/detectors/chatbot/chatbot.go index cb6b5f7a801a..60d54bd175ef 100644 --- a/pkg/detectors/chatbot/chatbot.go +++ b/pkg/detectors/chatbot/chatbot.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/chatfule/chatfule.go b/pkg/detectors/chatfule/chatfule.go index 6319dda2917b..91772f4ec0e1 100644 --- a/pkg/detectors/chatfule/chatfule.go +++ b/pkg/detectors/chatfule/chatfule.go @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/checio/checio.go b/pkg/detectors/checio/checio.go index 981e5abf29ce..587dc216b44a 100644 --- a/pkg/detectors/checio/checio.go +++ b/pkg/detectors/checio/checio.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-Authorization", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/checklyhq/checklyhq.go b/pkg/detectors/checklyhq/checklyhq.go index a9d6c3bc81d9..6f81656467e2 100644 --- a/pkg/detectors/checklyhq/checklyhq.go +++ b/pkg/detectors/checklyhq/checklyhq.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/checkout/checkout.go b/pkg/detectors/checkout/checkout.go index 879005ca8d02..84f2234e8713 100644 --- a/pkg/detectors/checkout/checkout.go +++ b/pkg/detectors/checkout/checkout.go @@ -66,7 +66,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/checkvist/checkvist.go b/pkg/detectors/checkvist/checkvist.go index 94f9260d0dd2..30c5b8731f23 100644 --- a/pkg/detectors/checkvist/checkvist.go +++ b/pkg/detectors/checkvist/checkvist.go @@ -71,7 +71,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/x-www-form-urlencoded") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/cicero/cicero.go b/pkg/detectors/cicero/cicero.go index 88271e94d049..801ee6dfac67 100644 --- a/pkg/detectors/cicero/cicero.go +++ b/pkg/detectors/cicero/cicero.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/clarifai/clarifai.go b/pkg/detectors/clarifai/clarifai.go index a8feaf6c1c09..725c8da5292a 100644 --- a/pkg/detectors/clarifai/clarifai.go +++ b/pkg/detectors/clarifai/clarifai.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Key %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } @@ -69,7 +69,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Key %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/clearbit/clearbit.go b/pkg/detectors/clearbit/clearbit.go index 590cf028c0ae..e149a4fc1428 100644 --- a/pkg/detectors/clearbit/clearbit.go +++ b/pkg/detectors/clearbit/clearbit.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/clicksendsms/clicksendsms.go b/pkg/detectors/clicksendsms/clicksendsms.go index 51e002c05e37..ef6a9b68a7d4 100644 --- a/pkg/detectors/clicksendsms/clicksendsms.go +++ b/pkg/detectors/clicksendsms/clicksendsms.go @@ -69,7 +69,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", sEnc)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/cliengo/cliengo.go b/pkg/detectors/cliengo/cliengo.go index e9dbebab9752..421a1dd5e8e3 100644 --- a/pkg/detectors/cliengo/cliengo.go +++ b/pkg/detectors/cliengo/cliengo.go @@ -52,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/clinchpad/clinchpad.go b/pkg/detectors/clinchpad/clinchpad.go index 60ed04968a44..ab8f6d4d0f74 100644 --- a/pkg/detectors/clinchpad/clinchpad.go +++ b/pkg/detectors/clinchpad/clinchpad.go @@ -57,7 +57,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", sEnc)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/clockify/clockify.go b/pkg/detectors/clockify/clockify.go index 103fe4e6e4da..ed19afcb6861 100644 --- a/pkg/detectors/clockify/clockify.go +++ b/pkg/detectors/clockify/clockify.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-Api-Key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/clockworksms/clockworksms.go b/pkg/detectors/clockworksms/clockworksms.go index 4a167e5e7089..a3996e5fdb5b 100644 --- a/pkg/detectors/clockworksms/clockworksms.go +++ b/pkg/detectors/clockworksms/clockworksms.go @@ -65,7 +65,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("access_token", tokenRes) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/closecrm/close.go b/pkg/detectors/closecrm/close.go index 41df5ec709af..aa7f579f55e5 100644 --- a/pkg/detectors/closecrm/close.go +++ b/pkg/detectors/closecrm/close.go @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/cloudconvert/cloudconvert.go b/pkg/detectors/cloudconvert/cloudconvert.go index 4d62b4fe2c70..0c2e48e93104 100644 --- a/pkg/detectors/cloudconvert/cloudconvert.go +++ b/pkg/detectors/cloudconvert/cloudconvert.go @@ -60,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/cloudelements/cloudelements.go b/pkg/detectors/cloudelements/cloudelements.go index dfa788c86803..78e5f3b9357c 100644 --- a/pkg/detectors/cloudelements/cloudelements.go +++ b/pkg/detectors/cloudelements/cloudelements.go @@ -66,7 +66,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("User %s, Organization %s", resMatch, resOrgMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/cloudflareapitoken/cloudflareapitoken.go b/pkg/detectors/cloudflareapitoken/cloudflareapitoken.go index 7645d81d7247..e848cc3e8c46 100644 --- a/pkg/detectors/cloudflareapitoken/cloudflareapitoken.go +++ b/pkg/detectors/cloudflareapitoken/cloudflareapitoken.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/cloudflareglobalapikey/cloudflareglobalapikey.go b/pkg/detectors/cloudflareglobalapikey/cloudflareglobalapikey.go index ac2d268cdd4c..9ab63e450644 100644 --- a/pkg/detectors/cloudflareglobalapikey/cloudflareglobalapikey.go +++ b/pkg/detectors/cloudflareglobalapikey/cloudflareglobalapikey.go @@ -70,7 +70,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/cloudimage/cloudimage.go b/pkg/detectors/cloudimage/cloudimage.go index a992e427667d..2cf168664905 100644 --- a/pkg/detectors/cloudimage/cloudimage.go +++ b/pkg/detectors/cloudimage/cloudimage.go @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-Client-Key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/cloudmersive/cloudmersive.go b/pkg/detectors/cloudmersive/cloudmersive.go index 2589a73b16e5..a7c626c4b49d 100644 --- a/pkg/detectors/cloudmersive/cloudmersive.go +++ b/pkg/detectors/cloudmersive/cloudmersive.go @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Apikey", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/cloudplan/cloudplan.go b/pkg/detectors/cloudplan/cloudplan.go index cba92389be9a..817998bdfac1 100644 --- a/pkg/detectors/cloudplan/cloudplan.go +++ b/pkg/detectors/cloudplan/cloudplan.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("session_id", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/cloudsmith/cloudsmith.go b/pkg/detectors/cloudsmith/cloudsmith.go index a0278c16dd21..e400c7964b67 100644 --- a/pkg/detectors/cloudsmith/cloudsmith.go +++ b/pkg/detectors/cloudsmith/cloudsmith.go @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-Api-Key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { var r response if err := json.NewDecoder(res.Body).Decode(&r); err != nil { diff --git a/pkg/detectors/cloverly/cloverly.go b/pkg/detectors/cloverly/cloverly.go index d9f22756436b..4a090286fc86 100644 --- a/pkg/detectors/cloverly/cloverly.go +++ b/pkg/detectors/cloverly/cloverly.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/cloze/cloze.go b/pkg/detectors/cloze/cloze.go index eb22cd275780..ca821d8080b9 100644 --- a/pkg/detectors/cloze/cloze.go +++ b/pkg/detectors/cloze/cloze.go @@ -66,7 +66,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/clustdoc/clustdoc.go b/pkg/detectors/clustdoc/clustdoc.go index fbe50ce134d5..9fcd611fe759 100644 --- a/pkg/detectors/clustdoc/clustdoc.go +++ b/pkg/detectors/clustdoc/clustdoc.go @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/coda/coda.go b/pkg/detectors/coda/coda.go index e89e51ab5e95..2d29c2571832 100644 --- a/pkg/detectors/coda/coda.go +++ b/pkg/detectors/coda/coda.go @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode == 401 { diff --git a/pkg/detectors/codacy/codacy.go b/pkg/detectors/codacy/codacy.go index 3b6f5abf3830..562c155451ee 100644 --- a/pkg/detectors/codacy/codacy.go +++ b/pkg/detectors/codacy/codacy.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("api-token", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/codeclimate/codeclimate.go b/pkg/detectors/codeclimate/codeclimate.go index fac992d69953..9875fd3b56d6 100644 --- a/pkg/detectors/codeclimate/codeclimate.go +++ b/pkg/detectors/codeclimate/codeclimate.go @@ -62,7 +62,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Token token=%s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { var r response if err := json.NewDecoder(res.Body).Decode(&r); err != nil { diff --git a/pkg/detectors/codemagic/codemagic.go b/pkg/detectors/codemagic/codemagic.go index 63f3afed9987..c22cd0591e63 100644 --- a/pkg/detectors/codemagic/codemagic.go +++ b/pkg/detectors/codemagic/codemagic.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("x-auth-token", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/codequiry/codequiry.go b/pkg/detectors/codequiry/codequiry.go index d8d191ef2b62..7b3250f8b02d 100644 --- a/pkg/detectors/codequiry/codequiry.go +++ b/pkg/detectors/codequiry/codequiry.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("apikey", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/coinapi/coinapi.go b/pkg/detectors/coinapi/coinapi.go index 1732055a3db5..9d822b1c7618 100644 --- a/pkg/detectors/coinapi/coinapi.go +++ b/pkg/detectors/coinapi/coinapi.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-CoinAPI-Key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/coinlayer/coinlayer.go b/pkg/detectors/coinlayer/coinlayer.go index 71df5549c7cb..2fdcadf4bbbd 100644 --- a/pkg/detectors/coinlayer/coinlayer.go +++ b/pkg/detectors/coinlayer/coinlayer.go @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err == nil { bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `"success": true`) || strings.Contains(bodyString, `"info":"Access Restricted - Your current Subscription Plan does not support HTTPS Encryption."`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { s1.Verified = true diff --git a/pkg/detectors/coinlib/coinlib.go b/pkg/detectors/coinlib/coinlib.go index 8dfda739e1dd..a023bb75e9e6 100644 --- a/pkg/detectors/coinlib/coinlib.go +++ b/pkg/detectors/coinlib/coinlib.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/collect2/collect2.go b/pkg/detectors/collect2/collect2.go index 851142d7a1e1..753914bc009d 100644 --- a/pkg/detectors/collect2/collect2.go +++ b/pkg/detectors/collect2/collect2.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/column/column.go b/pkg/detectors/column/column.go index cf8173a422f8..a4e083a5c6d1 100644 --- a/pkg/detectors/column/column.go +++ b/pkg/detectors/column/column.go @@ -56,7 +56,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", base64.StdEncoding.EncodeToString([]byte(resMatch)))) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else { diff --git a/pkg/detectors/commercejs/commercejs.go b/pkg/detectors/commercejs/commercejs.go index 4c5209d91a12..82b00667318e 100644 --- a/pkg/detectors/commercejs/commercejs.go +++ b/pkg/detectors/commercejs/commercejs.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-Authorization", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/commodities/commodities.go b/pkg/detectors/commodities/commodities.go index 6dc0e68844e4..a0a6fde5fde9 100644 --- a/pkg/detectors/commodities/commodities.go +++ b/pkg/detectors/commodities/commodities.go @@ -61,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `"success":true`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { s1.Verified = true diff --git a/pkg/detectors/companyhub/companyhub.go b/pkg/detectors/companyhub/companyhub.go index e6fca68f27f8..f1945be52b8c 100644 --- a/pkg/detectors/companyhub/companyhub.go +++ b/pkg/detectors/companyhub/companyhub.go @@ -66,7 +66,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/confluent/confluent.go b/pkg/detectors/confluent/confluent.go index 530e3c4f3e6d..ae4157ef7914 100644 --- a/pkg/detectors/confluent/confluent.go +++ b/pkg/detectors/confluent/confluent.go @@ -68,7 +68,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", sEnc)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/contentfulpersonalaccesstoken/contentfulpersonalaccesstoken.go b/pkg/detectors/contentfulpersonalaccesstoken/contentfulpersonalaccesstoken.go index 30525dafb663..8926787a0cef 100644 --- a/pkg/detectors/contentfulpersonalaccesstoken/contentfulpersonalaccesstoken.go +++ b/pkg/detectors/contentfulpersonalaccesstoken/contentfulpersonalaccesstoken.go @@ -52,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", keyRes)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/conversiontools/conversiontools.go b/pkg/detectors/conversiontools/conversiontools.go index b0f9656c6025..d6393e18527a 100644 --- a/pkg/detectors/conversiontools/conversiontools.go +++ b/pkg/detectors/conversiontools/conversiontools.go @@ -56,7 +56,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/convertapi/convertapi.go b/pkg/detectors/convertapi/convertapi.go index b70e2c90ecab..0430c171eae4 100644 --- a/pkg/detectors/convertapi/convertapi.go +++ b/pkg/detectors/convertapi/convertapi.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/convertkit/convertkit.go b/pkg/detectors/convertkit/convertkit.go index cc23ebfabae2..122baa87c004 100644 --- a/pkg/detectors/convertkit/convertkit.go +++ b/pkg/detectors/convertkit/convertkit.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/convier/convier.go b/pkg/detectors/convier/convier.go index ac890a525a55..9fcf405ba52e 100644 --- a/pkg/detectors/convier/convier.go +++ b/pkg/detectors/convier/convier.go @@ -64,7 +64,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `"error":false`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { s1.Verified = true diff --git a/pkg/detectors/countrylayer/countrylayer.go b/pkg/detectors/countrylayer/countrylayer.go index 245841d59682..400237f03b7f 100644 --- a/pkg/detectors/countrylayer/countrylayer.go +++ b/pkg/detectors/countrylayer/countrylayer.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/courier/courier.go b/pkg/detectors/courier/courier.go index 8ca8f52f7242..2afa8b9bd240 100644 --- a/pkg/detectors/courier/courier.go +++ b/pkg/detectors/courier/courier.go @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/coveralls/coveralls.go b/pkg/detectors/coveralls/coveralls.go index 2e6d4f1ef211..43f733040d4c 100644 --- a/pkg/detectors/coveralls/coveralls.go +++ b/pkg/detectors/coveralls/coveralls.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("token %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/craftmypdf/craftmypdf.go b/pkg/detectors/craftmypdf/craftmypdf.go index b4933bc891fa..afb26da9f4e1 100644 --- a/pkg/detectors/craftmypdf/craftmypdf.go +++ b/pkg/detectors/craftmypdf/craftmypdf.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-API-KEY", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/crowdin/crowdin.go b/pkg/detectors/crowdin/crowdin.go index 670f1770552b..8944bf6d7433 100644 --- a/pkg/detectors/crowdin/crowdin.go +++ b/pkg/detectors/crowdin/crowdin.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/cryptocompare/cryptocompare.go b/pkg/detectors/cryptocompare/cryptocompare.go index f8a5133dc67f..782628ce6440 100644 --- a/pkg/detectors/cryptocompare/cryptocompare.go +++ b/pkg/detectors/cryptocompare/cryptocompare.go @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } bodyString := string(bodyBytes) errCode := strings.Contains(bodyString, `"Response":"Success"`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if errCode { s1.Verified = true diff --git a/pkg/detectors/currencycloud/currencycloud.go b/pkg/detectors/currencycloud/currencycloud.go index 77e89fd424f6..9c3f90a59c7c 100644 --- a/pkg/detectors/currencycloud/currencycloud.go +++ b/pkg/detectors/currencycloud/currencycloud.go @@ -67,7 +67,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { continue diff --git a/pkg/detectors/currencyfreaks/currencyfreaks.go b/pkg/detectors/currencyfreaks/currencyfreaks.go index f7f782d6e042..c82272e2894c 100644 --- a/pkg/detectors/currencyfreaks/currencyfreaks.go +++ b/pkg/detectors/currencyfreaks/currencyfreaks.go @@ -52,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/currencylayer/currencylayer.go b/pkg/detectors/currencylayer/currencylayer.go index d4e230783fce..ede0239182c1 100644 --- a/pkg/detectors/currencylayer/currencylayer.go +++ b/pkg/detectors/currencylayer/currencylayer.go @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err2 == nil { bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `"success": true`) || strings.Contains(bodyString, `"info":"Access Restricted - Your current Subscription Plan does not support HTTPS Encryption."`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { s1.Verified = true diff --git a/pkg/detectors/currencyscoop/currencyscoop.go b/pkg/detectors/currencyscoop/currencyscoop.go index 2808a4c2db4b..a9c511a524c0 100644 --- a/pkg/detectors/currencyscoop/currencyscoop.go +++ b/pkg/detectors/currencyscoop/currencyscoop.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/customerguru/customerguru.go b/pkg/detectors/customerguru/customerguru.go index c235ea817e87..e82873834e88 100644 --- a/pkg/detectors/customerguru/customerguru.go +++ b/pkg/detectors/customerguru/customerguru.go @@ -64,7 +64,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/customerio/customerio.go b/pkg/detectors/customerio/customerio.go index cc600eb0ec3f..c1dea10b1d63 100644 --- a/pkg/detectors/customerio/customerio.go +++ b/pkg/detectors/customerio/customerio.go @@ -70,7 +70,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", sEnc)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/d7network/d7network.go b/pkg/detectors/d7network/d7network.go index 14b17d79b3f7..36f107de9d41 100644 --- a/pkg/detectors/d7network/d7network.go +++ b/pkg/detectors/d7network/d7network.go @@ -50,7 +50,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", "Basic "+resMatch) res, err := detectors.DetectorHttpClientWithNoLocalAddresses.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/dailyco/dailyco.go b/pkg/detectors/dailyco/dailyco.go index 1eae0ff5f3d4..0c77fcae5b6f 100644 --- a/pkg/detectors/dailyco/dailyco.go +++ b/pkg/detectors/dailyco/dailyco.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/dandelion/dandelion.go b/pkg/detectors/dandelion/dandelion.go index 6f1d83dc9da7..a498cafc60e5 100644 --- a/pkg/detectors/dandelion/dandelion.go +++ b/pkg/detectors/dandelion/dandelion.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/dareboost/dareboost.go b/pkg/detectors/dareboost/dareboost.go index 2dcc5128f89b..049297aed86e 100644 --- a/pkg/detectors/dareboost/dareboost.go +++ b/pkg/detectors/dareboost/dareboost.go @@ -64,7 +64,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `"status":200`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { s1.Verified = true diff --git a/pkg/detectors/databox/databox.go b/pkg/detectors/databox/databox.go index 441c1b706fab..ea1cb8f14b6c 100644 --- a/pkg/detectors/databox/databox.go +++ b/pkg/detectors/databox/databox.go @@ -67,7 +67,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", sEnc)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/datadogtoken/datadogtoken.go b/pkg/detectors/datadogtoken/datadogtoken.go index f5e9e68ea894..593d42ece5c9 100644 --- a/pkg/detectors/datadogtoken/datadogtoken.go +++ b/pkg/detectors/datadogtoken/datadogtoken.go @@ -139,7 +139,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("DD-APPLICATION-KEY", resAppMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true s1.SecretParts = map[string]string{"api_key": resApiMatch, "app_key": resAppMatch, "endpoint": baseURL} diff --git a/pkg/detectors/datagov/datagov.go b/pkg/detectors/datagov/datagov.go index a5cb91f89393..8fe15d5ad20a 100644 --- a/pkg/detectors/datagov/datagov.go +++ b/pkg/detectors/datagov/datagov.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/debounce/debounce.go b/pkg/detectors/debounce/debounce.go index a2a535020447..12781f3e52e7 100644 --- a/pkg/detectors/debounce/debounce.go +++ b/pkg/detectors/debounce/debounce.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/deepai/deepai.go b/pkg/detectors/deepai/deepai.go index 686bd07bffef..befc7e70171a 100644 --- a/pkg/detectors/deepai/deepai.go +++ b/pkg/detectors/deepai/deepai.go @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err != nil { continue } - writer.Close() + _ = writer.Close() req, err := http.NewRequestWithContext(ctx, "POST", "https://api.deepai.org/api/text-tagging", bytes.NewReader(body.Bytes())) if err != nil { continue @@ -68,7 +68,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("api-key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/deepgram/deepgram.go b/pkg/detectors/deepgram/deepgram.go index 18e41438ed7e..92991cf73a67 100644 --- a/pkg/detectors/deepgram/deepgram.go +++ b/pkg/detectors/deepgram/deepgram.go @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Token %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/delighted/delighted.go b/pkg/detectors/delighted/delighted.go index fe8f42998709..748ec5e813ae 100644 --- a/pkg/detectors/delighted/delighted.go +++ b/pkg/detectors/delighted/delighted.go @@ -62,7 +62,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", sEnc)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/demio/demio.go b/pkg/detectors/demio/demio.go index a94921fc83e4..b1ef8ffe72f5 100644 --- a/pkg/detectors/demio/demio.go +++ b/pkg/detectors/demio/demio.go @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/deno/denodeploy.go b/pkg/detectors/deno/denodeploy.go index 838fd3942af9..c0cc4a822a29 100644 --- a/pkg/detectors/deno/denodeploy.go +++ b/pkg/detectors/deno/denodeploy.go @@ -65,8 +65,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() - if res.StatusCode == 200 { + defer func() { _ = res.Body.Close() }() + switch res.StatusCode { + case 200: s1.Verified = true body, err := io.ReadAll(res.Body) @@ -82,9 +83,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } } } - } else if res.StatusCode == 401 { + case 401: // The secret is determinately not verified (nothing to do) - } else { + default: err = fmt.Errorf("unexpected HTTP response status %d", res.StatusCode) s1.SetVerificationError(err, token) } diff --git a/pkg/detectors/deputy/deputy.go b/pkg/detectors/deputy/deputy.go index 10e1fa4f9c40..1d27b4a122fc 100644 --- a/pkg/detectors/deputy/deputy.go +++ b/pkg/detectors/deputy/deputy.go @@ -61,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("OAuth %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/detectify/detectify.go b/pkg/detectors/detectify/detectify.go index 82484c723a9f..ba9c025300f6 100644 --- a/pkg/detectors/detectify/detectify.go +++ b/pkg/detectors/detectify/detectify.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-Detectify-Key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/detectlanguage/detectlanguage.go b/pkg/detectors/detectlanguage/detectlanguage.go index 55fefb6de6a5..10a04f91e580 100644 --- a/pkg/detectors/detectlanguage/detectlanguage.go +++ b/pkg/detectors/detectlanguage/detectlanguage.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/dfuse/dfuse.go b/pkg/detectors/dfuse/dfuse.go index c57bcc3f9923..408b35fb849d 100644 --- a/pkg/detectors/dfuse/dfuse.go +++ b/pkg/detectors/dfuse/dfuse.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/diffbot/diffbot.go b/pkg/detectors/diffbot/diffbot.go index 0b5385a08be2..63f77d4a6dcc 100644 --- a/pkg/detectors/diffbot/diffbot.go +++ b/pkg/detectors/diffbot/diffbot.go @@ -61,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err == nil { bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `"token":`) && strings.Contains(bodyString, `"planCredits":`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { s1.Verified = true diff --git a/pkg/detectors/diggernaut/diggernaut.go b/pkg/detectors/diggernaut/diggernaut.go index 13754ce1cbc9..4d28aadad84f 100644 --- a/pkg/detectors/diggernaut/diggernaut.go +++ b/pkg/detectors/diggernaut/diggernaut.go @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Token %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/digitaloceantoken/digitaloceantoken.go b/pkg/detectors/digitaloceantoken/digitaloceantoken.go index e60fd3df8d22..a248b00fff46 100644 --- a/pkg/detectors/digitaloceantoken/digitaloceantoken.go +++ b/pkg/detectors/digitaloceantoken/digitaloceantoken.go @@ -79,7 +79,7 @@ func verifyDigitalOceanToken(ctx context.Context, client *http.Client, token str if err != nil { return false, fmt.Errorf("failed to make request: %w", err) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() switch resp.StatusCode { case http.StatusOK: diff --git a/pkg/detectors/digitaloceanv2/digitaloceanv2.go b/pkg/detectors/digitaloceanv2/digitaloceanv2.go index b42117fe23aa..28254e7ac28d 100644 --- a/pkg/detectors/digitaloceanv2/digitaloceanv2.go +++ b/pkg/detectors/digitaloceanv2/digitaloceanv2.go @@ -60,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result // Check if the token is a refresh token or an access token switch { case strings.HasPrefix(token, "dor_v1_"): - verified, verificationErr, newAccessToken := verifyRefreshToken(ctx, client, token) + verified, newAccessToken, verificationErr := verifyRefreshToken(ctx, client, token) s1.SetVerificationError(verificationErr) s1.Verified = verified if s1.Verified { @@ -90,42 +90,42 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result // If the token is valid, it returns the new access token and no error. // If the token is invalid/expired, it returns an empty string and no error. // If an error is encountered, it returns an empty string along and the error. -func verifyRefreshToken(ctx context.Context, client *http.Client, token string) (bool, error, string) { +func verifyRefreshToken(ctx context.Context, client *http.Client, token string) (bool, string, error) { // Ref: https://docs.digitalocean.com/reference/api/oauth/ url := "https://cloud.digitalocean.com/v1/oauth/token?grant_type=refresh_token&refresh_token=" + token req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, nil) if err != nil { - return false, fmt.Errorf("failed to create request: %w", err), "" + return false, "", fmt.Errorf("failed to create request: %w", err) } res, err := client.Do(req) if err != nil { - return false, fmt.Errorf("failed to make request: %w", err), "" + return false, "", fmt.Errorf("failed to make request: %w", err) } bodyBytes, err := io.ReadAll(res.Body) if err != nil { - return false, fmt.Errorf("failed to read response body: %w", err), "" + return false, "", fmt.Errorf("failed to read response body: %w", err) } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() switch res.StatusCode { case http.StatusOK: var responseMap map[string]interface{} if err := json.Unmarshal(bodyBytes, &responseMap); err != nil { - return false, fmt.Errorf("failed to parse response body: %w", err), "" + return false, "", fmt.Errorf("failed to parse response body: %w", err) } // Extract the access token from the response accessToken, exists := responseMap["access_token"].(string) if !exists { - return false, fmt.Errorf("access_token not found in response: %s", string(bodyBytes)), "" + return false, "", fmt.Errorf("access_token not found in response: %s", string(bodyBytes)) } - return true, nil, accessToken + return true, accessToken, nil case http.StatusUnauthorized: - return false, nil, "" + return false, "", nil default: - return false, fmt.Errorf("unexpected status code: %d", res.StatusCode), "" + return false, "", fmt.Errorf("unexpected status code: %d", res.StatusCode) } } @@ -147,7 +147,7 @@ func verifyAccessToken(ctx context.Context, client *http.Client, token string) ( if err != nil { return false, fmt.Errorf("failed to make request: %w", err) } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() switch res.StatusCode { case http.StatusOK: diff --git a/pkg/detectors/discordbottoken/discordbottoken.go b/pkg/detectors/discordbottoken/discordbottoken.go index e1b0d33600bc..432b8dc8e6ef 100644 --- a/pkg/detectors/discordbottoken/discordbottoken.go +++ b/pkg/detectors/discordbottoken/discordbottoken.go @@ -63,7 +63,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bot %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/discordwebhook/discordwebhook.go b/pkg/detectors/discordwebhook/discordwebhook.go index 6fb040c048a3..97e177543f98 100644 --- a/pkg/detectors/discordwebhook/discordwebhook.go +++ b/pkg/detectors/discordwebhook/discordwebhook.go @@ -48,7 +48,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/disqus/disqus.go b/pkg/detectors/disqus/disqus.go index 119bfd1c358d..7d304b1cf743 100644 --- a/pkg/detectors/disqus/disqus.go +++ b/pkg/detectors/disqus/disqus.go @@ -52,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/ditto/ditto.go b/pkg/detectors/ditto/ditto.go index 1655eaee6f41..47e589fa2450 100644 --- a/pkg/detectors/ditto/ditto.go +++ b/pkg/detectors/ditto/ditto.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("token %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/dnscheck/dnscheck.go b/pkg/detectors/dnscheck/dnscheck.go index 8c87fbf673cd..11769142787d 100644 --- a/pkg/detectors/dnscheck/dnscheck.go +++ b/pkg/detectors/dnscheck/dnscheck.go @@ -63,7 +63,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/dockerhub/v1/dockerhub.go b/pkg/detectors/dockerhub/v1/dockerhub.go index e29ce4c239c0..0ede5a9e966c 100644 --- a/pkg/detectors/dockerhub/v1/dockerhub.go +++ b/pkg/detectors/dockerhub/v1/dockerhub.go @@ -117,13 +117,14 @@ func (s Scanner) verifyMatch(ctx context.Context, username string, password stri if err != nil { return false, nil, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() body, err := io.ReadAll(res.Body) if err != nil { return false, nil, err } - if res.StatusCode == http.StatusOK { + switch res.StatusCode { + case http.StatusOK: var tokenRes tokenResponse if err := json.Unmarshal(body, &tokenRes); (err != nil || tokenRes == tokenResponse{}) { return false, nil, err @@ -144,7 +145,7 @@ func (s Scanner) verifyMatch(ctx context.Context, username string, password stri return true, extraData, nil } return true, nil, nil - } else if res.StatusCode == http.StatusUnauthorized { + case http.StatusUnauthorized: // Valid credentials can still return a 401 status code if 2FA is enabled var mfaRes mfaRequiredResponse if err := json.Unmarshal(body, &mfaRes); err != nil || mfaRes.MfaToken == "" { @@ -156,7 +157,7 @@ func (s Scanner) verifyMatch(ctx context.Context, username string, password stri "2fa_required": "true", } return true, extraData, nil - } else { + default: return false, nil, fmt.Errorf("unexpected response status %d", res.StatusCode) } } diff --git a/pkg/detectors/dockerhub/v2/dockerhub.go b/pkg/detectors/dockerhub/v2/dockerhub.go index 4f55f6fa91c6..57962335bc0a 100644 --- a/pkg/detectors/dockerhub/v2/dockerhub.go +++ b/pkg/detectors/dockerhub/v2/dockerhub.go @@ -117,13 +117,14 @@ func (s Scanner) verifyMatch(ctx context.Context, username string, password stri if err != nil { return false, nil, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() body, err := io.ReadAll(res.Body) if err != nil { return false, nil, err } - if res.StatusCode == http.StatusOK { + switch res.StatusCode { + case http.StatusOK: var tokenRes tokenResponse if err := json.Unmarshal(body, &tokenRes); (err != nil || tokenRes == tokenResponse{}) { return false, nil, err @@ -144,7 +145,7 @@ func (s Scanner) verifyMatch(ctx context.Context, username string, password stri return true, extraData, nil } return true, nil, nil - } else if res.StatusCode == http.StatusUnauthorized { + case http.StatusUnauthorized: // Valid credentials can still return a 401 status code if 2FA is enabled var mfaRes mfaRequiredResponse if err := json.Unmarshal(body, &mfaRes); err != nil || mfaRes.MfaToken == "" { @@ -156,7 +157,7 @@ func (s Scanner) verifyMatch(ctx context.Context, username string, password stri "2fa_required": "true", } return true, extraData, nil - } else { + default: return false, nil, fmt.Errorf("unexpected response status %d", res.StatusCode) } } diff --git a/pkg/detectors/docparser/docparser.go b/pkg/detectors/docparser/docparser.go index f8b1bc825027..01a98131bea4 100644 --- a/pkg/detectors/docparser/docparser.go +++ b/pkg/detectors/docparser/docparser.go @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/documo/documo.go b/pkg/detectors/documo/documo.go index 461836511bae..8a2dab35143c 100644 --- a/pkg/detectors/documo/documo.go +++ b/pkg/detectors/documo/documo.go @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/docusign/docusign.go b/pkg/detectors/docusign/docusign.go index aacd1e061505..dc57157384d0 100644 --- a/pkg/detectors/docusign/docusign.go +++ b/pkg/detectors/docusign/docusign.go @@ -83,7 +83,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } verifiedBodyResponse, err := common.ResponseContainsSubstring(res.Body, "ey") - res.Body.Close() + _ = res.Body.Close() if err != nil { return nil, err diff --git a/pkg/detectors/doppler/doppler.go b/pkg/detectors/doppler/doppler.go index d711d846aea0..32e240e70dc6 100644 --- a/pkg/detectors/doppler/doppler.go +++ b/pkg/detectors/doppler/doppler.go @@ -73,7 +73,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true var r response diff --git a/pkg/detectors/dronahq/dronahq.go b/pkg/detectors/dronahq/dronahq.go index 83d24f63de92..63166205e6b7 100644 --- a/pkg/detectors/dronahq/dronahq.go +++ b/pkg/detectors/dronahq/dronahq.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/droneci/droneci.go b/pkg/detectors/droneci/droneci.go index e16609ad4a3a..7bc3e6df704d 100644 --- a/pkg/detectors/droneci/droneci.go +++ b/pkg/detectors/droneci/droneci.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/duply/duply.go b/pkg/detectors/duply/duply.go index 03a1574cda2f..c83d4a34b526 100644 --- a/pkg/detectors/duply/duply.go +++ b/pkg/detectors/duply/duply.go @@ -65,7 +65,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/dynalist/dynalist.go b/pkg/detectors/dynalist/dynalist.go index 21d69765cf09..c734571f2373 100644 --- a/pkg/detectors/dynalist/dynalist.go +++ b/pkg/detectors/dynalist/dynalist.go @@ -60,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err == nil { bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `"_code":"Ok"`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { s1.Verified = true diff --git a/pkg/detectors/dyspatch/dyspatch.go b/pkg/detectors/dyspatch/dyspatch.go index f4772b3d4a65..974f4e9ca80d 100644 --- a/pkg/detectors/dyspatch/dyspatch.go +++ b/pkg/detectors/dyspatch/dyspatch.go @@ -56,7 +56,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { continue diff --git a/pkg/detectors/eagleeyenetworks/eagleeyenetworks.go b/pkg/detectors/eagleeyenetworks/eagleeyenetworks.go index af48b0415893..6e4d600d631b 100644 --- a/pkg/detectors/eagleeyenetworks/eagleeyenetworks.go +++ b/pkg/detectors/eagleeyenetworks/eagleeyenetworks.go @@ -62,7 +62,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/ecostruxureit/ecostruxureit.go b/pkg/detectors/ecostruxureit/ecostruxureit.go index 24e143ce0a91..f70caa4e8670 100644 --- a/pkg/detectors/ecostruxureit/ecostruxureit.go +++ b/pkg/detectors/ecostruxureit/ecostruxureit.go @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/edamam/edamam.go b/pkg/detectors/edamam/edamam.go index afb6edceb8b2..77563cc2ad4f 100644 --- a/pkg/detectors/edamam/edamam.go +++ b/pkg/detectors/edamam/edamam.go @@ -63,7 +63,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/edenai/edenai.go b/pkg/detectors/edenai/edenai.go index d43d83ac021d..16c563dc061f 100644 --- a/pkg/detectors/edenai/edenai.go +++ b/pkg/detectors/edenai/edenai.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/eightxeight/eightxeight.go b/pkg/detectors/eightxeight/eightxeight.go index 6543a86e299b..7df28a91ab23 100644 --- a/pkg/detectors/eightxeight/eightxeight.go +++ b/pkg/detectors/eightxeight/eightxeight.go @@ -71,7 +71,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/elasticemail/elasticemail.go b/pkg/detectors/elasticemail/elasticemail.go index d49470b4f70e..0225a843166e 100644 --- a/pkg/detectors/elasticemail/elasticemail.go +++ b/pkg/detectors/elasticemail/elasticemail.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { data, readErr := io.ReadAll(res.Body) - res.Body.Close() + _ = res.Body.Close() if readErr == nil { var ResVar struct { Success bool `json:"success"` diff --git a/pkg/detectors/enablex/enablex.go b/pkg/detectors/enablex/enablex.go index 2fbf690c9c6c..ca1e0c9c686e 100644 --- a/pkg/detectors/enablex/enablex.go +++ b/pkg/detectors/enablex/enablex.go @@ -61,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.SetBasicAuth(userPatMatch, tokenPatMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/enigma/enigma.go b/pkg/detectors/enigma/enigma.go index 18df615e0865..df6f175d7d32 100644 --- a/pkg/detectors/enigma/enigma.go +++ b/pkg/detectors/enigma/enigma.go @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("x-api-key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/envoyapikey/envoyapikey.go b/pkg/detectors/envoyapikey/envoyapikey.go index 5ef0d8203206..153c4f01135e 100644 --- a/pkg/detectors/envoyapikey/envoyapikey.go +++ b/pkg/detectors/envoyapikey/envoyapikey.go @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-Api-Key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() body, _ := io.ReadAll(res.Body) // Invalid API keys can also return status code 200, so check for presence of 'status 401' in response body. diff --git a/pkg/detectors/etherscan/etherscan.go b/pkg/detectors/etherscan/etherscan.go index e46d2d99f65a..c519f486e0ff 100644 --- a/pkg/detectors/etherscan/etherscan.go +++ b/pkg/detectors/etherscan/etherscan.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { continue diff --git a/pkg/detectors/ethplorer/ethplorer.go b/pkg/detectors/ethplorer/ethplorer.go index b113206a2996..08ce6327e51e 100644 --- a/pkg/detectors/ethplorer/ethplorer.go +++ b/pkg/detectors/ethplorer/ethplorer.go @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/x-www-form-urlencoded") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/everhour/everhour.go b/pkg/detectors/everhour/everhour.go index c04ddb966fc1..a2583ef0da3f 100644 --- a/pkg/detectors/everhour/everhour.go +++ b/pkg/detectors/everhour/everhour.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-Api-Key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/exchangeratesapi/exchangeratesapi.go b/pkg/detectors/exchangeratesapi/exchangeratesapi.go index 20c600312c33..88f65b2d01cc 100644 --- a/pkg/detectors/exchangeratesapi/exchangeratesapi.go +++ b/pkg/detectors/exchangeratesapi/exchangeratesapi.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/exportsdk/exportsdk.go b/pkg/detectors/exportsdk/exportsdk.go index aaf81e8e52f3..81590080cfdc 100644 --- a/pkg/detectors/exportsdk/exportsdk.go +++ b/pkg/detectors/exportsdk/exportsdk.go @@ -61,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-API-KEY", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/extractorapi/extractorapi.go b/pkg/detectors/extractorapi/extractorapi.go index 6bd17a1e2380..4ad6ee34c979 100644 --- a/pkg/detectors/extractorapi/extractorapi.go +++ b/pkg/detectors/extractorapi/extractorapi.go @@ -52,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/facebookoauth/facebookoauth.go b/pkg/detectors/facebookoauth/facebookoauth.go index 1793b59be586..e81b0c7f7b0f 100644 --- a/pkg/detectors/facebookoauth/facebookoauth.go +++ b/pkg/detectors/facebookoauth/facebookoauth.go @@ -67,7 +67,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/faceplusplus/faceplusplus.go b/pkg/detectors/faceplusplus/faceplusplus.go index 4a771336aa3b..c9f1ea80591c 100644 --- a/pkg/detectors/faceplusplus/faceplusplus.go +++ b/pkg/detectors/faceplusplus/faceplusplus.go @@ -64,7 +64,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/fastforex/fastforex.go b/pkg/detectors/fastforex/fastforex.go index 88ebaf8aeeea..2d7271d4e252 100644 --- a/pkg/detectors/fastforex/fastforex.go +++ b/pkg/detectors/fastforex/fastforex.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/feedier/feedier.go b/pkg/detectors/feedier/feedier.go index 3c066449fb4c..c1a5939ecf97 100644 --- a/pkg/detectors/feedier/feedier.go +++ b/pkg/detectors/feedier/feedier.go @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/figmapersonalaccesstoken/v1/figmapersonalaccesstoken.go b/pkg/detectors/figmapersonalaccesstoken/v1/figmapersonalaccesstoken.go index 4a6558eab3fa..3e90aed56405 100644 --- a/pkg/detectors/figmapersonalaccesstoken/v1/figmapersonalaccesstoken.go +++ b/pkg/detectors/figmapersonalaccesstoken/v1/figmapersonalaccesstoken.go @@ -65,7 +65,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-Figma-Token", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode != 403 { diff --git a/pkg/detectors/figmapersonalaccesstoken/v2/figmapersonalaccesstoken_v2.go b/pkg/detectors/figmapersonalaccesstoken/v2/figmapersonalaccesstoken_v2.go index 061e82e815bc..b6578df06a82 100644 --- a/pkg/detectors/figmapersonalaccesstoken/v2/figmapersonalaccesstoken_v2.go +++ b/pkg/detectors/figmapersonalaccesstoken/v2/figmapersonalaccesstoken_v2.go @@ -69,7 +69,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-Figma-Token", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode != 403 { diff --git a/pkg/detectors/fileio/fileio.go b/pkg/detectors/fileio/fileio.go index 8b6ec9c86443..4dcb0e887045 100644 --- a/pkg/detectors/fileio/fileio.go +++ b/pkg/detectors/fileio/fileio.go @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result bodyBytes, err := io.ReadAll(res.Body) if err == nil { isJson := json.Valid(bodyBytes) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if isJson { s1.Verified = true diff --git a/pkg/detectors/finage/finage.go b/pkg/detectors/finage/finage.go index 067a4bd42914..4958a3cc573a 100644 --- a/pkg/detectors/finage/finage.go +++ b/pkg/detectors/finage/finage.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/financialmodelingprep/financialmodelingprep.go b/pkg/detectors/financialmodelingprep/financialmodelingprep.go index e0309dcd9885..b350d545993a 100644 --- a/pkg/detectors/financialmodelingprep/financialmodelingprep.go +++ b/pkg/detectors/financialmodelingprep/financialmodelingprep.go @@ -61,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result // error response is in json validResponse := strings.Contains(bodyString, `[ "`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { s1.Verified = true diff --git a/pkg/detectors/findl/findl.go b/pkg/detectors/findl/findl.go index 657b5e09fd46..c77f6085b8af 100644 --- a/pkg/detectors/findl/findl.go +++ b/pkg/detectors/findl/findl.go @@ -56,7 +56,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-API-Key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/finnhub/finnhub.go b/pkg/detectors/finnhub/finnhub.go index a8014d7dbd3f..85c531d5083e 100644 --- a/pkg/detectors/finnhub/finnhub.go +++ b/pkg/detectors/finnhub/finnhub.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/fixerio/fixerio.go b/pkg/detectors/fixerio/fixerio.go index d499c6d0ab4f..26e1d785384c 100644 --- a/pkg/detectors/fixerio/fixerio.go +++ b/pkg/detectors/fixerio/fixerio.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { continue @@ -66,7 +66,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result // ingenious! validResponse := strings.Contains(body, `"success": true`) || strings.Contains(body, `"info":"Access Restricted - Your current Subscription Plan does not support HTTPS Encryption."`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 && validResponse { s1.Verified = true diff --git a/pkg/detectors/flatio/flatio.go b/pkg/detectors/flatio/flatio.go index 7af1ce3659ab..2d215d758996 100644 --- a/pkg/detectors/flatio/flatio.go +++ b/pkg/detectors/flatio/flatio.go @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/fleetbase/fleetbase.go b/pkg/detectors/fleetbase/fleetbase.go index a00efc3d1620..12c03523056e 100644 --- a/pkg/detectors/fleetbase/fleetbase.go +++ b/pkg/detectors/fleetbase/fleetbase.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/flickr/flickr.go b/pkg/detectors/flickr/flickr.go index f01c0089225c..da8592c5e57b 100644 --- a/pkg/detectors/flickr/flickr.go +++ b/pkg/detectors/flickr/flickr.go @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { continue diff --git a/pkg/detectors/flightapi/flightapi.go b/pkg/detectors/flightapi/flightapi.go index 2d480caf793c..67d1fc6b667d 100644 --- a/pkg/detectors/flightapi/flightapi.go +++ b/pkg/detectors/flightapi/flightapi.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/flightstats/flightstats.go b/pkg/detectors/flightstats/flightstats.go index b2aace0b2f8c..5a5e6fe0e1ae 100644 --- a/pkg/detectors/flightstats/flightstats.go +++ b/pkg/detectors/flightstats/flightstats.go @@ -62,7 +62,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { continue diff --git a/pkg/detectors/float/float.go b/pkg/detectors/float/float.go index 186825f6c297..28da924c49bd 100644 --- a/pkg/detectors/float/float.go +++ b/pkg/detectors/float/float.go @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("User-Agent", "TruffleHog3 (example@example.com)") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/flowflu/flowflu.go b/pkg/detectors/flowflu/flowflu.go index 95acf15e3bd5..e0cc5cc4e685 100644 --- a/pkg/detectors/flowflu/flowflu.go +++ b/pkg/detectors/flowflu/flowflu.go @@ -70,7 +70,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `total_result`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { s1.Verified = true diff --git a/pkg/detectors/flutterwave/flutterwave.go b/pkg/detectors/flutterwave/flutterwave.go index 5f5bf3d342ca..19a8cf7987f9 100644 --- a/pkg/detectors/flutterwave/flutterwave.go +++ b/pkg/detectors/flutterwave/flutterwave.go @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/fmfw/fmfw.go b/pkg/detectors/fmfw/fmfw.go index 92266ba39a8a..7b85d371fb1f 100644 --- a/pkg/detectors/fmfw/fmfw.go +++ b/pkg/detectors/fmfw/fmfw.go @@ -64,7 +64,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.SetBasicAuth(userPatMatch, tokenPatMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/formbucket/formbucket.go b/pkg/detectors/formbucket/formbucket.go index 3f7cd894282a..76441a2cea99 100644 --- a/pkg/detectors/formbucket/formbucket.go +++ b/pkg/detectors/formbucket/formbucket.go @@ -56,14 +56,14 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() body, errBody := io.ReadAll(res.Body) if errBody != nil { continue } bodyString := string(body) validResponse := strings.Contains(bodyString, `created_on`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if errBody == nil { if res.StatusCode >= 200 && res.StatusCode < 300 && validResponse { s1.Verified = true diff --git a/pkg/detectors/formcraft/formcraft.go b/pkg/detectors/formcraft/formcraft.go index 3590fa0ac719..b1c9754abe7f 100644 --- a/pkg/detectors/formcraft/formcraft.go +++ b/pkg/detectors/formcraft/formcraft.go @@ -57,7 +57,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", sEnc)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/formio/formio.go b/pkg/detectors/formio/formio.go index 53f3088a30af..3c13423c2af7 100644 --- a/pkg/detectors/formio/formio.go +++ b/pkg/detectors/formio/formio.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("x-jwt-token", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/formsite/formsite.go b/pkg/detectors/formsite/formsite.go index 2373d4839c6a..dc0e19e75964 100644 --- a/pkg/detectors/formsite/formsite.go +++ b/pkg/detectors/formsite/formsite.go @@ -63,7 +63,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/foursquare/foursquare.go b/pkg/detectors/foursquare/foursquare.go index c42a862cdb98..979bbd63a743 100644 --- a/pkg/detectors/foursquare/foursquare.go +++ b/pkg/detectors/foursquare/foursquare.go @@ -63,7 +63,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/frameio/frameio.go b/pkg/detectors/frameio/frameio.go index a6f869019604..52e23dae6a0b 100644 --- a/pkg/detectors/frameio/frameio.go +++ b/pkg/detectors/frameio/frameio.go @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/freshbooks/freshbooks.go b/pkg/detectors/freshbooks/freshbooks.go index d3c2385f2fad..c6b8c3d453fa 100644 --- a/pkg/detectors/freshbooks/freshbooks.go +++ b/pkg/detectors/freshbooks/freshbooks.go @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { continue diff --git a/pkg/detectors/freshdesk/freshdesk.go b/pkg/detectors/freshdesk/freshdesk.go index 0631aeda41a7..9b4a66ee6cca 100644 --- a/pkg/detectors/freshdesk/freshdesk.go +++ b/pkg/detectors/freshdesk/freshdesk.go @@ -64,7 +64,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", sEnc)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/front/front.go b/pkg/detectors/front/front.go index e6a50b0f9e84..060c221df2c4 100644 --- a/pkg/detectors/front/front.go +++ b/pkg/detectors/front/front.go @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/ftp/ftp.go b/pkg/detectors/ftp/ftp.go index 16ad41dcce73..db757b35e6b8 100644 --- a/pkg/detectors/ftp/ftp.go +++ b/pkg/detectors/ftp/ftp.go @@ -70,7 +70,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result rawURL, _ := url.Parse(urlMatch) rawURL.Path = "" - redact := strings.TrimSpace(strings.Replace(rawURL.String(), password, "********", -1)) + redact := strings.TrimSpace(strings.ReplaceAll(rawURL.String(), password, "********")) s1 := detectors.Result{ DetectorType: detector_typepb.DetectorType_FTP, @@ -139,7 +139,7 @@ func verifyFTP(timeout time.Duration, u *url.URL) error { return nil, err } if err := conn.SetDeadline(time.Now().Add(timeout)); err != nil { - conn.Close() + _ = conn.Close() return nil, err } return conn, nil diff --git a/pkg/detectors/fulcrum/fulcrum.go b/pkg/detectors/fulcrum/fulcrum.go index 57113c6054b9..065eb7ef7493 100644 --- a/pkg/detectors/fulcrum/fulcrum.go +++ b/pkg/detectors/fulcrum/fulcrum.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-ApiToken", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/fullstory/v1/fullstory.go b/pkg/detectors/fullstory/v1/fullstory.go index 15cdce5eaa26..e5de71e78a44 100644 --- a/pkg/detectors/fullstory/v1/fullstory.go +++ b/pkg/detectors/fullstory/v1/fullstory.go @@ -60,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/fullstory/v2/fullstory_v2.go b/pkg/detectors/fullstory/v2/fullstory_v2.go index 1918ad6a309d..aa719c70acdd 100644 --- a/pkg/detectors/fullstory/v2/fullstory_v2.go +++ b/pkg/detectors/fullstory/v2/fullstory_v2.go @@ -60,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/fxmarket/fxmarket.go b/pkg/detectors/fxmarket/fxmarket.go index cbadf5bc4c85..f0e824cb25f1 100644 --- a/pkg/detectors/fxmarket/fxmarket.go +++ b/pkg/detectors/fxmarket/fxmarket.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/gcp/gcp.go b/pkg/detectors/gcp/gcp.go index dc911d80b5ac..e7b8ee2f992d 100644 --- a/pkg/detectors/gcp/gcp.go +++ b/pkg/detectors/gcp/gcp.go @@ -212,7 +212,7 @@ func findMatchingCertificateKID(ctx context.Context, certsURL, privateKeyPEM str } // Compare RSA public keys - if publicKey.PublicKey.N.Cmp(certPublicKey.N) == 0 && publicKey.PublicKey.E == certPublicKey.E { + if publicKey.N.Cmp(certPublicKey.N) == 0 && publicKey.E == certPublicKey.E { return kid, nil } } @@ -233,7 +233,7 @@ func fetchServiceAccountCerts(ctx context.Context, certsURL string) (map[string] if err != nil { return nil, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode < 200 || resp.StatusCode >= 300 { return nil, nil diff --git a/pkg/detectors/geckoboard/geckoboard.go b/pkg/detectors/geckoboard/geckoboard.go index 4bd76c802eff..46e81f25feec 100644 --- a/pkg/detectors/geckoboard/geckoboard.go +++ b/pkg/detectors/geckoboard/geckoboard.go @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/gemini/gemini.go b/pkg/detectors/gemini/gemini.go index 283723d5bbea..5fe1eac66adc 100644 --- a/pkg/detectors/gemini/gemini.go +++ b/pkg/detectors/gemini/gemini.go @@ -77,7 +77,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/gengo/gengo.go b/pkg/detectors/gengo/gengo.go index d1aa53b5c9fe..7c74d9615020 100644 --- a/pkg/detectors/gengo/gengo.go +++ b/pkg/detectors/gengo/gengo.go @@ -77,7 +77,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Accept", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() body, errBody := io.ReadAll(res.Body) if errBody == nil { diff --git a/pkg/detectors/geoapify/geoapify.go b/pkg/detectors/geoapify/geoapify.go index 09d6739e0b34..956cd90902bc 100644 --- a/pkg/detectors/geoapify/geoapify.go +++ b/pkg/detectors/geoapify/geoapify.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/geocode/geocode.go b/pkg/detectors/geocode/geocode.go index c2160584f511..a9e1739b9899 100644 --- a/pkg/detectors/geocode/geocode.go +++ b/pkg/detectors/geocode/geocode.go @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err == nil { bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `"remaining_credits" :`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { s1.Verified = true diff --git a/pkg/detectors/geocodify/geocodify.go b/pkg/detectors/geocodify/geocodify.go index 9a592a76f36a..db3538895f94 100644 --- a/pkg/detectors/geocodify/geocodify.go +++ b/pkg/detectors/geocodify/geocodify.go @@ -52,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/geocodio/geocodio.go b/pkg/detectors/geocodio/geocodio.go index c9ced6834f1f..157d0b4888d7 100644 --- a/pkg/detectors/geocodio/geocodio.go +++ b/pkg/detectors/geocodio/geocodio.go @@ -63,7 +63,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/geoipifi/geoipifi.go b/pkg/detectors/geoipifi/geoipifi.go index 7547362aea1e..b03f6e132723 100644 --- a/pkg/detectors/geoipifi/geoipifi.go +++ b/pkg/detectors/geoipifi/geoipifi.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/getemail/getemail.go b/pkg/detectors/getemail/getemail.go index deab794a3e62..6ddf51f35df1 100644 --- a/pkg/detectors/getemail/getemail.go +++ b/pkg/detectors/getemail/getemail.go @@ -61,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } bodyString := string(bodyBytes) errCode := strings.Contains(bodyString, `"code":"USER_NOT_EXIST"`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if errCode { s1.Verified = false diff --git a/pkg/detectors/getemails/getemails.go b/pkg/detectors/getemails/getemails.go index a509ff0f25ea..e049b45e2039 100644 --- a/pkg/detectors/getemails/getemails.go +++ b/pkg/detectors/getemails/getemails.go @@ -64,7 +64,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/getgeoapi/getgeoapi.go b/pkg/detectors/getgeoapi/getgeoapi.go index bff3e7c368de..2a723b60f99c 100644 --- a/pkg/detectors/getgeoapi/getgeoapi.go +++ b/pkg/detectors/getgeoapi/getgeoapi.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/getgist/getgist.go b/pkg/detectors/getgist/getgist.go index 87fbb1343a1c..2b88b53ad54b 100644 --- a/pkg/detectors/getgist/getgist.go +++ b/pkg/detectors/getgist/getgist.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/getresponse/getresponse.go b/pkg/detectors/getresponse/getresponse.go index 7b02af9414d8..c89a7a21e35a 100644 --- a/pkg/detectors/getresponse/getresponse.go +++ b/pkg/detectors/getresponse/getresponse.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-Auth-Token", fmt.Sprintf("api-key %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/getsandbox/getsandbox.go b/pkg/detectors/getsandbox/getsandbox.go index 248be740f415..67157a530c39 100644 --- a/pkg/detectors/getsandbox/getsandbox.go +++ b/pkg/detectors/getsandbox/getsandbox.go @@ -61,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("API-Key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/github/v1/github_old.go b/pkg/detectors/github/v1/github_old.go index f907b36f37c6..393c16553533 100644 --- a/pkg/detectors/github/v1/github_old.go +++ b/pkg/detectors/github/v1/github_old.go @@ -170,7 +170,7 @@ func (s Scanner) VerifyGithub(ctx context.Context, client *http.Client, token st if res.StatusCode >= 200 && res.StatusCode < 300 { var userResponse UserRes err = json.NewDecoder(res.Body).Decode(&userResponse) - res.Body.Close() + _ = res.Body.Close() if err == nil { // GitHub does not seem to consistently return this header. scopes := res.Header.Get("X-OAuth-Scopes") diff --git a/pkg/detectors/githubapp/githubapp.go b/pkg/detectors/githubapp/githubapp.go index 25f82b0b16af..dd3b1840311b 100644 --- a/pkg/detectors/githubapp/githubapp.go +++ b/pkg/detectors/githubapp/githubapp.go @@ -86,7 +86,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", tokenString)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/gitlab/v1/gitlab.go b/pkg/detectors/gitlab/v1/gitlab.go index 793a44de1988..40e90ac69454 100644 --- a/pkg/detectors/gitlab/v1/gitlab.go +++ b/pkg/detectors/gitlab/v1/gitlab.go @@ -134,7 +134,7 @@ func VerifyGitlab(ctx context.Context, client *http.Client, baseEndpoint, resMat return false, nil, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { diff --git a/pkg/detectors/gitter/gitter.go b/pkg/detectors/gitter/gitter.go index cd8253186772..1f9137469618 100644 --- a/pkg/detectors/gitter/gitter.go +++ b/pkg/detectors/gitter/gitter.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/glassnode/glassnode.go b/pkg/detectors/glassnode/glassnode.go index 4b08a50d43ed..0ca330818118 100644 --- a/pkg/detectors/glassnode/glassnode.go +++ b/pkg/detectors/glassnode/glassnode.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/gocanvas/gocanvas.go b/pkg/detectors/gocanvas/gocanvas.go index 0fbfeb62c40b..f13168c70f1f 100644 --- a/pkg/detectors/gocanvas/gocanvas.go +++ b/pkg/detectors/gocanvas/gocanvas.go @@ -70,7 +70,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() body, errBody := io.ReadAll(res.Body) if errBody == nil { diff --git a/pkg/detectors/gocardless/gocardless.go b/pkg/detectors/gocardless/gocardless.go index 8bc90a8eb8cb..7edc19c19c0a 100644 --- a/pkg/detectors/gocardless/gocardless.go +++ b/pkg/detectors/gocardless/gocardless.go @@ -57,7 +57,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("GoCardless-Version", "2015-07-06") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/goodday/goodday.go b/pkg/detectors/goodday/goodday.go index 11aff376bdfc..c41a8f8d0f08 100644 --- a/pkg/detectors/goodday/goodday.go +++ b/pkg/detectors/goodday/goodday.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("gd-api-token", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/googleoauth2/googleoauth2_access_token.go b/pkg/detectors/googleoauth2/googleoauth2_access_token.go index 2939e75409db..a7c1845b01af 100644 --- a/pkg/detectors/googleoauth2/googleoauth2_access_token.go +++ b/pkg/detectors/googleoauth2/googleoauth2_access_token.go @@ -88,7 +88,8 @@ func (s Scanner) verify(ctx context.Context, token string) (bool, map[string]str _, _ = io.Copy(io.Discard, res.Body) }() - if res.StatusCode == http.StatusOK { + switch res.StatusCode { + case http.StatusOK: var token tokenInfo if err := json.NewDecoder(res.Body).Decode(&token); err != nil { return false, nil, fmt.Errorf("failed to decode response: %w", err) @@ -106,7 +107,7 @@ func (s Scanner) verify(ctx context.Context, token string) (bool, map[string]str extraData["expires_at"] = time.Unix(exp, 0).String() } return true, extraData, nil - } else if res.StatusCode == http.StatusBadRequest { + case http.StatusBadRequest: var errInfo errorInfo if err := json.NewDecoder(res.Body).Decode(&errInfo); err != nil { return false, nil, fmt.Errorf("failed to decode response: %w", err) @@ -118,7 +119,7 @@ func (s Scanner) verify(ctx context.Context, token string) (bool, map[string]str } else { return false, nil, fmt.Errorf("unexpected error description '%s' for %s", errInfo.Error, req.URL) } - } else { + default: return false, nil, fmt.Errorf("unexpected response %d for %s", res.StatusCode, req.URL) } } diff --git a/pkg/detectors/grafanaserviceaccount/grafanaserviceaccount.go b/pkg/detectors/grafanaserviceaccount/grafanaserviceaccount.go index a98e7b8fc7e0..02fab0ed7507 100644 --- a/pkg/detectors/grafanaserviceaccount/grafanaserviceaccount.go +++ b/pkg/detectors/grafanaserviceaccount/grafanaserviceaccount.go @@ -68,7 +68,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", key)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode == 401 { diff --git a/pkg/detectors/graphcms/graphcms.go b/pkg/detectors/graphcms/graphcms.go index 73c843cf5543..6c1e1ab012ba 100644 --- a/pkg/detectors/graphcms/graphcms.go +++ b/pkg/detectors/graphcms/graphcms.go @@ -65,7 +65,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/graphhopper/graphhopper.go b/pkg/detectors/graphhopper/graphhopper.go index 00a7022aef28..a528a1b5e7db 100644 --- a/pkg/detectors/graphhopper/graphhopper.go +++ b/pkg/detectors/graphhopper/graphhopper.go @@ -49,7 +49,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/groovehq/groovehq.go b/pkg/detectors/groovehq/groovehq.go index bcb8ebb5a158..141a61754114 100644 --- a/pkg/detectors/groovehq/groovehq.go +++ b/pkg/detectors/groovehq/groovehq.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/gtmetrix/gtmetrix.go b/pkg/detectors/gtmetrix/gtmetrix.go index 6d989a72e865..b61e6ae8337b 100644 --- a/pkg/detectors/gtmetrix/gtmetrix.go +++ b/pkg/detectors/gtmetrix/gtmetrix.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.SetBasicAuth(resMatch, "") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/guardianapi/guardianapi.go b/pkg/detectors/guardianapi/guardianapi.go index 07ee12bd2006..d7255d820053 100644 --- a/pkg/detectors/guardianapi/guardianapi.go +++ b/pkg/detectors/guardianapi/guardianapi.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/gumroad/gumroad.go b/pkg/detectors/gumroad/gumroad.go index 86cc11361f6f..6f77a49d2969 100644 --- a/pkg/detectors/gumroad/gumroad.go +++ b/pkg/detectors/gumroad/gumroad.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/x-www-form-urlencoded") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/guru/guru.go b/pkg/detectors/guru/guru.go index b0e564f91787..fd19de83c584 100644 --- a/pkg/detectors/guru/guru.go +++ b/pkg/detectors/guru/guru.go @@ -67,7 +67,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", encoded)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/gyazo/gyazo.go b/pkg/detectors/gyazo/gyazo.go index 02cb9825d621..6948b6a66072 100644 --- a/pkg/detectors/gyazo/gyazo.go +++ b/pkg/detectors/gyazo/gyazo.go @@ -52,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/happyscribe/happyscribe.go b/pkg/detectors/happyscribe/happyscribe.go index a86cefe9f1e4..e210c5c79d2c 100644 --- a/pkg/detectors/happyscribe/happyscribe.go +++ b/pkg/detectors/happyscribe/happyscribe.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/harvest/harvest.go b/pkg/detectors/harvest/harvest.go index 7f4aabc1e64f..7dc03bc7b7db 100644 --- a/pkg/detectors/harvest/harvest.go +++ b/pkg/detectors/harvest/harvest.go @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/hellosign/hellosign.go b/pkg/detectors/hellosign/hellosign.go index 668ba59ad012..92b15dbd7433 100644 --- a/pkg/detectors/hellosign/hellosign.go +++ b/pkg/detectors/hellosign/hellosign.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.SetBasicAuth(resMatch, "") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/helpcrunch/helpcrunch.go b/pkg/detectors/helpcrunch/helpcrunch.go index 4c2a0ae9f02e..cc4b18af99ac 100644 --- a/pkg/detectors/helpcrunch/helpcrunch.go +++ b/pkg/detectors/helpcrunch/helpcrunch.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/helpscout/helpscout.go b/pkg/detectors/helpscout/helpscout.go index b258c69fa9a5..a9886a22c3ca 100644 --- a/pkg/detectors/helpscout/helpscout.go +++ b/pkg/detectors/helpscout/helpscout.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.SetBasicAuth(resMatch, "X") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/hereapi/hereapi.go b/pkg/detectors/hereapi/hereapi.go index 5e2decbbb881..e0e2467c395f 100644 --- a/pkg/detectors/hereapi/hereapi.go +++ b/pkg/detectors/hereapi/hereapi.go @@ -51,7 +51,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/hive/hive.go b/pkg/detectors/hive/hive.go index fd959d5d7303..b1bfdd10d668 100644 --- a/pkg/detectors/hive/hive.go +++ b/pkg/detectors/hive/hive.go @@ -60,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/hiveage/hiveage.go b/pkg/detectors/hiveage/hiveage.go index 00db0ad9be30..390db1e61569 100644 --- a/pkg/detectors/hiveage/hiveage.go +++ b/pkg/detectors/hiveage/hiveage.go @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", encoded)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/holidayapi/holidayapi.go b/pkg/detectors/holidayapi/holidayapi.go index e27734e5bf08..6ad43c84f4a1 100644 --- a/pkg/detectors/holidayapi/holidayapi.go +++ b/pkg/detectors/holidayapi/holidayapi.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/holistic/holistic.go b/pkg/detectors/holistic/holistic.go index 713e01362f6f..e5157a7dd19f 100644 --- a/pkg/detectors/holistic/holistic.go +++ b/pkg/detectors/holistic/holistic.go @@ -62,7 +62,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result bodyString := string(bodyBytes) errorResponse := strings.Contains(bodyString, `"data":[]`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 && !errorResponse { s1.Verified = true } diff --git a/pkg/detectors/honeycomb/honeycomb.go b/pkg/detectors/honeycomb/honeycomb.go index d9b8fe7c979b..83145288e986 100644 --- a/pkg/detectors/honeycomb/honeycomb.go +++ b/pkg/detectors/honeycomb/honeycomb.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-Honeycomb-Team", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/host/host.go b/pkg/detectors/host/host.go index b95ef6713d88..4cc96d295140 100644 --- a/pkg/detectors/host/host.go +++ b/pkg/detectors/host/host.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/html2pdf/html2pdf.go b/pkg/detectors/html2pdf/html2pdf.go index 43a33952e160..c6f5146b26d6 100644 --- a/pkg/detectors/html2pdf/html2pdf.go +++ b/pkg/detectors/html2pdf/html2pdf.go @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := http.Post("https://api.html2pdf.app/v1/generate", "application/json", reqBuf) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/http_test.go b/pkg/detectors/http_test.go index 7210a837ff6e..3a374a969f1d 100644 --- a/pkg/detectors/http_test.go +++ b/pkg/detectors/http_test.go @@ -56,7 +56,7 @@ func TestWithNoLocalIP(t *testing.T) { conn, err := transport.DialContext(context.Background(), "tcp", "google.com:80") assert.NoError(t, err) assert.NotNil(t, conn) - conn.Close() + _ = conn.Close() }) t.Run("Allows dialing non-local IP", func(t *testing.T) { @@ -69,7 +69,7 @@ func TestWithNoLocalIP(t *testing.T) { conn, err := transport.DialContext(context.Background(), "tcp", "1.1.1.1:80") assert.NoError(t, err) assert.NotNil(t, conn) - conn.Close() + _ = conn.Close() }) t.Run("Handles invalid address", func(t *testing.T) { diff --git a/pkg/detectors/huggingface/huggingface.go b/pkg/detectors/huggingface/huggingface.go index 9690d9f7718b..e838fc7b8c8d 100644 --- a/pkg/detectors/huggingface/huggingface.go +++ b/pkg/detectors/huggingface/huggingface.go @@ -78,7 +78,7 @@ func (s Scanner) verifyResult(ctx context.Context, apiKey string) (bool, map[str return false, nil, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { whoamiRes := whoamiResponse{} err := json.NewDecoder(res.Body).Decode(&whoamiRes) diff --git a/pkg/detectors/humanity/humanity.go b/pkg/detectors/humanity/humanity.go index f6247843af0a..959860dfa2b1 100644 --- a/pkg/detectors/humanity/humanity.go +++ b/pkg/detectors/humanity/humanity.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { continue diff --git a/pkg/detectors/hunter/hunter.go b/pkg/detectors/hunter/hunter.go index 246d94fdc592..589ff0325bee 100644 --- a/pkg/detectors/hunter/hunter.go +++ b/pkg/detectors/hunter/hunter.go @@ -51,7 +51,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/hybiscus/hybiscus.go b/pkg/detectors/hybiscus/hybiscus.go index d39e970eb8fe..7f7fbd78ead7 100644 --- a/pkg/detectors/hybiscus/hybiscus.go +++ b/pkg/detectors/hybiscus/hybiscus.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-API-KEY", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/hypertrack/hypertrack.go b/pkg/detectors/hypertrack/hypertrack.go index ab18081fad32..b9095ddb20f5 100644 --- a/pkg/detectors/hypertrack/hypertrack.go +++ b/pkg/detectors/hypertrack/hypertrack.go @@ -61,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/ibmclouduserkey/ibmclouduserkey.go b/pkg/detectors/ibmclouduserkey/ibmclouduserkey.go index 6367b6061c95..494be3e4256a 100644 --- a/pkg/detectors/ibmclouduserkey/ibmclouduserkey.go +++ b/pkg/detectors/ibmclouduserkey/ibmclouduserkey.go @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", "Basic Yng6Yng=") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/iconfinder/iconfinder.go b/pkg/detectors/iconfinder/iconfinder.go index d9fd8627b97b..bf805236f176 100644 --- a/pkg/detectors/iconfinder/iconfinder.go +++ b/pkg/detectors/iconfinder/iconfinder.go @@ -3,10 +3,11 @@ package iconfinder import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/iexapis/iexapis.go b/pkg/detectors/iexapis/iexapis.go index 0733fecab5a9..083c35323bc1 100644 --- a/pkg/detectors/iexapis/iexapis.go +++ b/pkg/detectors/iexapis/iexapis.go @@ -2,10 +2,11 @@ package iexapis import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -51,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/iexcloud/iexcloud.go b/pkg/detectors/iexcloud/iexcloud.go index 780f3c6fbdbc..c3605aca4d13 100644 --- a/pkg/detectors/iexcloud/iexcloud.go +++ b/pkg/detectors/iexcloud/iexcloud.go @@ -3,10 +3,11 @@ package iexcloud import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/imagekit/imagekit.go b/pkg/detectors/imagekit/imagekit.go index 78899e66bc91..aa253842cf62 100644 --- a/pkg/detectors/imagekit/imagekit.go +++ b/pkg/detectors/imagekit/imagekit.go @@ -2,10 +2,11 @@ package imagekit import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/imagga/imagga.go b/pkg/detectors/imagga/imagga.go index b04d11f4b237..688ab28aa6c6 100644 --- a/pkg/detectors/imagga/imagga.go +++ b/pkg/detectors/imagga/imagga.go @@ -3,10 +3,11 @@ package imagga import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/impala/impala.go b/pkg/detectors/impala/impala.go index 037d133748b9..040419409b72 100644 --- a/pkg/detectors/impala/impala.go +++ b/pkg/detectors/impala/impala.go @@ -2,10 +2,11 @@ package impala import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("x-api-key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/infura/infura.go b/pkg/detectors/infura/infura.go index e988aa8e8026..a659d883c91a 100644 --- a/pkg/detectors/infura/infura.go +++ b/pkg/detectors/infura/infura.go @@ -2,11 +2,12 @@ package infura import ( "context" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { continue diff --git a/pkg/detectors/insightly/insightly.go b/pkg/detectors/insightly/insightly.go index 80619821340c..22c9e77e5f5b 100644 --- a/pkg/detectors/insightly/insightly.go +++ b/pkg/detectors/insightly/insightly.go @@ -2,10 +2,11 @@ package insightly import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.SetBasicAuth(resMatch, "") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/instabot/instabot.go b/pkg/detectors/instabot/instabot.go index 64362555aacb..9d47bec36041 100644 --- a/pkg/detectors/instabot/instabot.go +++ b/pkg/detectors/instabot/instabot.go @@ -2,10 +2,11 @@ package instabot import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -51,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-Instabot-Api-Key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/instamojo/instamojo.go b/pkg/detectors/instamojo/instamojo.go index e36ac2c43e76..c79c4c54f706 100644 --- a/pkg/detectors/instamojo/instamojo.go +++ b/pkg/detectors/instamojo/instamojo.go @@ -70,7 +70,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/x-www-form-urlencoded") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { continue diff --git a/pkg/detectors/intercom/intercom.go b/pkg/detectors/intercom/intercom.go index cdfbd56c2cf4..5680d5e2c8f1 100644 --- a/pkg/detectors/intercom/intercom.go +++ b/pkg/detectors/intercom/intercom.go @@ -3,10 +3,11 @@ package intercom import ( "context" "encoding/base64" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -63,7 +64,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/interseller/interseller.go b/pkg/detectors/interseller/interseller.go index 6eee0a98b6ee..ac2c9e38f534 100644 --- a/pkg/detectors/interseller/interseller.go +++ b/pkg/detectors/interseller/interseller.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-API-Key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/intra42/intra42.go b/pkg/detectors/intra42/intra42.go index cc741b10b266..31346cd34c39 100644 --- a/pkg/detectors/intra42/intra42.go +++ b/pkg/detectors/intra42/intra42.go @@ -102,7 +102,7 @@ func verifyIntra42(ctx context.Context, client *http.Client, resMatch string, re if err != nil { return false, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() switch res.StatusCode { case http.StatusOK: diff --git a/pkg/detectors/intrinio/intrinio.go b/pkg/detectors/intrinio/intrinio.go index 0cf5c3298f41..9a8ba435d531 100644 --- a/pkg/detectors/intrinio/intrinio.go +++ b/pkg/detectors/intrinio/intrinio.go @@ -3,10 +3,11 @@ package intrinio import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/invoiceocean/invoiceocean.go b/pkg/detectors/invoiceocean/invoiceocean.go index a0cde788265b..46082090366b 100644 --- a/pkg/detectors/invoiceocean/invoiceocean.go +++ b/pkg/detectors/invoiceocean/invoiceocean.go @@ -60,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/ip2location/ip2location.go b/pkg/detectors/ip2location/ip2location.go index 8b5adcdf9f3a..f0bc0e607268 100644 --- a/pkg/detectors/ip2location/ip2location.go +++ b/pkg/detectors/ip2location/ip2location.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode == 401 { diff --git a/pkg/detectors/ipapi/ipapi.go b/pkg/detectors/ipapi/ipapi.go index 2ba194933eff..76070ce23b87 100644 --- a/pkg/detectors/ipapi/ipapi.go +++ b/pkg/detectors/ipapi/ipapi.go @@ -3,11 +3,12 @@ package ipapi import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -59,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result bodyString := string(bodyBytes) valid := strings.Contains(bodyString, "continent_code") || strings.Contains(bodyString, `"info":"Access Restricted - Your current Subscription Plan does not support HTTPS Encryption."`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if valid { s1.Verified = true diff --git a/pkg/detectors/ipgeolocation/ipgeolocation.go b/pkg/detectors/ipgeolocation/ipgeolocation.go index 13fe2ee728cf..52a3883b52ce 100644 --- a/pkg/detectors/ipgeolocation/ipgeolocation.go +++ b/pkg/detectors/ipgeolocation/ipgeolocation.go @@ -3,10 +3,11 @@ package ipgeolocation import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/ipinfo/ipinfo.go b/pkg/detectors/ipinfo/ipinfo.go index bb5c50b3b0a7..0d253f84ee6f 100644 --- a/pkg/detectors/ipinfo/ipinfo.go +++ b/pkg/detectors/ipinfo/ipinfo.go @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode == 403 { diff --git a/pkg/detectors/ipinfodb/ipinfodb.go b/pkg/detectors/ipinfodb/ipinfodb.go index 496dde166573..431f2e2d7297 100644 --- a/pkg/detectors/ipinfodb/ipinfodb.go +++ b/pkg/detectors/ipinfodb/ipinfodb.go @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err == nil { bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `"statusCode": "OK"`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { s1.Verified = true diff --git a/pkg/detectors/ipstack/ipstack.go b/pkg/detectors/ipstack/ipstack.go index 3d80a33dc324..c32c963efee9 100644 --- a/pkg/detectors/ipstack/ipstack.go +++ b/pkg/detectors/ipstack/ipstack.go @@ -2,11 +2,12 @@ package ipstack import ( "context" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -51,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { continue diff --git a/pkg/detectors/jdbc/jdbc.go b/pkg/detectors/jdbc/jdbc.go index cb9816f468f4..3c2547f8b913 100644 --- a/pkg/detectors/jdbc/jdbc.go +++ b/pkg/detectors/jdbc/jdbc.go @@ -252,7 +252,7 @@ func pingErr(ctx context.Context, driverName, conn string) error { if err != nil { return err } - defer db.Close() + defer func() { _ = db.Close() }() if err := db.PingContext(ctx); err != nil { return err diff --git a/pkg/detectors/jotform/jotform.go b/pkg/detectors/jotform/jotform.go index 19954941372b..fb94224f0190 100644 --- a/pkg/detectors/jotform/jotform.go +++ b/pkg/detectors/jotform/jotform.go @@ -2,10 +2,11 @@ package jotform import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/jumpcloud/jumpcloud.go b/pkg/detectors/jumpcloud/jumpcloud.go index 2f43fb336e40..ae6c4e9b7fc9 100644 --- a/pkg/detectors/jumpcloud/jumpcloud.go +++ b/pkg/detectors/jumpcloud/jumpcloud.go @@ -2,10 +2,11 @@ package jumpcloud import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/jupiterone/jupiterone.go b/pkg/detectors/jupiterone/jupiterone.go index 13d647a3ba37..243a56948a00 100644 --- a/pkg/detectors/jupiterone/jupiterone.go +++ b/pkg/detectors/jupiterone/jupiterone.go @@ -68,12 +68,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() - if res.StatusCode == 200 { + defer func() { _ = res.Body.Close() }() + switch res.StatusCode { + case 200: s1.Verified = true - } else if res.StatusCode == 401 { + case 401: // The secret is determinately not verified (nothing to do) - } else { + default: s1.SetVerificationError(fmt.Errorf("unexpected HTTP response status %d", res.StatusCode), resMatch) } } else { diff --git a/pkg/detectors/juro/juro.go b/pkg/detectors/juro/juro.go index ad23a0d570be..676ed0b8e0c6 100644 --- a/pkg/detectors/juro/juro.go +++ b/pkg/detectors/juro/juro.go @@ -2,10 +2,11 @@ package juro import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("x-api-key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/jwt/jwt.go b/pkg/detectors/jwt/jwt.go index 827443391545..d7390a968ab0 100644 --- a/pkg/detectors/jwt/jwt.go +++ b/pkg/detectors/jwt/jwt.go @@ -223,7 +223,7 @@ func verifyJWT(ctx context.Context, client *http.Client, tokenParts []string, pa if err != nil { return false, fmt.Errorf("failed to perform OIDC discovery: %w", err) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode != 200 { return false, fmt.Errorf("bad status for OIDC discovery document: %v", resp.Status) } @@ -250,7 +250,7 @@ func verifyJWT(ctx context.Context, client *http.Client, tokenParts []string, pa if err != nil { return false, fmt.Errorf("failed to fetch JWKS: %w", err) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode != 200 { return false, fmt.Errorf("bad status for JWKS: %v", resp.Status) } diff --git a/pkg/detectors/kanban/kanban.go b/pkg/detectors/kanban/kanban.go index 6c7a9f3a9e04..d50f30f10cae 100644 --- a/pkg/detectors/kanban/kanban.go +++ b/pkg/detectors/kanban/kanban.go @@ -60,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/kanbantool/kanbantool.go b/pkg/detectors/kanbantool/kanbantool.go index d187081aa820..8854f053291e 100644 --- a/pkg/detectors/kanbantool/kanbantool.go +++ b/pkg/detectors/kanbantool/kanbantool.go @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/karmacrm/karmacrm.go b/pkg/detectors/karmacrm/karmacrm.go index ebeeefb11aab..17d6aead8de6 100644 --- a/pkg/detectors/karmacrm/karmacrm.go +++ b/pkg/detectors/karmacrm/karmacrm.go @@ -3,10 +3,11 @@ package karmacrm import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/keenio/keenio.go b/pkg/detectors/keenio/keenio.go index 2b72e1b63dfb..6080a4979630 100644 --- a/pkg/detectors/keenio/keenio.go +++ b/pkg/detectors/keenio/keenio.go @@ -2,10 +2,11 @@ package keenio import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -60,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/kickbox/kickbox.go b/pkg/detectors/kickbox/kickbox.go index cb38ee4715da..9dc64e540ef9 100644 --- a/pkg/detectors/kickbox/kickbox.go +++ b/pkg/detectors/kickbox/kickbox.go @@ -2,10 +2,11 @@ package kickbox import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -51,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/klaviyo/klaviyo.go b/pkg/detectors/klaviyo/klaviyo.go index e31d0d2ed1fb..372c4b4fe973 100644 --- a/pkg/detectors/klaviyo/klaviyo.go +++ b/pkg/detectors/klaviyo/klaviyo.go @@ -4,10 +4,11 @@ import ( "context" "encoding/json" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -73,7 +74,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Set("Authorization", "Klaviyo-API-Key "+resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode == 403 { diff --git a/pkg/detectors/klipfolio/klipfolio.go b/pkg/detectors/klipfolio/klipfolio.go index 2a66e3696333..28ce4746b46e 100644 --- a/pkg/detectors/klipfolio/klipfolio.go +++ b/pkg/detectors/klipfolio/klipfolio.go @@ -2,10 +2,11 @@ package klipfolio import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("kf-api-key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/knapsackpro/knapsackpro.go b/pkg/detectors/knapsackpro/knapsackpro.go index b0254ce9841e..0882c9d2db16 100644 --- a/pkg/detectors/knapsackpro/knapsackpro.go +++ b/pkg/detectors/knapsackpro/knapsackpro.go @@ -2,10 +2,11 @@ package knapsackpro import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/kraken/kraken.go b/pkg/detectors/kraken/kraken.go index ac78ccc891cb..a037d53ff7cd 100644 --- a/pkg/detectors/kraken/kraken.go +++ b/pkg/detectors/kraken/kraken.go @@ -86,7 +86,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() out, _ := io.ReadAll(res.Body) if !strings.Contains(string(out), "Invalid key") { s1.Verified = true diff --git a/pkg/detectors/kucoin/kucoin.go b/pkg/detectors/kucoin/kucoin.go index 743788d94638..7e4b24b51464 100644 --- a/pkg/detectors/kucoin/kucoin.go +++ b/pkg/detectors/kucoin/kucoin.go @@ -5,12 +5,13 @@ import ( "crypto/hmac" "crypto/sha256" "encoding/base64" - regexp "github.com/wasilibs/go-re2" "net/http" "strconv" "strings" "time" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -88,7 +89,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/kylas/kylas.go b/pkg/detectors/kylas/kylas.go index a94fd737675e..d7df79dbf1c7 100644 --- a/pkg/detectors/kylas/kylas.go +++ b/pkg/detectors/kylas/kylas.go @@ -2,10 +2,11 @@ package kylas import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("api-key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/languagelayer/languagelayer.go b/pkg/detectors/languagelayer/languagelayer.go index 135edd961e90..c271921e3040 100644 --- a/pkg/detectors/languagelayer/languagelayer.go +++ b/pkg/detectors/languagelayer/languagelayer.go @@ -3,11 +3,12 @@ package languagelayer import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -57,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err == nil { bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `results`) || strings.Contains(bodyString, `"info":"Access Restricted - Your current Subscription Plan does not support HTTPS Encryption."`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { s1.Verified = true diff --git a/pkg/detectors/larksuiteapikey/larksuiteapikey.go b/pkg/detectors/larksuiteapikey/larksuiteapikey.go index 3a8d9e6a6e32..5aefe72cc12c 100644 --- a/pkg/detectors/larksuiteapikey/larksuiteapikey.go +++ b/pkg/detectors/larksuiteapikey/larksuiteapikey.go @@ -116,7 +116,7 @@ func verifyCredentials(ctx context.Context, client *http.Client, appId, appSecre if bodyResponse.Code == 0 { return true, nil } else { - return false, fmt.Errorf("Verification failed code %d, message %s", bodyResponse.Code, bodyResponse.Message) + return false, fmt.Errorf("verification failed code %d, message %s", bodyResponse.Code, bodyResponse.Message) } } default: diff --git a/pkg/detectors/leadfeeder/leadfeeder.go b/pkg/detectors/leadfeeder/leadfeeder.go index f619c711f7c9..794cb031c506 100644 --- a/pkg/detectors/leadfeeder/leadfeeder.go +++ b/pkg/detectors/leadfeeder/leadfeeder.go @@ -3,10 +3,11 @@ package leadfeeder import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Token token=%s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/lemlist/lemlist.go b/pkg/detectors/lemlist/lemlist.go index c8d779ebb3cc..05b1c785a3f6 100644 --- a/pkg/detectors/lemlist/lemlist.go +++ b/pkg/detectors/lemlist/lemlist.go @@ -4,10 +4,11 @@ import ( "context" b64 "encoding/base64" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -56,7 +57,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", sEnc)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/lemonsqueezy/lemonsqueezy.go b/pkg/detectors/lemonsqueezy/lemonsqueezy.go index d70476446960..31034a15c5de 100644 --- a/pkg/detectors/lemonsqueezy/lemonsqueezy.go +++ b/pkg/detectors/lemonsqueezy/lemonsqueezy.go @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode == 401 { diff --git a/pkg/detectors/lendflow/lendflow.go b/pkg/detectors/lendflow/lendflow.go index 1723957fd1a9..5585f831d69c 100644 --- a/pkg/detectors/lendflow/lendflow.go +++ b/pkg/detectors/lendflow/lendflow.go @@ -61,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Accept", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/lessannoyingcrm/lessannoyingcrm.go b/pkg/detectors/lessannoyingcrm/lessannoyingcrm.go index 9232d985f2a0..bf69f7aebf26 100644 --- a/pkg/detectors/lessannoyingcrm/lessannoyingcrm.go +++ b/pkg/detectors/lessannoyingcrm/lessannoyingcrm.go @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Accept", "application/vnd.lessannoyingcrm+json; version=3") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/lexigram/lexigram.go b/pkg/detectors/lexigram/lexigram.go index c72b6734be70..6e29f16fe816 100644 --- a/pkg/detectors/lexigram/lexigram.go +++ b/pkg/detectors/lexigram/lexigram.go @@ -3,10 +3,11 @@ package lexigram import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/linearapi/linearapi.go b/pkg/detectors/linearapi/linearapi.go index f6ae661f7381..09363bb0e7b4 100644 --- a/pkg/detectors/linearapi/linearapi.go +++ b/pkg/detectors/linearapi/linearapi.go @@ -2,11 +2,12 @@ package linearapi import ( "context" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -56,7 +57,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { continue diff --git a/pkg/detectors/linemessaging/linemessaging.go b/pkg/detectors/linemessaging/linemessaging.go index 9d5d0ea9f6a1..1febd9d64401 100644 --- a/pkg/detectors/linemessaging/linemessaging.go +++ b/pkg/detectors/linemessaging/linemessaging.go @@ -3,10 +3,11 @@ package linemessaging import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/linenotify/linenotify.go b/pkg/detectors/linenotify/linenotify.go index 9688eb91848f..00af92baafce 100644 --- a/pkg/detectors/linenotify/linenotify.go +++ b/pkg/detectors/linenotify/linenotify.go @@ -3,10 +3,11 @@ package linenotify import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/linkpreview/linkpreview.go b/pkg/detectors/linkpreview/linkpreview.go index f2118c5ecc86..dce295e9d6bd 100644 --- a/pkg/detectors/linkpreview/linkpreview.go +++ b/pkg/detectors/linkpreview/linkpreview.go @@ -3,10 +3,11 @@ package linkpreview import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -50,7 +51,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/liveagent/liveagent.go b/pkg/detectors/liveagent/liveagent.go index 09628f2ec7b8..2d110628e332 100644 --- a/pkg/detectors/liveagent/liveagent.go +++ b/pkg/detectors/liveagent/liveagent.go @@ -67,7 +67,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("apikey", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode == 403 { diff --git a/pkg/detectors/livestorm/livestorm.go b/pkg/detectors/livestorm/livestorm.go index e16bf9645ce5..58704ed7149f 100644 --- a/pkg/detectors/livestorm/livestorm.go +++ b/pkg/detectors/livestorm/livestorm.go @@ -2,10 +2,11 @@ package livestorm import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/loadmill/loadmill.go b/pkg/detectors/loadmill/loadmill.go index c8a8b6ff4765..3053a7e4bd20 100644 --- a/pkg/detectors/loadmill/loadmill.go +++ b/pkg/detectors/loadmill/loadmill.go @@ -3,10 +3,11 @@ package loadmill import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/lob/lob.go b/pkg/detectors/lob/lob.go index c86abb288247..a0902356fe66 100644 --- a/pkg/detectors/lob/lob.go +++ b/pkg/detectors/lob/lob.go @@ -2,10 +2,11 @@ package lob import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.SetBasicAuth(resMatch, "") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/locationiq/locationiq.go b/pkg/detectors/locationiq/locationiq.go index 17e2ddbb79ec..8935b8967bc8 100644 --- a/pkg/detectors/locationiq/locationiq.go +++ b/pkg/detectors/locationiq/locationiq.go @@ -2,10 +2,11 @@ package locationiq import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -51,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/loggly/loggly.go b/pkg/detectors/loggly/loggly.go index 463c7fa76e62..006ce1136454 100644 --- a/pkg/detectors/loggly/loggly.go +++ b/pkg/detectors/loggly/loggly.go @@ -69,7 +69,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", key)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode == 401 { diff --git a/pkg/detectors/loginradius/loginradius.go b/pkg/detectors/loginradius/loginradius.go index b357b0211cc1..eb3394248a2d 100644 --- a/pkg/detectors/loginradius/loginradius.go +++ b/pkg/detectors/loginradius/loginradius.go @@ -52,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/logzio/logzio.go b/pkg/detectors/logzio/logzio.go index 265dd6918d27..50b7d3d83259 100644 --- a/pkg/detectors/logzio/logzio.go +++ b/pkg/detectors/logzio/logzio.go @@ -3,10 +3,11 @@ package logzio import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -59,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json; charset=utf-8") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode == 401 { diff --git a/pkg/detectors/loyverse/loyverse.go b/pkg/detectors/loyverse/loyverse.go index 1434256dcecf..94a88229e34f 100644 --- a/pkg/detectors/loyverse/loyverse.go +++ b/pkg/detectors/loyverse/loyverse.go @@ -3,10 +3,11 @@ package loyverse import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/lunchmoney/lunchmoney.go b/pkg/detectors/lunchmoney/lunchmoney.go index 7baf1387601d..e26faef5f322 100644 --- a/pkg/detectors/lunchmoney/lunchmoney.go +++ b/pkg/detectors/lunchmoney/lunchmoney.go @@ -3,10 +3,11 @@ package lunchmoney import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/luno/luno.go b/pkg/detectors/luno/luno.go index 262c5db1934e..03c2ec50c48e 100644 --- a/pkg/detectors/luno/luno.go +++ b/pkg/detectors/luno/luno.go @@ -2,10 +2,11 @@ package luno import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -60,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.SetBasicAuth(userPatMatch, tokenPatMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/m3o/m3o.go b/pkg/detectors/m3o/m3o.go index a510e32d9d30..90509c6cd7d3 100644 --- a/pkg/detectors/m3o/m3o.go +++ b/pkg/detectors/m3o/m3o.go @@ -3,10 +3,11 @@ package m3o import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -58,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/madkudu/madkudu.go b/pkg/detectors/madkudu/madkudu.go index 8dc391d30163..97570bb0a5bf 100644 --- a/pkg/detectors/madkudu/madkudu.go +++ b/pkg/detectors/madkudu/madkudu.go @@ -2,10 +2,11 @@ package madkudu import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.SetBasicAuth(resMatch, "") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/magicbell/magicbell.go b/pkg/detectors/magicbell/magicbell.go index 6252058aa9a1..4bfb6870315f 100644 --- a/pkg/detectors/magicbell/magicbell.go +++ b/pkg/detectors/magicbell/magicbell.go @@ -63,7 +63,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-MAGICBELL-USER-EMAIL", emailMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/magnetic/magnetic.go b/pkg/detectors/magnetic/magnetic.go index f25e63c23418..4dd370e99fe5 100644 --- a/pkg/detectors/magnetic/magnetic.go +++ b/pkg/detectors/magnetic/magnetic.go @@ -2,10 +2,11 @@ package magnetic import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -51,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/mailboxlayer/mailboxlayer.go b/pkg/detectors/mailboxlayer/mailboxlayer.go index a7b48ea91006..48f451b9bbcb 100644 --- a/pkg/detectors/mailboxlayer/mailboxlayer.go +++ b/pkg/detectors/mailboxlayer/mailboxlayer.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { continue diff --git a/pkg/detectors/mailchimp/mailchimp.go b/pkg/detectors/mailchimp/mailchimp.go index 84f862ce780c..ee430730e914 100644 --- a/pkg/detectors/mailchimp/mailchimp.go +++ b/pkg/detectors/mailchimp/mailchimp.go @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("accept", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { result.Verified = true } diff --git a/pkg/detectors/mailerlite/mailerlite.go b/pkg/detectors/mailerlite/mailerlite.go index c6facbbcd944..1b2019b21d93 100644 --- a/pkg/detectors/mailerlite/mailerlite.go +++ b/pkg/detectors/mailerlite/mailerlite.go @@ -2,10 +2,11 @@ package mailerlite import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-MailerLite-ApiKey", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/mailgun/mailgun.go b/pkg/detectors/mailgun/mailgun.go index 0f6cc497e321..47359d7d46f9 100644 --- a/pkg/detectors/mailgun/mailgun.go +++ b/pkg/detectors/mailgun/mailgun.go @@ -103,7 +103,8 @@ func verifyMatch(ctx context.Context, client *http.Client, token string) (bool, _ = res.Body.Close() }() - if res.StatusCode == http.StatusOK { + switch res.StatusCode { + case http.StatusOK: var domains domainResponse if err := json.NewDecoder(res.Body).Decode(&domains); err != nil { return false, nil, fmt.Errorf("error decoding response body: %w", err) @@ -132,9 +133,9 @@ func verifyMatch(ctx context.Context, client *http.Client, token string) (bool, } return true, extraData, nil - } else if res.StatusCode == http.StatusUnauthorized { + case http.StatusUnauthorized: return false, nil, nil - } else { + default: return false, nil, fmt.Errorf("unexpected HTTP response status %d", res.StatusCode) } } diff --git a/pkg/detectors/mailjetbasicauth/mailjetbasicauth.go b/pkg/detectors/mailjetbasicauth/mailjetbasicauth.go index 09a66a2e97c5..53b73ba46c84 100644 --- a/pkg/detectors/mailjetbasicauth/mailjetbasicauth.go +++ b/pkg/detectors/mailjetbasicauth/mailjetbasicauth.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/mailjetsms/mailjetsms.go b/pkg/detectors/mailjetsms/mailjetsms.go index 871a5a68cd07..e88500d01eed 100644 --- a/pkg/detectors/mailjetsms/mailjetsms.go +++ b/pkg/detectors/mailjetsms/mailjetsms.go @@ -3,10 +3,11 @@ package mailjetsms import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/mailmodo/mailmodo.go b/pkg/detectors/mailmodo/mailmodo.go index f3781d60288a..eeebb0971c99 100644 --- a/pkg/detectors/mailmodo/mailmodo.go +++ b/pkg/detectors/mailmodo/mailmodo.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("mmApiKey", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/mailsac/mailsac.go b/pkg/detectors/mailsac/mailsac.go index ad6ff4010cd8..733afaefa9ef 100644 --- a/pkg/detectors/mailsac/mailsac.go +++ b/pkg/detectors/mailsac/mailsac.go @@ -2,10 +2,11 @@ package mailsac import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Mailsac-Key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/mandrill/mandrill.go b/pkg/detectors/mandrill/mandrill.go index 9b4a16f2efa2..3d25cb04ad85 100644 --- a/pkg/detectors/mandrill/mandrill.go +++ b/pkg/detectors/mandrill/mandrill.go @@ -3,10 +3,11 @@ package mandrill import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/manifest/manifest.go b/pkg/detectors/manifest/manifest.go index f33a6a669ae6..2a4ba92bcda1 100644 --- a/pkg/detectors/manifest/manifest.go +++ b/pkg/detectors/manifest/manifest.go @@ -2,10 +2,11 @@ package manifest import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/mapbox/mapbox.go b/pkg/detectors/mapbox/mapbox.go index d2feda74b515..53482d2a387f 100644 --- a/pkg/detectors/mapbox/mapbox.go +++ b/pkg/detectors/mapbox/mapbox.go @@ -57,7 +57,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/mapquest/mapquest.go b/pkg/detectors/mapquest/mapquest.go index 30efb0f55e63..e771f2a5338d 100644 --- a/pkg/detectors/mapquest/mapquest.go +++ b/pkg/detectors/mapquest/mapquest.go @@ -2,10 +2,11 @@ package mapquest import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -51,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/marketstack/marketstack.go b/pkg/detectors/marketstack/marketstack.go index 1f5c3fc23a96..4ab8bfe421eb 100644 --- a/pkg/detectors/marketstack/marketstack.go +++ b/pkg/detectors/marketstack/marketstack.go @@ -3,10 +3,11 @@ package marketstack import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/mattermostpersonaltoken/mattermostpersonaltoken.go b/pkg/detectors/mattermostpersonaltoken/mattermostpersonaltoken.go index 28b097bf49b1..73938cc872b0 100644 --- a/pkg/detectors/mattermostpersonaltoken/mattermostpersonaltoken.go +++ b/pkg/detectors/mattermostpersonaltoken/mattermostpersonaltoken.go @@ -65,7 +65,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/mavenlink/mavenlink.go b/pkg/detectors/mavenlink/mavenlink.go index 961ed4c07f19..2474385e6785 100644 --- a/pkg/detectors/mavenlink/mavenlink.go +++ b/pkg/detectors/mavenlink/mavenlink.go @@ -3,10 +3,11 @@ package mavenlink import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/maxmindlicense/v1/maxmindlicense.go b/pkg/detectors/maxmindlicense/v1/maxmindlicense.go index da21ec8998ef..e278a644625c 100644 --- a/pkg/detectors/maxmindlicense/v1/maxmindlicense.go +++ b/pkg/detectors/maxmindlicense/v1/maxmindlicense.go @@ -67,7 +67,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.SetBasicAuth(idRes, keyRes) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/meaningcloud/meaningcloud.go b/pkg/detectors/meaningcloud/meaningcloud.go index 8428e6877f2d..d912813701fa 100644 --- a/pkg/detectors/meaningcloud/meaningcloud.go +++ b/pkg/detectors/meaningcloud/meaningcloud.go @@ -4,12 +4,13 @@ import ( "bytes" "context" "encoding/json" - regexp "github.com/wasilibs/go-re2" "io" "mime/multipart" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -71,7 +72,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err != nil { continue } - writer.Close() + _ = writer.Close() req, err := http.NewRequestWithContext(ctx, "POST", "https://api.meaningcloud.com/lang-4.0/identification", bytes.NewReader(body.Bytes())) if err != nil { continue @@ -79,7 +80,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", writer.FormDataContentType()) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { var r response if err := json.NewDecoder(res.Body).Decode(&r); err != nil { diff --git a/pkg/detectors/mediastack/mediastack.go b/pkg/detectors/mediastack/mediastack.go index ac44fe833929..ffacab9adc70 100644 --- a/pkg/detectors/mediastack/mediastack.go +++ b/pkg/detectors/mediastack/mediastack.go @@ -3,11 +3,12 @@ package mediastack import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" "time" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -55,7 +56,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/meistertask/meistertask.go b/pkg/detectors/meistertask/meistertask.go index e6b5e346e121..a8161c67fee1 100644 --- a/pkg/detectors/meistertask/meistertask.go +++ b/pkg/detectors/meistertask/meistertask.go @@ -3,10 +3,11 @@ package meistertask import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/mesibo/mesibo.go b/pkg/detectors/mesibo/mesibo.go index 2dcc70344ba2..83e30a89588b 100644 --- a/pkg/detectors/mesibo/mesibo.go +++ b/pkg/detectors/mesibo/mesibo.go @@ -96,7 +96,7 @@ func (s Scanner) verify(ctx context.Context, token string) (bool, error) { if err != nil { return false, fmt.Errorf("failed to execute request: %w", err) } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() // The backend API always returns HTTP 200, with the actual result encoded in the // JSON response body. diff --git a/pkg/detectors/messagebird/messagebird.go b/pkg/detectors/messagebird/messagebird.go index 59c164f214f7..6a9e07cbf62a 100644 --- a/pkg/detectors/messagebird/messagebird.go +++ b/pkg/detectors/messagebird/messagebird.go @@ -3,10 +3,11 @@ package messagebird import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("AccessKey %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/metaapi/metaapi.go b/pkg/detectors/metaapi/metaapi.go index 93b8939f7159..301cac6e4997 100644 --- a/pkg/detectors/metaapi/metaapi.go +++ b/pkg/detectors/metaapi/metaapi.go @@ -3,11 +3,12 @@ package metaapi import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -62,7 +63,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("apikey", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() body, errBody := io.ReadAll(res.Body) if errBody == nil { diff --git a/pkg/detectors/metabase/metabase.go b/pkg/detectors/metabase/metabase.go index 406bebc7a191..289f1e32e513 100644 --- a/pkg/detectors/metabase/metabase.go +++ b/pkg/detectors/metabase/metabase.go @@ -73,7 +73,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-Metabase-Session", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() body, err := io.ReadAll(res.Body) if err != nil { continue diff --git a/pkg/detectors/metrilo/metrilo.go b/pkg/detectors/metrilo/metrilo.go index daa2202c9214..b9d6d96bbdec 100644 --- a/pkg/detectors/metrilo/metrilo.go +++ b/pkg/detectors/metrilo/metrilo.go @@ -2,10 +2,11 @@ package metrilo import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Length", `0`) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/microsoftteamswebhook/microsoftteamswebhook.go b/pkg/detectors/microsoftteamswebhook/microsoftteamswebhook.go index 4a5c993c313e..823e6cd9396f 100644 --- a/pkg/detectors/microsoftteamswebhook/microsoftteamswebhook.go +++ b/pkg/detectors/microsoftteamswebhook/microsoftteamswebhook.go @@ -81,7 +81,7 @@ func verifyWebhook(ctx context.Context, client *http.Client, webhookURL string) if err != nil { return false, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() body, err := io.ReadAll(res.Body) if err != nil { diff --git a/pkg/detectors/mindmeister/mindmeister.go b/pkg/detectors/mindmeister/mindmeister.go index 5f9f045dd26b..c8ee0c18638f 100644 --- a/pkg/detectors/mindmeister/mindmeister.go +++ b/pkg/detectors/mindmeister/mindmeister.go @@ -3,11 +3,12 @@ package mindmeister import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -58,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err == nil { bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `"stat":"ok"`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { s1.Verified = true diff --git a/pkg/detectors/miro/miro.go b/pkg/detectors/miro/miro.go index 535ea078436a..618d23d30920 100644 --- a/pkg/detectors/miro/miro.go +++ b/pkg/detectors/miro/miro.go @@ -3,10 +3,11 @@ package miro import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/mite/mite.go b/pkg/detectors/mite/mite.go index e21554ca8495..c91c75d2ecb4 100644 --- a/pkg/detectors/mite/mite.go +++ b/pkg/detectors/mite/mite.go @@ -60,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-MiteApiKey", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/mixmax/mixmax.go b/pkg/detectors/mixmax/mixmax.go index de8e26e61973..d83b5c0c36ff 100644 --- a/pkg/detectors/mixmax/mixmax.go +++ b/pkg/detectors/mixmax/mixmax.go @@ -2,10 +2,11 @@ package mixmax import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-API-Token", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/mixpanel/mixpanel.go b/pkg/detectors/mixpanel/mixpanel.go index 9a2e63d1e59f..76d01a80fd66 100644 --- a/pkg/detectors/mixpanel/mixpanel.go +++ b/pkg/detectors/mixpanel/mixpanel.go @@ -2,10 +2,11 @@ package mixpanel import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -60,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.SetBasicAuth(userPatMatch, tokenPatMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/mockaroo/mockaroo.go b/pkg/detectors/mockaroo/mockaroo.go index c005331aa435..55e152b453f2 100644 --- a/pkg/detectors/mockaroo/mockaroo.go +++ b/pkg/detectors/mockaroo/mockaroo.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { var t typeRes err = json.NewDecoder(res.Body).Decode(&t) diff --git a/pkg/detectors/moderation/moderation.go b/pkg/detectors/moderation/moderation.go index ade9f0b15e3e..2a12d69d804f 100644 --- a/pkg/detectors/moderation/moderation.go +++ b/pkg/detectors/moderation/moderation.go @@ -60,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/mongodb/mongodb.go b/pkg/detectors/mongodb/mongodb.go index 604d8bdb8f99..601bde7acff5 100644 --- a/pkg/detectors/mongodb/mongodb.go +++ b/pkg/detectors/mongodb/mongodb.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } // If the query string contains `&` the options will not be parsed. - connStr := strings.Replace(strings.TrimSpace(match[1]), "&", "&", -1) + connStr := strings.ReplaceAll(strings.TrimSpace(match[1]), "&", "&") connUrl, err := url.Parse(connStr) if err != nil { logger.V(3).Info("Skipping invalid URL", "err", err) diff --git a/pkg/detectors/monkeylearn/monkeylearn.go b/pkg/detectors/monkeylearn/monkeylearn.go index 938be4f77e72..a2a1ed2e2f7f 100644 --- a/pkg/detectors/monkeylearn/monkeylearn.go +++ b/pkg/detectors/monkeylearn/monkeylearn.go @@ -3,10 +3,11 @@ package monkeylearn import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Token %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/moonclerk/moonclerk.go b/pkg/detectors/moonclerk/moonclerk.go index 3bf6115dc39b..1014d6c34880 100644 --- a/pkg/detectors/moonclerk/moonclerk.go +++ b/pkg/detectors/moonclerk/moonclerk.go @@ -2,10 +2,11 @@ package moonclerk import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", "Token token="+resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/moosend/moosend.go b/pkg/detectors/moosend/moosend.go index 75e5b8446905..3b3951e5c954 100644 --- a/pkg/detectors/moosend/moosend.go +++ b/pkg/detectors/moosend/moosend.go @@ -2,11 +2,12 @@ package moosend import ( "context" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { continue diff --git a/pkg/detectors/moralis/moralis.go b/pkg/detectors/moralis/moralis.go index ae505af22dc0..eb74e6e0f201 100644 --- a/pkg/detectors/moralis/moralis.go +++ b/pkg/detectors/moralis/moralis.go @@ -2,10 +2,11 @@ package moralis import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-API-Key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/mrticktock/mrticktock.go b/pkg/detectors/mrticktock/mrticktock.go index 4452a5713c8f..c783d8995c0b 100644 --- a/pkg/detectors/mrticktock/mrticktock.go +++ b/pkg/detectors/mrticktock/mrticktock.go @@ -65,7 +65,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/x-www-form-urlencoded") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { continue diff --git a/pkg/detectors/mux/mux.go b/pkg/detectors/mux/mux.go index 3f0781fcc718..298f7ec049a0 100644 --- a/pkg/detectors/mux/mux.go +++ b/pkg/detectors/mux/mux.go @@ -61,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.SetBasicAuth(resMatch, resSecretMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/myfreshworks/myfreshworks.go b/pkg/detectors/myfreshworks/myfreshworks.go index 9790fb78c753..307dadbec047 100644 --- a/pkg/detectors/myfreshworks/myfreshworks.go +++ b/pkg/detectors/myfreshworks/myfreshworks.go @@ -4,11 +4,12 @@ import ( "context" "encoding/json" "fmt" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -86,7 +87,7 @@ func verifyMyfreshworks(ctx context.Context, client *http.Client, resMatch, resI if err != nil { return false, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode == http.StatusOK { body, err := io.ReadAll(res.Body) @@ -95,7 +96,7 @@ func verifyMyfreshworks(ctx context.Context, client *http.Client, resMatch, resI } return json.Valid(body), nil - } else if !(res.StatusCode == http.StatusUnauthorized || res.StatusCode == http.StatusForbidden) { + } else if res.StatusCode != http.StatusUnauthorized && res.StatusCode != http.StatusForbidden { return false, fmt.Errorf("unexpected HTTP response status %d", res.StatusCode) } diff --git a/pkg/detectors/myintervals/myintervals.go b/pkg/detectors/myintervals/myintervals.go index d802115b4051..5887442a890f 100644 --- a/pkg/detectors/myintervals/myintervals.go +++ b/pkg/detectors/myintervals/myintervals.go @@ -4,10 +4,11 @@ import ( "context" b64 "encoding/base64" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -57,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", sEnc)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/nasdaqdatalink/nasdaqdatalink.go b/pkg/detectors/nasdaqdatalink/nasdaqdatalink.go index 283b8a1f53be..f4ea104a4aec 100644 --- a/pkg/detectors/nasdaqdatalink/nasdaqdatalink.go +++ b/pkg/detectors/nasdaqdatalink/nasdaqdatalink.go @@ -3,11 +3,12 @@ package nasdaqdatalink import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" "time" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -55,7 +56,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/nethunt/nethunt.go b/pkg/detectors/nethunt/nethunt.go index 649e613ddd44..d68978b26829 100644 --- a/pkg/detectors/nethunt/nethunt.go +++ b/pkg/detectors/nethunt/nethunt.go @@ -2,10 +2,11 @@ package nethunt import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -60,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.SetBasicAuth(userPatMatch, tokenPatMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/netsuite/netsuite.go b/pkg/detectors/netsuite/netsuite.go index 10f44889599c..82ce63ef5c44 100644 --- a/pkg/detectors/netsuite/netsuite.go +++ b/pkg/detectors/netsuite/netsuite.go @@ -127,7 +127,7 @@ func (s Scanner) Description() string { func verifyCredentials(ctx context.Context, client *http.Client, cs credentialSet) (bool, error) { // for url, filter or replace underscore in accountID if needed and lower case the accountID - urlAccountId := strings.ToLower(strings.Replace(cs.accountID, "_", "-", -1)) + urlAccountId := strings.ToLower(strings.ReplaceAll(cs.accountID, "_", "-")) baseUrl := "https://" + urlAccountId + ".suitetalk.api.netsuite.com" @@ -169,7 +169,7 @@ func verifyCredentials(ctx context.Context, client *http.Client, cs credentialSe } return false, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() switch res.StatusCode { case http.StatusOK: return true, nil diff --git a/pkg/detectors/neutrinoapi/neutrinoapi.go b/pkg/detectors/neutrinoapi/neutrinoapi.go index 5bcbd0c1cbfb..16a577c0abe3 100644 --- a/pkg/detectors/neutrinoapi/neutrinoapi.go +++ b/pkg/detectors/neutrinoapi/neutrinoapi.go @@ -4,12 +4,13 @@ import ( "bytes" "context" "fmt" - regexp "github.com/wasilibs/go-re2" "io" "mime/multipart" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -67,7 +68,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err != nil { continue } - writer.Close() + _ = writer.Close() req, err := http.NewRequestWithContext(ctx, "POST", fmt.Sprintf("https://neutrinoapi.net/url-info?user-id=%s&api-key=%s", resIdMatch, resMatch), bytes.NewReader(body.Bytes())) if err != nil { continue @@ -75,7 +76,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", writer.FormDataContentType()) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/newrelicpersonalapikey/newrelicpersonalapikey.go b/pkg/detectors/newrelicpersonalapikey/newrelicpersonalapikey.go index 56dc90e458de..cea6dd87c4cf 100644 --- a/pkg/detectors/newrelicpersonalapikey/newrelicpersonalapikey.go +++ b/pkg/detectors/newrelicpersonalapikey/newrelicpersonalapikey.go @@ -58,12 +58,12 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result resEU, errEU := client.Do(reqEU) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } } else if errEU == nil { - defer resEU.Body.Close() + defer func() { _ = resEU.Body.Close() }() if resEU.StatusCode >= 200 && resEU.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/newsapi/newsapi.go b/pkg/detectors/newsapi/newsapi.go index b928f01419bf..1ab3dee1fdf8 100644 --- a/pkg/detectors/newsapi/newsapi.go +++ b/pkg/detectors/newsapi/newsapi.go @@ -2,10 +2,11 @@ package newsapi import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -51,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/newscatcher/newscatcher.go b/pkg/detectors/newscatcher/newscatcher.go index 47a7bdd6d21d..3ff0e0c7a80f 100644 --- a/pkg/detectors/newscatcher/newscatcher.go +++ b/pkg/detectors/newscatcher/newscatcher.go @@ -2,10 +2,11 @@ package newscatcher import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("x-api-key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/nexmoapikey/nexmoapikey.go b/pkg/detectors/nexmoapikey/nexmoapikey.go index a3969ac53d0c..1cc0bd50640f 100644 --- a/pkg/detectors/nexmoapikey/nexmoapikey.go +++ b/pkg/detectors/nexmoapikey/nexmoapikey.go @@ -2,10 +2,11 @@ package nexmoapikey import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -61,7 +62,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/nftport/nftport.go b/pkg/detectors/nftport/nftport.go index 155cd217dcb0..0dd666d0acde 100644 --- a/pkg/detectors/nftport/nftport.go +++ b/pkg/detectors/nftport/nftport.go @@ -2,10 +2,11 @@ package nftport import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/ngc/ngc.go b/pkg/detectors/ngc/ngc.go index 79b1b2f12938..9cd1e1644d78 100644 --- a/pkg/detectors/ngc/ngc.go +++ b/pkg/detectors/ngc/ngc.go @@ -3,10 +3,11 @@ package ngc import ( "context" "encoding/base64" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -63,7 +64,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/nicereply/nicereply.go b/pkg/detectors/nicereply/nicereply.go index f70b5875ba4a..6ee0917de462 100644 --- a/pkg/detectors/nicereply/nicereply.go +++ b/pkg/detectors/nicereply/nicereply.go @@ -4,10 +4,11 @@ import ( "context" b64 "encoding/base64" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -56,7 +57,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", sEnc)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/nightfall/nightfall.go b/pkg/detectors/nightfall/nightfall.go index 6e0cfface20a..382b5e4708fa 100644 --- a/pkg/detectors/nightfall/nightfall.go +++ b/pkg/detectors/nightfall/nightfall.go @@ -3,10 +3,11 @@ package nightfall import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -56,7 +57,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/nimble/nimble.go b/pkg/detectors/nimble/nimble.go index 7b85199941cf..5102b933b254 100644 --- a/pkg/detectors/nimble/nimble.go +++ b/pkg/detectors/nimble/nimble.go @@ -3,10 +3,11 @@ package nimble import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/noticeable/noticeable.go b/pkg/detectors/noticeable/noticeable.go index 505ff9b67f8d..0cbda5544b09 100644 --- a/pkg/detectors/noticeable/noticeable.go +++ b/pkg/detectors/noticeable/noticeable.go @@ -3,10 +3,11 @@ package noticeable import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -55,7 +56,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Apikey %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/notion/notion.go b/pkg/detectors/notion/notion.go index e7a2d751deea..79724a30a0ad 100644 --- a/pkg/detectors/notion/notion.go +++ b/pkg/detectors/notion/notion.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 || res.StatusCode == 403 { // if >= 200 and < 300, the secret is valid and has privileges for the /v1/users endpoint // If 403, the secret is valid, but does not have privileges for the /v1/users endpoint, diff --git a/pkg/detectors/nozbeteams/nozbeteams.go b/pkg/detectors/nozbeteams/nozbeteams.go index c30252e530ac..33edc2dcd5f6 100644 --- a/pkg/detectors/nozbeteams/nozbeteams.go +++ b/pkg/detectors/nozbeteams/nozbeteams.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/npmtoken/npmtoken.go b/pkg/detectors/npmtoken/npmtoken.go index 9f4e957509b2..886cba5bf9cc 100644 --- a/pkg/detectors/npmtoken/npmtoken.go +++ b/pkg/detectors/npmtoken/npmtoken.go @@ -57,7 +57,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true s1.SecretParts = map[string]string{ diff --git a/pkg/detectors/npmtokenv2/npmtokenv2.go b/pkg/detectors/npmtokenv2/npmtokenv2.go index 1a6e36fc4c6d..040fa7dfe8b1 100644 --- a/pkg/detectors/npmtokenv2/npmtokenv2.go +++ b/pkg/detectors/npmtokenv2/npmtokenv2.go @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true s1.SecretParts = map[string]string{ diff --git a/pkg/detectors/nugetapikey/nugetapikey.go b/pkg/detectors/nugetapikey/nugetapikey.go index 19f8bba82c5a..0340bc006c71 100644 --- a/pkg/detectors/nugetapikey/nugetapikey.go +++ b/pkg/detectors/nugetapikey/nugetapikey.go @@ -2,10 +2,11 @@ package nugetapikey import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-NuGet-ApiKey", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() // we can either match on response code "400" or "Bad Request" response if res.StatusCode == 400 { s1.Verified = true diff --git a/pkg/detectors/numverify/numverify.go b/pkg/detectors/numverify/numverify.go index 4d907c1919dd..0b7793144b16 100644 --- a/pkg/detectors/numverify/numverify.go +++ b/pkg/detectors/numverify/numverify.go @@ -3,11 +3,12 @@ package numverify import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err == nil { bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `country_code`) || strings.Contains(bodyString, `"info":"Access Restricted - Your current Subscription Plan does not support HTTPS Encryption."`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { s1.Verified = true diff --git a/pkg/detectors/nutritionix/nutritionix.go b/pkg/detectors/nutritionix/nutritionix.go index 086c4392511e..e70c55c84fcc 100644 --- a/pkg/detectors/nutritionix/nutritionix.go +++ b/pkg/detectors/nutritionix/nutritionix.go @@ -2,10 +2,11 @@ package nutritionix import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -63,7 +64,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("x-app-key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/nylas/nylas.go b/pkg/detectors/nylas/nylas.go index 8c779901aba4..c6579b1c6514 100644 --- a/pkg/detectors/nylas/nylas.go +++ b/pkg/detectors/nylas/nylas.go @@ -3,10 +3,11 @@ package nylas import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/oanda/oanda.go b/pkg/detectors/oanda/oanda.go index 3715d8444730..6eabcafdd87a 100644 --- a/pkg/detectors/oanda/oanda.go +++ b/pkg/detectors/oanda/oanda.go @@ -3,10 +3,11 @@ package oanda import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/okta/okta.go b/pkg/detectors/okta/okta.go index 56b7bad686fe..27e22d2c631c 100644 --- a/pkg/detectors/okta/okta.go +++ b/pkg/detectors/okta/okta.go @@ -98,7 +98,7 @@ func verifyOktaToken(ctx context.Context, client *http.Client, domain, token str if err != nil { return false, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() switch resp.StatusCode { case http.StatusOK: diff --git a/pkg/detectors/omnisend/omnisend.go b/pkg/detectors/omnisend/omnisend.go index 70ea501c7900..70f315841b4f 100644 --- a/pkg/detectors/omnisend/omnisend.go +++ b/pkg/detectors/omnisend/omnisend.go @@ -2,10 +2,11 @@ package omnisend import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-API-KEY", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/onedesk/onedesk.go b/pkg/detectors/onedesk/onedesk.go index 475c0fb8b60a..83b1ee06f2a5 100644 --- a/pkg/detectors/onedesk/onedesk.go +++ b/pkg/detectors/onedesk/onedesk.go @@ -65,7 +65,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { continue diff --git a/pkg/detectors/onelogin/onelogin.go b/pkg/detectors/onelogin/onelogin.go index 64b7a10582f8..699e129fb621 100644 --- a/pkg/detectors/onelogin/onelogin.go +++ b/pkg/detectors/onelogin/onelogin.go @@ -3,11 +3,12 @@ package onelogin import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" "time" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" ) @@ -65,7 +66,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json; charset=utf-8") res, err := client.Do(req) if err == nil { - res.Body.Close() // The request body is unused. + _ = res.Body.Close() // The request body is unused. if res.StatusCode >= 200 && res.StatusCode < 300 { result.Verified = true diff --git a/pkg/detectors/onepagecrm/onepagecrm.go b/pkg/detectors/onepagecrm/onepagecrm.go index 536a865d49b2..adbbcc598db0 100644 --- a/pkg/detectors/onepagecrm/onepagecrm.go +++ b/pkg/detectors/onepagecrm/onepagecrm.go @@ -2,10 +2,11 @@ package onepagecrm import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -59,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.SetBasicAuth(userPatMatch, tokenPatMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/onesignal/onesignal.go b/pkg/detectors/onesignal/onesignal.go index 839007378651..3843161ce332 100644 --- a/pkg/detectors/onesignal/onesignal.go +++ b/pkg/detectors/onesignal/onesignal.go @@ -4,10 +4,11 @@ import ( "context" b64 "encoding/base64" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -57,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", sEnc)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/oopspam/oopspam.go b/pkg/detectors/oopspam/oopspam.go index 92d398a5e31d..f39759f50d9a 100644 --- a/pkg/detectors/oopspam/oopspam.go +++ b/pkg/detectors/oopspam/oopspam.go @@ -2,10 +2,11 @@ package oopspam import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-Api-Key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/opencagedata/opencagedata.go b/pkg/detectors/opencagedata/opencagedata.go index 2c61bb5a5cbc..9010a3ae2fc4 100644 --- a/pkg/detectors/opencagedata/opencagedata.go +++ b/pkg/detectors/opencagedata/opencagedata.go @@ -3,10 +3,11 @@ package opencagedata import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/openuv/openuv.go b/pkg/detectors/openuv/openuv.go index daeaf7be69e6..af0ffbd18840 100644 --- a/pkg/detectors/openuv/openuv.go +++ b/pkg/detectors/openuv/openuv.go @@ -2,10 +2,11 @@ package openuv import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("x-access-token", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/openvpn/openvpn.go b/pkg/detectors/openvpn/openvpn.go index 1feca62e4b78..fc157dfd23a3 100644 --- a/pkg/detectors/openvpn/openvpn.go +++ b/pkg/detectors/openvpn/openvpn.go @@ -81,7 +81,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("content-type", "application/x-www-form-urlencoded") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode == 401 { diff --git a/pkg/detectors/openweather/openweather.go b/pkg/detectors/openweather/openweather.go index 8d8895dfb435..9ae6567da9c2 100644 --- a/pkg/detectors/openweather/openweather.go +++ b/pkg/detectors/openweather/openweather.go @@ -2,10 +2,11 @@ package openweather import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/optimizely/optimizely.go b/pkg/detectors/optimizely/optimizely.go index 55827f93ff0f..4392470d8118 100644 --- a/pkg/detectors/optimizely/optimizely.go +++ b/pkg/detectors/optimizely/optimizely.go @@ -3,10 +3,11 @@ package optimizely import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/overloop/overloop.go b/pkg/detectors/overloop/overloop.go index 93e5c7ecd52a..a8e10d0b0cb4 100644 --- a/pkg/detectors/overloop/overloop.go +++ b/pkg/detectors/overloop/overloop.go @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Set("Authorization", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode == 401 { diff --git a/pkg/detectors/owlbot/owlbot.go b/pkg/detectors/owlbot/owlbot.go index 34725279dcf8..95a5840d7b16 100644 --- a/pkg/detectors/owlbot/owlbot.go +++ b/pkg/detectors/owlbot/owlbot.go @@ -3,10 +3,11 @@ package owlbot import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Token %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/packagecloud/packagecloud.go b/pkg/detectors/packagecloud/packagecloud.go index 2b5055a469cd..6c619adba708 100644 --- a/pkg/detectors/packagecloud/packagecloud.go +++ b/pkg/detectors/packagecloud/packagecloud.go @@ -2,10 +2,11 @@ package packagecloud import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.SetBasicAuth(resMatch, "") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/pagerdutyapikey/pagerdutyapikey.go b/pkg/detectors/pagerdutyapikey/pagerdutyapikey.go index 01aefe3ef921..a61f2ee00974 100644 --- a/pkg/detectors/pagerdutyapikey/pagerdutyapikey.go +++ b/pkg/detectors/pagerdutyapikey/pagerdutyapikey.go @@ -80,7 +80,7 @@ func verifyPagerdutyapikey(ctx context.Context, client *http.Client, token strin if err != nil { return false, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() switch res.StatusCode { case http.StatusOK: diff --git a/pkg/detectors/pandadoc/pandadoc.go b/pkg/detectors/pandadoc/pandadoc.go index 9ee3ef07cdb4..9c471a33f546 100644 --- a/pkg/detectors/pandadoc/pandadoc.go +++ b/pkg/detectors/pandadoc/pandadoc.go @@ -3,10 +3,11 @@ package pandadoc import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("API-Key %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/pandascore/pandascore.go b/pkg/detectors/pandascore/pandascore.go index e4b24cfa49b8..4caffed79a1c 100644 --- a/pkg/detectors/pandascore/pandascore.go +++ b/pkg/detectors/pandascore/pandascore.go @@ -3,10 +3,11 @@ package pandascore import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else { diff --git a/pkg/detectors/paperform/paperform.go b/pkg/detectors/paperform/paperform.go index 84e78f9e112b..61bd259f310e 100644 --- a/pkg/detectors/paperform/paperform.go +++ b/pkg/detectors/paperform/paperform.go @@ -3,10 +3,11 @@ package paperform import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/paralleldots/paralleldots.go b/pkg/detectors/paralleldots/paralleldots.go index fd65488c44b7..b39d9c82fd39 100644 --- a/pkg/detectors/paralleldots/paralleldots.go +++ b/pkg/detectors/paralleldots/paralleldots.go @@ -3,12 +3,13 @@ package paralleldots import ( "bytes" "context" - regexp "github.com/wasilibs/go-re2" "io" "mime/multipart" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -66,7 +67,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err != nil { continue } - writer.Close() + _ = writer.Close() req, err := http.NewRequestWithContext(ctx, "POST", "https://apis.paralleldots.com/v4/intent", bytes.NewReader(payload.Bytes())) if err != nil { continue @@ -74,7 +75,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", writer.FormDataContentType()) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { continue diff --git a/pkg/detectors/parsehub/parsehub.go b/pkg/detectors/parsehub/parsehub.go index 0323924561d3..1732a52c5c41 100644 --- a/pkg/detectors/parsehub/parsehub.go +++ b/pkg/detectors/parsehub/parsehub.go @@ -3,10 +3,11 @@ package parsehub import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/parsers/parsers.go b/pkg/detectors/parsers/parsers.go index f71d32e3234c..1398fecff741 100644 --- a/pkg/detectors/parsers/parsers.go +++ b/pkg/detectors/parsers/parsers.go @@ -2,10 +2,11 @@ package parsers import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("x-api-key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/parseur/parseur.go b/pkg/detectors/parseur/parseur.go index 0d068f1333c5..edf5a04a7005 100644 --- a/pkg/detectors/parseur/parseur.go +++ b/pkg/detectors/parseur/parseur.go @@ -73,7 +73,7 @@ func verifyResult(ctx context.Context, client *http.Client, token string) (bool, return false, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { return true, nil } diff --git a/pkg/detectors/partnerstack/partnerstack.go b/pkg/detectors/partnerstack/partnerstack.go index 3ab42b13cd84..22dd40178339 100644 --- a/pkg/detectors/partnerstack/partnerstack.go +++ b/pkg/detectors/partnerstack/partnerstack.go @@ -3,10 +3,11 @@ package partnerstack import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/pastebin/pastebin.go b/pkg/detectors/pastebin/pastebin.go index 5b585fb42576..c5d6d3f36af4 100644 --- a/pkg/detectors/pastebin/pastebin.go +++ b/pkg/detectors/pastebin/pastebin.go @@ -3,12 +3,13 @@ package pastebin import ( "bytes" "context" - regexp "github.com/wasilibs/go-re2" "io" "mime/multipart" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -74,7 +75,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err != nil { continue } - writer.Close() + _ = writer.Close() req, err := http.NewRequestWithContext(ctx, "POST", "https://pastebin.com/api/api_post.php", bytes.NewReader(body.Bytes())) if err != nil { continue @@ -82,7 +83,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", writer.FormDataContentType()) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/paydirtapp/paydirtapp.go b/pkg/detectors/paydirtapp/paydirtapp.go index 82fe2422a067..6e2560e8574e 100644 --- a/pkg/detectors/paydirtapp/paydirtapp.go +++ b/pkg/detectors/paydirtapp/paydirtapp.go @@ -2,10 +2,11 @@ package paydirtapp import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -51,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/paymoapp/paymoapp.go b/pkg/detectors/paymoapp/paymoapp.go index 58940fc00f3f..5eda513d2dbb 100644 --- a/pkg/detectors/paymoapp/paymoapp.go +++ b/pkg/detectors/paymoapp/paymoapp.go @@ -3,10 +3,11 @@ package paymoapp import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/paymongo/paymongo.go b/pkg/detectors/paymongo/paymongo.go index 20b0a2d61173..4f97ce5b66ac 100644 --- a/pkg/detectors/paymongo/paymongo.go +++ b/pkg/detectors/paymongo/paymongo.go @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.SetBasicAuth(resMatch, "") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/paypaloauth/paypaloauth.go b/pkg/detectors/paypaloauth/paypaloauth.go index c9f15264e770..6cd467d8ef51 100644 --- a/pkg/detectors/paypaloauth/paypaloauth.go +++ b/pkg/detectors/paypaloauth/paypaloauth.go @@ -4,10 +4,11 @@ import ( "context" b64 "encoding/base64" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -66,7 +67,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", encoded)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/paystack/paystack.go b/pkg/detectors/paystack/paystack.go index 5326f0919b04..c7294da3e64e 100644 --- a/pkg/detectors/paystack/paystack.go +++ b/pkg/detectors/paystack/paystack.go @@ -3,10 +3,11 @@ package paystack import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/pdflayer/pdflayer.go b/pkg/detectors/pdflayer/pdflayer.go index 24b400f1871b..710ce447ab8a 100644 --- a/pkg/detectors/pdflayer/pdflayer.go +++ b/pkg/detectors/pdflayer/pdflayer.go @@ -3,11 +3,12 @@ package pdflayer import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -57,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err == nil { bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `Contents`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { s1.Verified = true diff --git a/pkg/detectors/pdfshift/pdfshift.go b/pkg/detectors/pdfshift/pdfshift.go index 8cb9d0a6dce8..a89545cbb504 100644 --- a/pkg/detectors/pdfshift/pdfshift.go +++ b/pkg/detectors/pdfshift/pdfshift.go @@ -2,10 +2,11 @@ package pdfshift import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.SetBasicAuth("api", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/peopledatalabs/peopledatalabs.go b/pkg/detectors/peopledatalabs/peopledatalabs.go index 951e5a1775e9..e13119861843 100644 --- a/pkg/detectors/peopledatalabs/peopledatalabs.go +++ b/pkg/detectors/peopledatalabs/peopledatalabs.go @@ -2,10 +2,11 @@ package peopledatalabs import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-Api-Key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/pepipost/pepipost.go b/pkg/detectors/pepipost/pepipost.go index 18be9866f439..fa2029e75547 100644 --- a/pkg/detectors/pepipost/pepipost.go +++ b/pkg/detectors/pepipost/pepipost.go @@ -2,10 +2,11 @@ package pepipost import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("api_key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/percy/percy.go b/pkg/detectors/percy/percy.go index 81c45344c7fc..619beddef8d2 100644 --- a/pkg/detectors/percy/percy.go +++ b/pkg/detectors/percy/percy.go @@ -3,10 +3,11 @@ package percy import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Token %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/pinata/pinata.go b/pkg/detectors/pinata/pinata.go index 465dda391ec4..d22292f98651 100644 --- a/pkg/detectors/pinata/pinata.go +++ b/pkg/detectors/pinata/pinata.go @@ -2,11 +2,12 @@ package pinata import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" "time" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -65,7 +66,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("pinata_secret_api_key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/pipedream/pipedream.go b/pkg/detectors/pipedream/pipedream.go index ad48747376e4..2048e2d4108d 100644 --- a/pkg/detectors/pipedream/pipedream.go +++ b/pkg/detectors/pipedream/pipedream.go @@ -3,11 +3,12 @@ package pipedream import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" "time" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -56,7 +57,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/pipedrive/pipedrive.go b/pkg/detectors/pipedrive/pipedrive.go index 587de4427e96..81e00984887f 100644 --- a/pkg/detectors/pipedrive/pipedrive.go +++ b/pkg/detectors/pipedrive/pipedrive.go @@ -3,10 +3,11 @@ package pipedrive import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/pivotaltracker/pivotaltracker.go b/pkg/detectors/pivotaltracker/pivotaltracker.go index c872968bcaaf..23aa0e837a2d 100644 --- a/pkg/detectors/pivotaltracker/pivotaltracker.go +++ b/pkg/detectors/pivotaltracker/pivotaltracker.go @@ -2,9 +2,10 @@ package pivotaltracker import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -55,7 +56,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-TrackerToken", token) res, err := client.Do(req) if err == nil { - res.Body.Close() // The request body is unused. + _ = res.Body.Close() // The request body is unused. if res.StatusCode >= 200 && res.StatusCode < 300 { result.Verified = true diff --git a/pkg/detectors/pixabay/pixabay.go b/pkg/detectors/pixabay/pixabay.go index 37da38040b0c..efdae36956d9 100644 --- a/pkg/detectors/pixabay/pixabay.go +++ b/pkg/detectors/pixabay/pixabay.go @@ -3,10 +3,11 @@ package pixabay import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/plaidkey/plaidkey.go b/pkg/detectors/plaidkey/plaidkey.go index ff5e5f96d9f2..553e628f2c47 100644 --- a/pkg/detectors/plaidkey/plaidkey.go +++ b/pkg/detectors/plaidkey/plaidkey.go @@ -116,7 +116,7 @@ func verifyMatch(ctx context.Context, client *http.Client, id string, secret str if err != nil { return false, nil, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() switch res.StatusCode { case http.StatusOK: diff --git a/pkg/detectors/planetscale/planetscale.go b/pkg/detectors/planetscale/planetscale.go index bc50e00f16b7..da7091f7843c 100644 --- a/pkg/detectors/planetscale/planetscale.go +++ b/pkg/detectors/planetscale/planetscale.go @@ -64,7 +64,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result // Send HTTP request res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true s1.SecretParts = map[string]string{ diff --git a/pkg/detectors/planetscaledb/planetscaledb.go b/pkg/detectors/planetscaledb/planetscaledb.go index 4a9db7b9a157..8c78de0b5f16 100644 --- a/pkg/detectors/planetscaledb/planetscaledb.go +++ b/pkg/detectors/planetscaledb/planetscaledb.go @@ -70,7 +70,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } else { s1.SetVerificationError(err, password[0]) } - db.Close() + _ = db.Close() } } diff --git a/pkg/detectors/planviewleankit/planviewleankit.go b/pkg/detectors/planviewleankit/planviewleankit.go index 1aa14091d875..185037caa12a 100644 --- a/pkg/detectors/planviewleankit/planviewleankit.go +++ b/pkg/detectors/planviewleankit/planviewleankit.go @@ -60,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/planyo/planyo.go b/pkg/detectors/planyo/planyo.go index f85b7ecf193c..2880285a4b46 100644 --- a/pkg/detectors/planyo/planyo.go +++ b/pkg/detectors/planyo/planyo.go @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Accept", "application/vnd.planyo+json; version=3") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { continue diff --git a/pkg/detectors/plivo/plivo.go b/pkg/detectors/plivo/plivo.go index c47de4a29406..2af3b51d3543 100644 --- a/pkg/detectors/plivo/plivo.go +++ b/pkg/detectors/plivo/plivo.go @@ -4,10 +4,11 @@ import ( "context" b64 "encoding/base64" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -65,7 +66,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", decodeSecret)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/podio/podio.go b/pkg/detectors/podio/podio.go index 87c9390cb526..a2aef0591b88 100644 --- a/pkg/detectors/podio/podio.go +++ b/pkg/detectors/podio/podio.go @@ -3,10 +3,11 @@ package podio import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/pollsapi/pollsapi.go b/pkg/detectors/pollsapi/pollsapi.go index 6d0c92319840..34c0abcac3d1 100644 --- a/pkg/detectors/pollsapi/pollsapi.go +++ b/pkg/detectors/pollsapi/pollsapi.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("api-key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/poloniex/poloniex.go b/pkg/detectors/poloniex/poloniex.go index 584bafb14b32..5215b8df590b 100644 --- a/pkg/detectors/poloniex/poloniex.go +++ b/pkg/detectors/poloniex/poloniex.go @@ -5,13 +5,14 @@ import ( "crypto/hmac" "crypto/sha512" "encoding/hex" - regexp "github.com/wasilibs/go-re2" "net/http" "net/url" "strconv" "strings" "time" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -80,7 +81,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Sign", signature) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/polygon/polygon.go b/pkg/detectors/polygon/polygon.go index c206fc309382..5f2794b5bb5b 100644 --- a/pkg/detectors/polygon/polygon.go +++ b/pkg/detectors/polygon/polygon.go @@ -2,10 +2,11 @@ package polygon import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/portainer/portainer.go b/pkg/detectors/portainer/portainer.go index d40a99da183d..11b7ad0739d1 100644 --- a/pkg/detectors/portainer/portainer.go +++ b/pkg/detectors/portainer/portainer.go @@ -75,7 +75,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode == 401 || res.StatusCode == 403 { diff --git a/pkg/detectors/portainertoken/portainertoken.go b/pkg/detectors/portainertoken/portainertoken.go index 53947379961a..2f706141f809 100644 --- a/pkg/detectors/portainertoken/portainertoken.go +++ b/pkg/detectors/portainertoken/portainertoken.go @@ -79,7 +79,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode == 401 { diff --git a/pkg/detectors/positionstack/positionstack.go b/pkg/detectors/positionstack/positionstack.go index 6e0c3af08fce..6b1695ff07a0 100644 --- a/pkg/detectors/positionstack/positionstack.go +++ b/pkg/detectors/positionstack/positionstack.go @@ -3,10 +3,11 @@ package positionstack import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/postageapp/postageapp.go b/pkg/detectors/postageapp/postageapp.go index 8f293521554e..79cf4481d9b5 100644 --- a/pkg/detectors/postageapp/postageapp.go +++ b/pkg/detectors/postageapp/postageapp.go @@ -2,10 +2,11 @@ package postageapp import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Transfer-Encoding", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/postbacks/postbacks.go b/pkg/detectors/postbacks/postbacks.go index 341468a80e62..d09d3843f040 100644 --- a/pkg/detectors/postbacks/postbacks.go +++ b/pkg/detectors/postbacks/postbacks.go @@ -2,11 +2,12 @@ package postbacks import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" "time" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -57,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Postbacks-Authorization", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/postgres/postgres.go b/pkg/detectors/postgres/postgres.go index 7f5fd0db6ad4..69140fde02f0 100644 --- a/pkg/detectors/postgres/postgres.go +++ b/pkg/detectors/postgres/postgres.go @@ -280,7 +280,7 @@ func verifyPostgres(params map[string]string) (bool, error) { if err != nil { return false, err } - defer db.Close() + defer func() { _ = db.Close() }() err = db.Ping() switch { diff --git a/pkg/detectors/posthog/posthog.go b/pkg/detectors/posthog/posthog.go index 157d61c5baa8..0ea6b1eb719b 100644 --- a/pkg/detectors/posthog/posthog.go +++ b/pkg/detectors/posthog/posthog.go @@ -56,7 +56,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true s1.SecretParts = map[string]string{ @@ -66,7 +66,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result // Try EU Endpoint only if other one fails. res, err := client.Do(reqEU) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true s1.SecretParts = map[string]string{ diff --git a/pkg/detectors/postman/postman.go b/pkg/detectors/postman/postman.go index b4540d219fb5..ed9523c20331 100644 --- a/pkg/detectors/postman/postman.go +++ b/pkg/detectors/postman/postman.go @@ -82,7 +82,7 @@ func verifyPostman(ctx context.Context, client *http.Client, token string) (bool if err != nil { return false, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() switch res.StatusCode { case http.StatusOK: diff --git a/pkg/detectors/powrbot/powrbot.go b/pkg/detectors/powrbot/powrbot.go index 9a1a5d8f7517..2884d80ca90d 100644 --- a/pkg/detectors/powrbot/powrbot.go +++ b/pkg/detectors/powrbot/powrbot.go @@ -3,10 +3,11 @@ package powrbot import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("secret-key %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/prefect/prefect.go b/pkg/detectors/prefect/prefect.go index 0d2761eda49d..1aed862b7702 100644 --- a/pkg/detectors/prefect/prefect.go +++ b/pkg/detectors/prefect/prefect.go @@ -3,10 +3,11 @@ package prefect import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/privacy/privacy.go b/pkg/detectors/privacy/privacy.go index da59c9a05c82..208fb86bf322 100644 --- a/pkg/detectors/privacy/privacy.go +++ b/pkg/detectors/privacy/privacy.go @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Set("Authorization", "api-key "+resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode == 401 { diff --git a/pkg/detectors/privatekey/privatekey.go b/pkg/detectors/privatekey/privatekey.go index a345933ae4a1..b09282a40b9b 100644 --- a/pkg/detectors/privatekey/privatekey.go +++ b/pkg/detectors/privatekey/privatekey.go @@ -226,7 +226,7 @@ func LookupFingerprint(ctx context.Context, publicKeyFingerprintInHex string) (* if err != nil { return nil, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() results := DriftwoodResult{} err = json.NewDecoder(res.Body).Decode(&results) diff --git a/pkg/detectors/privatekey/ssh_integration.go b/pkg/detectors/privatekey/ssh_integration.go index 5f0a8cbc5221..913a1acd80e9 100644 --- a/pkg/detectors/privatekey/ssh_integration.go +++ b/pkg/detectors/privatekey/ssh_integration.go @@ -64,13 +64,13 @@ func firstResponseFromSSH(ctx context.Context, parsedKey any, username, hostport } return "", err } - defer client.Close() + defer func() { _ = client.Close() }() session, err := client.NewSession() if err != nil { return "", err } - defer session.Close() + defer func() { _ = session.Close() }() var output bytes.Buffer session.Stderr = &output @@ -93,7 +93,7 @@ func sshDialWithContext(ctx context.Context, network, addr string, config *ssh.C ncc, chans, reqs, err := ssh.NewClientConn(conn, addr, config) if err != nil { - conn.Close() + _ = conn.Close() return nil, fmt.Errorf("error creating SSH connection to %s: %w", addr, err) } diff --git a/pkg/detectors/prodpad/prodpad.go b/pkg/detectors/prodpad/prodpad.go index f3d7f6726a60..b0417a961bce 100644 --- a/pkg/detectors/prodpad/prodpad.go +++ b/pkg/detectors/prodpad/prodpad.go @@ -3,10 +3,11 @@ package prodpad import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/prospectcrm/prospectcrm.go b/pkg/detectors/prospectcrm/prospectcrm.go index 3ebbbb5334ca..0f26e8c2de3c 100644 --- a/pkg/detectors/prospectcrm/prospectcrm.go +++ b/pkg/detectors/prospectcrm/prospectcrm.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/protocolsio/protocolsio.go b/pkg/detectors/protocolsio/protocolsio.go index 2e70a028f35a..a2ef1470b55b 100644 --- a/pkg/detectors/protocolsio/protocolsio.go +++ b/pkg/detectors/protocolsio/protocolsio.go @@ -3,10 +3,11 @@ package protocolsio import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/proxycrawl/proxycrawl.go b/pkg/detectors/proxycrawl/proxycrawl.go index 682a32d76fc1..90e25135ef6a 100644 --- a/pkg/detectors/proxycrawl/proxycrawl.go +++ b/pkg/detectors/proxycrawl/proxycrawl.go @@ -3,11 +3,12 @@ package proxycrawl import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" "time" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -55,7 +56,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/pubnubpublishkey/pubnubpublishkey.go b/pkg/detectors/pubnubpublishkey/pubnubpublishkey.go index 281372b32c8e..7229ffd8e49c 100644 --- a/pkg/detectors/pubnubpublishkey/pubnubpublishkey.go +++ b/pkg/detectors/pubnubpublishkey/pubnubpublishkey.go @@ -91,10 +91,10 @@ func verifyPubNub(ctx context.Context, client *http.Client, resMatch, ressubMatc return false, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { return true, nil - } else if !(res.StatusCode == 400 || res.StatusCode == 403) { + } else if res.StatusCode != 400 && res.StatusCode != 403 { // 403 is suggested by the API docs (https://www.pubnub.com/docs/sdks/rest-api/send-signal-to-channel) // 400 is what actually seems to be coming back for invalid credentials return false, fmt.Errorf("unexpected HTTP response status %d", res.StatusCode) diff --git a/pkg/detectors/pulumi/pulumi.go b/pkg/detectors/pulumi/pulumi.go index c727abe1a536..cbe9133e0b9c 100644 --- a/pkg/detectors/pulumi/pulumi.go +++ b/pkg/detectors/pulumi/pulumi.go @@ -3,10 +3,11 @@ package pulumi import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -55,7 +56,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("token %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/purestake/purestake.go b/pkg/detectors/purestake/purestake.go index e6cc2d5e37d3..8f785568712b 100644 --- a/pkg/detectors/purestake/purestake.go +++ b/pkg/detectors/purestake/purestake.go @@ -2,10 +2,11 @@ package purestake import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("x-api-key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/pushbulletapikey/pushbulletapikey.go b/pkg/detectors/pushbulletapikey/pushbulletapikey.go index f94e8fb1a868..d365d4674153 100644 --- a/pkg/detectors/pushbulletapikey/pushbulletapikey.go +++ b/pkg/detectors/pushbulletapikey/pushbulletapikey.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Access-Token", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/pypi/pypi.go b/pkg/detectors/pypi/pypi.go index 7982041fe65f..e2746a9c09f5 100644 --- a/pkg/detectors/pypi/pypi.go +++ b/pkg/detectors/pypi/pypi.go @@ -80,7 +80,7 @@ func verifyMatch(ctx context.Context, client *http.Client, token string) (bool, _ = writer.WriteField("content", "dummy-content") // Close the writer to finalize the form - writer.Close() + _ = writer.Close() // Create a new POST request to the PyPI legacy upload URL req, err := http.NewRequestWithContext(ctx, http.MethodPost, "https://upload.pypi.org/legacy/", &body) @@ -104,7 +104,8 @@ func verifyMatch(ctx context.Context, client *http.Client, token string) (bool, }() // Check for expected status codes for verification - if res.StatusCode == http.StatusBadRequest { + switch res.StatusCode { + case http.StatusBadRequest: verified, err := common.ResponseContainsSubstring(res.Body, "Include at least one message digest.") if err != nil { return false, nil, err @@ -112,7 +113,7 @@ func verifyMatch(ctx context.Context, client *http.Client, token string) (bool, if verified { return true, nil, nil } - } else if res.StatusCode == http.StatusForbidden { + case http.StatusForbidden: // If we get a 403 status, the key is invalid return false, nil, nil } diff --git a/pkg/detectors/rabbitmq/rabbitmq.go b/pkg/detectors/rabbitmq/rabbitmq.go index af7fcffb2033..d4ee7b98e774 100644 --- a/pkg/detectors/rabbitmq/rabbitmq.go +++ b/pkg/detectors/rabbitmq/rabbitmq.go @@ -63,7 +63,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result DetectorType: detector_typepb.DetectorType_RabbitMQ, Raw: []byte(urlMatch), SecretParts: map[string]string{"key": urlMatch}, - Redacted: strings.TrimSpace(strings.Replace(parsedURL.String(), password, "********", -1)), + Redacted: strings.TrimSpace(strings.ReplaceAll(parsedURL.String(), password, "********")), } if verify { diff --git a/pkg/detectors/railwayapp/railwayapp.go b/pkg/detectors/railwayapp/railwayapp.go index d0f61bca4505..b964c8b07479 100644 --- a/pkg/detectors/railwayapp/railwayapp.go +++ b/pkg/detectors/railwayapp/railwayapp.go @@ -119,7 +119,7 @@ func verifyRailwayApp(ctx context.Context, client *http.Client, match string) (b if err != nil { return false, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() /* GraphQL queries return response with 200 OK status code even for errors diff --git a/pkg/detectors/ramp/ramp.go b/pkg/detectors/ramp/ramp.go index a4d6a3df6df5..b9599d468dba 100644 --- a/pkg/detectors/ramp/ramp.go +++ b/pkg/detectors/ramp/ramp.go @@ -78,7 +78,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Set("Content-Type", "application/x-www-form-urlencoded") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode == 401 { diff --git a/pkg/detectors/rapidapi/rapidapi.go b/pkg/detectors/rapidapi/rapidapi.go index 5f9bfdcd43a6..f3378cecee06 100644 --- a/pkg/detectors/rapidapi/rapidapi.go +++ b/pkg/detectors/rapidapi/rapidapi.go @@ -2,10 +2,11 @@ package rapidapi import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -51,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("x-rapidapi-key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/raven/raven.go b/pkg/detectors/raven/raven.go index 4e05da24663b..a59a84511f9b 100644 --- a/pkg/detectors/raven/raven.go +++ b/pkg/detectors/raven/raven.go @@ -4,11 +4,12 @@ import ( "context" "encoding/json" "fmt" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -58,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err != nil { continue } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if json.Valid(bodyBytes) { s1.Verified = true diff --git a/pkg/detectors/rawg/rawg.go b/pkg/detectors/rawg/rawg.go index c2f89615d64f..9b63105a4091 100644 --- a/pkg/detectors/rawg/rawg.go +++ b/pkg/detectors/rawg/rawg.go @@ -2,10 +2,11 @@ package rawg import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -51,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/razorpay/razorpay.go b/pkg/detectors/razorpay/razorpay.go index 10cdf4849cef..d9323fa2d77a 100644 --- a/pkg/detectors/razorpay/razorpay.go +++ b/pkg/detectors/razorpay/razorpay.go @@ -68,7 +68,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err != nil { continue } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if json.Valid(bodyBytes) { s1.Verified = true diff --git a/pkg/detectors/reachmail/reachmail.go b/pkg/detectors/reachmail/reachmail.go index f4797ea95433..7468327ff89a 100644 --- a/pkg/detectors/reachmail/reachmail.go +++ b/pkg/detectors/reachmail/reachmail.go @@ -3,10 +3,11 @@ package reachmail import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -55,7 +56,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/readme/readme.go b/pkg/detectors/readme/readme.go index 12a286017c26..da87e4001800 100644 --- a/pkg/detectors/readme/readme.go +++ b/pkg/detectors/readme/readme.go @@ -2,10 +2,11 @@ package readme import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" ) @@ -50,7 +51,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("accept", "application/json") res, err := http.DefaultClient.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/reallysimplesystems/reallysimplesystems.go b/pkg/detectors/reallysimplesystems/reallysimplesystems.go index ea7506c5e332..d5835289d842 100644 --- a/pkg/detectors/reallysimplesystems/reallysimplesystems.go +++ b/pkg/detectors/reallysimplesystems/reallysimplesystems.go @@ -60,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err != nil { continue } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if json.Valid(bodyBytes) { s1.Verified = true diff --git a/pkg/detectors/rebrandly/rebrandly.go b/pkg/detectors/rebrandly/rebrandly.go index 7ce567e42198..d830943bca26 100644 --- a/pkg/detectors/rebrandly/rebrandly.go +++ b/pkg/detectors/rebrandly/rebrandly.go @@ -2,10 +2,11 @@ package rebrandly import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("apikey", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/rechargepayments/rechargepayments.go b/pkg/detectors/rechargepayments/rechargepayments.go index 6cf5282ae185..f6e2c2225d06 100644 --- a/pkg/detectors/rechargepayments/rechargepayments.go +++ b/pkg/detectors/rechargepayments/rechargepayments.go @@ -2,9 +2,10 @@ package rechargepayments import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -57,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-Recharge-Access-Token", token) res, err := client.Do(req) if err == nil { - res.Body.Close() // The request body is unused. + _ = res.Body.Close() // The request body is unused. if res.StatusCode == http.StatusOK { result.Verified = true diff --git a/pkg/detectors/redis/redis.go b/pkg/detectors/redis/redis.go index 4c4c39f73747..35f19659a688 100644 --- a/pkg/detectors/redis/redis.go +++ b/pkg/detectors/redis/redis.go @@ -56,7 +56,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result continue } - redact := strings.TrimSpace(strings.Replace(urlMatch, password, "*******", -1)) + redact := strings.TrimSpace(strings.ReplaceAll(urlMatch, password, "*******")) s := detectors.Result{ DetectorType: detector_typepb.DetectorType_Redis, @@ -99,7 +99,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result continue } - redact := strings.TrimSpace(strings.Replace(urlMatch, password, "*******", -1)) + redact := strings.TrimSpace(strings.ReplaceAll(urlMatch, password, "*******")) s := detectors.Result{ DetectorType: detector_typepb.DetectorType_Redis, diff --git a/pkg/detectors/refiner/refiner.go b/pkg/detectors/refiner/refiner.go index a226cbdea4cc..c7f689bb4c2b 100644 --- a/pkg/detectors/refiner/refiner.go +++ b/pkg/detectors/refiner/refiner.go @@ -3,10 +3,11 @@ package refiner import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -55,7 +56,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/rentman/rentman.go b/pkg/detectors/rentman/rentman.go index d242949239fa..fc0464233060 100644 --- a/pkg/detectors/rentman/rentman.go +++ b/pkg/detectors/rentman/rentman.go @@ -3,10 +3,11 @@ package rentman import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/repairshopr/repairshopr.go b/pkg/detectors/repairshopr/repairshopr.go index 203096388e3c..5bdf9a3e9407 100644 --- a/pkg/detectors/repairshopr/repairshopr.go +++ b/pkg/detectors/repairshopr/repairshopr.go @@ -61,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/replicate/replicate.go b/pkg/detectors/replicate/replicate.go index 04ba7298edb4..68923d5d7d31 100644 --- a/pkg/detectors/replicate/replicate.go +++ b/pkg/detectors/replicate/replicate.go @@ -3,10 +3,11 @@ package replicate import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Token %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode == 401 { diff --git a/pkg/detectors/replyio/replyio.go b/pkg/detectors/replyio/replyio.go index b0740ae00769..8fff1e3ffbd5 100644 --- a/pkg/detectors/replyio/replyio.go +++ b/pkg/detectors/replyio/replyio.go @@ -3,10 +3,11 @@ package replyio import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -55,7 +56,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-Api-Key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode == 401 { diff --git a/pkg/detectors/requestfinance/requestfinance.go b/pkg/detectors/requestfinance/requestfinance.go index 4f10dbd241a9..4216cd8f296e 100644 --- a/pkg/detectors/requestfinance/requestfinance.go +++ b/pkg/detectors/requestfinance/requestfinance.go @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode == 401 { diff --git a/pkg/detectors/restpackhtmltopdfapi/restpackhtmltopdfapi.go b/pkg/detectors/restpackhtmltopdfapi/restpackhtmltopdfapi.go index 8f9ec60f61f0..f73545086279 100644 --- a/pkg/detectors/restpackhtmltopdfapi/restpackhtmltopdfapi.go +++ b/pkg/detectors/restpackhtmltopdfapi/restpackhtmltopdfapi.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-Access-Token", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/restpackscreenshotapi/restpackscreenshotapi.go b/pkg/detectors/restpackscreenshotapi/restpackscreenshotapi.go index c4e4652de586..4f0bfcbd1e27 100644 --- a/pkg/detectors/restpackscreenshotapi/restpackscreenshotapi.go +++ b/pkg/detectors/restpackscreenshotapi/restpackscreenshotapi.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-Access-Token", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/rev/rev.go b/pkg/detectors/rev/rev.go index 27e7e93c66af..a6628b293809 100644 --- a/pkg/detectors/rev/rev.go +++ b/pkg/detectors/rev/rev.go @@ -60,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Rev %s:%s", resClientMatch, resUserMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/revampcrm/revampcrm.go b/pkg/detectors/revampcrm/revampcrm.go index 2e4088344a9f..844b17158c44 100644 --- a/pkg/detectors/revampcrm/revampcrm.go +++ b/pkg/detectors/revampcrm/revampcrm.go @@ -2,10 +2,11 @@ package revampcrm import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -59,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.SetBasicAuth(userPatMatch, tokenPatMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/ringcentral/ringcentral.go b/pkg/detectors/ringcentral/ringcentral.go index 75d7026a91d7..43a2adf31c49 100644 --- a/pkg/detectors/ringcentral/ringcentral.go +++ b/pkg/detectors/ringcentral/ringcentral.go @@ -61,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/ritekit/ritekit.go b/pkg/detectors/ritekit/ritekit.go index 692a473888bb..18b0288d4001 100644 --- a/pkg/detectors/ritekit/ritekit.go +++ b/pkg/detectors/ritekit/ritekit.go @@ -3,10 +3,11 @@ package ritekit import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/roaring/roaring.go b/pkg/detectors/roaring/roaring.go index e6b3b2b7cce5..6ac68f33bf86 100644 --- a/pkg/detectors/roaring/roaring.go +++ b/pkg/detectors/roaring/roaring.go @@ -4,10 +4,11 @@ import ( "context" b64 "encoding/base64" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -68,7 +69,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", sEnc)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/rocketreach/rocketreach.go b/pkg/detectors/rocketreach/rocketreach.go index 4db1d9250225..b57e5c991e19 100644 --- a/pkg/detectors/rocketreach/rocketreach.go +++ b/pkg/detectors/rocketreach/rocketreach.go @@ -2,10 +2,11 @@ package rocketreach import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Api-Key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/rootly/rootly.go b/pkg/detectors/rootly/rootly.go index 524305a14163..aa3283250e04 100644 --- a/pkg/detectors/rootly/rootly.go +++ b/pkg/detectors/rootly/rootly.go @@ -72,7 +72,7 @@ func verifyMatch(ctx context.Context, client *http.Client, token string) (bool, if err != nil { return false, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() switch res.StatusCode { case http.StatusOK, http.StatusNotFound: diff --git a/pkg/detectors/route4me/route4me.go b/pkg/detectors/route4me/route4me.go index 696576561ef4..b6de75caab78 100644 --- a/pkg/detectors/route4me/route4me.go +++ b/pkg/detectors/route4me/route4me.go @@ -2,10 +2,11 @@ package route4me import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -51,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/rownd/rownd.go b/pkg/detectors/rownd/rownd.go index 98999f9b3cb7..a65c0622fdeb 100644 --- a/pkg/detectors/rownd/rownd.go +++ b/pkg/detectors/rownd/rownd.go @@ -2,10 +2,11 @@ package rownd import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -70,7 +71,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("x-rownd-app-secret", secretMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/rubygems/rubygems.go b/pkg/detectors/rubygems/rubygems.go index d7dacbce975c..f8ab042106aa 100644 --- a/pkg/detectors/rubygems/rubygems.go +++ b/pkg/detectors/rubygems/rubygems.go @@ -2,10 +2,11 @@ package rubygems import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 || res.StatusCode == http.StatusForbidden { s1.Verified = true } diff --git a/pkg/detectors/runrunit/runrunit.go b/pkg/detectors/runrunit/runrunit.go index 365e3f8bd8b5..6fce3c8d3ee3 100644 --- a/pkg/detectors/runrunit/runrunit.go +++ b/pkg/detectors/runrunit/runrunit.go @@ -2,10 +2,11 @@ package runrunit import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -60,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("User-Token", resUserTokenMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/salesblink/salesblink.go b/pkg/detectors/salesblink/salesblink.go index 5dfac3d26842..771af9669232 100644 --- a/pkg/detectors/salesblink/salesblink.go +++ b/pkg/detectors/salesblink/salesblink.go @@ -2,10 +2,11 @@ package salesblink import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/salescookie/salescookie.go b/pkg/detectors/salescookie/salescookie.go index b30af186c483..eb68e8decefd 100644 --- a/pkg/detectors/salescookie/salescookie.go +++ b/pkg/detectors/salescookie/salescookie.go @@ -2,10 +2,11 @@ package salescookie import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/salesflare/salesflare.go b/pkg/detectors/salesflare/salesflare.go index 41b6ebdd3101..af0fbf2be082 100644 --- a/pkg/detectors/salesflare/salesflare.go +++ b/pkg/detectors/salesflare/salesflare.go @@ -3,10 +3,11 @@ package salesflare import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/salesforce/salesforce.go b/pkg/detectors/salesforce/salesforce.go index d9d88dd25ed3..89ca428613b7 100644 --- a/pkg/detectors/salesforce/salesforce.go +++ b/pkg/detectors/salesforce/salesforce.go @@ -82,7 +82,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result verifiedBodyResponse, err := common.ResponseContainsSubstring(res.Body, "records") - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 && verifiedBodyResponse { s1.Verified = true } else if res.StatusCode >= 200 && res.StatusCode < 300 && !verifiedBodyResponse { diff --git a/pkg/detectors/salesmate/salesmate.go b/pkg/detectors/salesmate/salesmate.go index 1bdadef1daf4..582e334927ae 100644 --- a/pkg/detectors/salesmate/salesmate.go +++ b/pkg/detectors/salesmate/salesmate.go @@ -61,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("sessionToken", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/satismeterwritekey/satismeterwritekey_test.go b/pkg/detectors/satismeterwritekey/satismeterwritekey_test.go index 6ab32f061cb2..8b2f1a915aab 100644 --- a/pkg/detectors/satismeterwritekey/satismeterwritekey_test.go +++ b/pkg/detectors/satismeterwritekey/satismeterwritekey_test.go @@ -33,7 +33,7 @@ var ( // Perform the request client := &http.Client{} resp, _ := client.Do(req) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // Check response status if resp.StatusCode == http.StatusNoContent { diff --git a/pkg/detectors/scalewaykey/scalewaykey.go b/pkg/detectors/scalewaykey/scalewaykey.go index e6fd1189d7a9..b9eb69217e08 100644 --- a/pkg/detectors/scalewaykey/scalewaykey.go +++ b/pkg/detectors/scalewaykey/scalewaykey.go @@ -2,10 +2,11 @@ package scalewaykey import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -51,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-Auth-Token", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/scalr/scalr.go b/pkg/detectors/scalr/scalr.go index e4ef42b8f333..283d72671861 100644 --- a/pkg/detectors/scalr/scalr.go +++ b/pkg/detectors/scalr/scalr.go @@ -3,10 +3,11 @@ package scalr import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -61,7 +62,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Prefer", "profile=preview") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/scrapeowl/scrapeowl.go b/pkg/detectors/scrapeowl/scrapeowl.go index a18329bcdd0b..c515d22641c9 100644 --- a/pkg/detectors/scrapeowl/scrapeowl.go +++ b/pkg/detectors/scrapeowl/scrapeowl.go @@ -52,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/scraperapi/scraperapi.go b/pkg/detectors/scraperapi/scraperapi.go index 96f93691fb1e..e291a3147a57 100644 --- a/pkg/detectors/scraperapi/scraperapi.go +++ b/pkg/detectors/scraperapi/scraperapi.go @@ -3,11 +3,12 @@ package scraperapi import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" "time" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/scraperbox/scraperbox.go b/pkg/detectors/scraperbox/scraperbox.go index 4a12dbad61df..65f9e8220c7f 100644 --- a/pkg/detectors/scraperbox/scraperbox.go +++ b/pkg/detectors/scraperbox/scraperbox.go @@ -3,11 +3,12 @@ package scraperbox import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" "time" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -55,7 +56,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/scrapestack/scrapestack.go b/pkg/detectors/scrapestack/scrapestack.go index 50c03e419b17..adf909b4db17 100644 --- a/pkg/detectors/scrapestack/scrapestack.go +++ b/pkg/detectors/scrapestack/scrapestack.go @@ -3,11 +3,12 @@ package scrapestack import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -57,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err == nil { bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `html`) || strings.Contains(bodyString, `"info":"Access Restricted - Your current Subscription Plan does not support HTTPS Encryption."`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { s1.Verified = true diff --git a/pkg/detectors/scrapfly/scrapfly.go b/pkg/detectors/scrapfly/scrapfly.go index 780f71963d94..92dc9f9f8046 100644 --- a/pkg/detectors/scrapfly/scrapfly.go +++ b/pkg/detectors/scrapfly/scrapfly.go @@ -3,11 +3,12 @@ package scrapfly import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" "time" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -59,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/scrapingant/scrapingant.go b/pkg/detectors/scrapingant/scrapingant.go index 75fade77e78e..312aec86b573 100644 --- a/pkg/detectors/scrapingant/scrapingant.go +++ b/pkg/detectors/scrapingant/scrapingant.go @@ -89,11 +89,12 @@ func verifyScrapingAnt(ctx context.Context, client *http.Client, apiKey string) _ = resp.Body.Close() }() - if resp.StatusCode == http.StatusOK { + switch resp.StatusCode { + case http.StatusOK: return true, nil - } else if resp.StatusCode == http.StatusUnauthorized || resp.StatusCode == http.StatusForbidden { + case http.StatusUnauthorized, http.StatusForbidden: return false, nil - } else { + default: return false, fmt.Errorf("unexpected status code: %d", resp.StatusCode) } } diff --git a/pkg/detectors/screenshotapi/screenshotapi.go b/pkg/detectors/screenshotapi/screenshotapi.go index d4df2c733495..8d10a2b0ce94 100644 --- a/pkg/detectors/screenshotapi/screenshotapi.go +++ b/pkg/detectors/screenshotapi/screenshotapi.go @@ -3,11 +3,12 @@ package screenshotapi import ( "context" "encoding/json" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" "time" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -59,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() var r response if err := json.NewDecoder(res.Body).Decode(&r); err != nil { s1.SetVerificationError(err, resMatch) diff --git a/pkg/detectors/screenshotlayer/screenshotlayer.go b/pkg/detectors/screenshotlayer/screenshotlayer.go index 346124a69fa8..6c98c8b5b810 100644 --- a/pkg/detectors/screenshotlayer/screenshotlayer.go +++ b/pkg/detectors/screenshotlayer/screenshotlayer.go @@ -3,12 +3,13 @@ package screenshotlayer import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" "time" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -58,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err == nil { bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `PNG`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { s1.Verified = true diff --git a/pkg/detectors/scrutinizerci/scrutinizerci.go b/pkg/detectors/scrutinizerci/scrutinizerci.go index 61ab7ff469b9..4c32c7c1b3cb 100644 --- a/pkg/detectors/scrutinizerci/scrutinizerci.go +++ b/pkg/detectors/scrutinizerci/scrutinizerci.go @@ -2,10 +2,11 @@ package scrutinizerci import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/securitytrails/securitytrails.go b/pkg/detectors/securitytrails/securitytrails.go index d3faffc7a5e8..a8bf7f8be81b 100644 --- a/pkg/detectors/securitytrails/securitytrails.go +++ b/pkg/detectors/securitytrails/securitytrails.go @@ -2,10 +2,11 @@ package securitytrails import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("APIKEY", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/segmentapikey/segmentapikey.go b/pkg/detectors/segmentapikey/segmentapikey.go index e7c3c92fbc27..935b43adaf05 100644 --- a/pkg/detectors/segmentapikey/segmentapikey.go +++ b/pkg/detectors/segmentapikey/segmentapikey.go @@ -3,10 +3,11 @@ package segmentapikey import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/selectpdf/selectpdf.go b/pkg/detectors/selectpdf/selectpdf.go index 400b7f6b5928..e456b9ef716c 100644 --- a/pkg/detectors/selectpdf/selectpdf.go +++ b/pkg/detectors/selectpdf/selectpdf.go @@ -3,11 +3,12 @@ package selectpdf import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" "time" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -55,7 +56,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/semaphore/semaphore.go b/pkg/detectors/semaphore/semaphore.go index 874c36b24ffb..049ed987c716 100644 --- a/pkg/detectors/semaphore/semaphore.go +++ b/pkg/detectors/semaphore/semaphore.go @@ -3,11 +3,12 @@ package semaphore import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -58,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Accept", "application/vnd.semaphore+json; version=3") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { continue diff --git a/pkg/detectors/sendbird/sendbird.go b/pkg/detectors/sendbird/sendbird.go index 3785de53e5e7..026cff7a78ac 100644 --- a/pkg/detectors/sendbird/sendbird.go +++ b/pkg/detectors/sendbird/sendbird.go @@ -4,10 +4,11 @@ import ( "context" "encoding/json" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -75,7 +76,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode == 400 { // Sendbird returns 400 for all errors diff --git a/pkg/detectors/sendbirdorganizationapi/sendbirdorganizationapi.go b/pkg/detectors/sendbirdorganizationapi/sendbirdorganizationapi.go index 10b265e989b8..f0e3e320b11a 100644 --- a/pkg/detectors/sendbirdorganizationapi/sendbirdorganizationapi.go +++ b/pkg/detectors/sendbirdorganizationapi/sendbirdorganizationapi.go @@ -63,7 +63,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err != nil { s1.SetVerificationError(err, resMatch) } else { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode != http.StatusForbidden { diff --git a/pkg/detectors/sendinbluev2/sendinbluev2.go b/pkg/detectors/sendinbluev2/sendinbluev2.go index 63508b2ea849..fb16ed94d26e 100644 --- a/pkg/detectors/sendinbluev2/sendinbluev2.go +++ b/pkg/detectors/sendinbluev2/sendinbluev2.go @@ -2,10 +2,11 @@ package sendinbluev2 import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -51,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("api-key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/serphouse/serphouse.go b/pkg/detectors/serphouse/serphouse.go index 772e0470fe4d..1832f4e39e84 100644 --- a/pkg/detectors/serphouse/serphouse.go +++ b/pkg/detectors/serphouse/serphouse.go @@ -3,10 +3,11 @@ package serphouse import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/serpstack/serpstack.go b/pkg/detectors/serpstack/serpstack.go index 79c905ae06b7..65ea2cbf03f2 100644 --- a/pkg/detectors/serpstack/serpstack.go +++ b/pkg/detectors/serpstack/serpstack.go @@ -61,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err == nil { bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `search_url`) || strings.Contains(bodyString, `"info":"Access Restricted - Your current Subscription Plan does not support HTTPS Encryption."`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { s1.Verified = true diff --git a/pkg/detectors/sheety/sheety.go b/pkg/detectors/sheety/sheety.go index 46f409a52b3b..13bb3f20abc6 100644 --- a/pkg/detectors/sheety/sheety.go +++ b/pkg/detectors/sheety/sheety.go @@ -60,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/sherpadesk/sherpadesk.go b/pkg/detectors/sherpadesk/sherpadesk.go index 0ec99b5a3e44..ff9e1f91fa1d 100644 --- a/pkg/detectors/sherpadesk/sherpadesk.go +++ b/pkg/detectors/sherpadesk/sherpadesk.go @@ -4,10 +4,11 @@ import ( "context" b64 "encoding/base64" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -57,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", sEnc)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/shipday/shipday.go b/pkg/detectors/shipday/shipday.go index 82434b87ae15..e1e0796edbb5 100644 --- a/pkg/detectors/shipday/shipday.go +++ b/pkg/detectors/shipday/shipday.go @@ -3,10 +3,11 @@ package shipday import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/shodankey/shodankey.go b/pkg/detectors/shodankey/shodankey.go index 1b56b3586d1f..ffd38ee48ce2 100644 --- a/pkg/detectors/shodankey/shodankey.go +++ b/pkg/detectors/shodankey/shodankey.go @@ -3,11 +3,12 @@ package shodankey import ( "context" "encoding/json" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -81,7 +82,7 @@ func verifyToken(ctx context.Context, client *http.Client, token string) bool { if err != nil { return false } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode < 200 || res.StatusCode >= 300 { return false diff --git a/pkg/detectors/shopify/shopify.go b/pkg/detectors/shopify/shopify.go index 6bd870926efe..6bb19b85a2c2 100644 --- a/pkg/detectors/shopify/shopify.go +++ b/pkg/detectors/shopify/shopify.go @@ -82,7 +82,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result "store_url": domainRes, } } - res.Body.Close() + _ = res.Body.Close() } } } diff --git a/pkg/detectors/shotstack/shotstack.go b/pkg/detectors/shotstack/shotstack.go index 3735ca167143..d4a8bf51148f 100644 --- a/pkg/detectors/shotstack/shotstack.go +++ b/pkg/detectors/shotstack/shotstack.go @@ -2,10 +2,11 @@ package shotstack import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -84,7 +85,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("x-api-key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/shutterstock/shutterstock.go b/pkg/detectors/shutterstock/shutterstock.go index cdd6f116b1be..3e1abccdf48c 100644 --- a/pkg/detectors/shutterstock/shutterstock.go +++ b/pkg/detectors/shutterstock/shutterstock.go @@ -2,10 +2,11 @@ package shutterstock import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -60,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.SetBasicAuth(resMatch, resSecretMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/shutterstockoauth/shutterstockoauth.go b/pkg/detectors/shutterstockoauth/shutterstockoauth.go index 61937ec4562b..4f955088a27c 100644 --- a/pkg/detectors/shutterstockoauth/shutterstockoauth.go +++ b/pkg/detectors/shutterstockoauth/shutterstockoauth.go @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/signable/signable.go b/pkg/detectors/signable/signable.go index cf10728ba1cf..4c6b5da0d29c 100644 --- a/pkg/detectors/signable/signable.go +++ b/pkg/detectors/signable/signable.go @@ -99,7 +99,7 @@ func verifyResult(ctx context.Context, client *http.Client, token string) (bool, return false, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { return true, nil } diff --git a/pkg/detectors/signalwire/signalwire.go b/pkg/detectors/signalwire/signalwire.go index 87ce6eae21f8..1e86e714d894 100644 --- a/pkg/detectors/signalwire/signalwire.go +++ b/pkg/detectors/signalwire/signalwire.go @@ -69,7 +69,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", sEnc)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/signaturit/signaturit.go b/pkg/detectors/signaturit/signaturit.go index e941bc4a39a9..a51327987fa8 100644 --- a/pkg/detectors/signaturit/signaturit.go +++ b/pkg/detectors/signaturit/signaturit.go @@ -3,10 +3,11 @@ package signaturit import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/signupgenius/signupgenius.go b/pkg/detectors/signupgenius/signupgenius.go index 0c1dc437097f..afe61c142466 100644 --- a/pkg/detectors/signupgenius/signupgenius.go +++ b/pkg/detectors/signupgenius/signupgenius.go @@ -2,10 +2,11 @@ package signupgenius import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -51,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/sigopt/sigopt.go b/pkg/detectors/sigopt/sigopt.go index 68d7c176d4d2..120385557580 100644 --- a/pkg/detectors/sigopt/sigopt.go +++ b/pkg/detectors/sigopt/sigopt.go @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", sEnc)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/simfin/simfin.go b/pkg/detectors/simfin/simfin.go index 8a079ac2a1d3..687be6b811eb 100644 --- a/pkg/detectors/simfin/simfin.go +++ b/pkg/detectors/simfin/simfin.go @@ -61,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } bodyString := string(bodyBytes) validResponse := !strings.Contains(bodyString, `"error"`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 && validResponse { s1.Verified = true } diff --git a/pkg/detectors/simplesat/simplesat.go b/pkg/detectors/simplesat/simplesat.go index d5ea5f21696d..4ba46e532248 100644 --- a/pkg/detectors/simplesat/simplesat.go +++ b/pkg/detectors/simplesat/simplesat.go @@ -2,10 +2,11 @@ package simplesat import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-Simplesat-Token", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/simplynoted/simplynoted.go b/pkg/detectors/simplynoted/simplynoted.go index fca259febebd..f7c987f8940c 100644 --- a/pkg/detectors/simplynoted/simplynoted.go +++ b/pkg/detectors/simplynoted/simplynoted.go @@ -3,10 +3,11 @@ package simplynoted import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/simvoly/simvoly.go b/pkg/detectors/simvoly/simvoly.go index b4ba6fcb2279..d8f891a24d1e 100644 --- a/pkg/detectors/simvoly/simvoly.go +++ b/pkg/detectors/simvoly/simvoly.go @@ -3,10 +3,11 @@ package simvoly import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/sinchmessage/sinchmessage.go b/pkg/detectors/sinchmessage/sinchmessage.go index b1f84055822f..0d6516f0c5c3 100644 --- a/pkg/detectors/sinchmessage/sinchmessage.go +++ b/pkg/detectors/sinchmessage/sinchmessage.go @@ -3,10 +3,11 @@ package sinchmessage import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -66,7 +67,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/sirv/sirv.go b/pkg/detectors/sirv/sirv.go index 21f135bbbc3d..12cdfa93a827 100644 --- a/pkg/detectors/sirv/sirv.go +++ b/pkg/detectors/sirv/sirv.go @@ -3,11 +3,12 @@ package sirv import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" "time" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -64,7 +65,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/siteleaf/siteleaf.go b/pkg/detectors/siteleaf/siteleaf.go index f53d506af7a9..d8a3544ee97b 100644 --- a/pkg/detectors/siteleaf/siteleaf.go +++ b/pkg/detectors/siteleaf/siteleaf.go @@ -4,10 +4,11 @@ import ( "context" b64 "encoding/base64" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -65,7 +66,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", sEnc)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/skrappio/skrappio.go b/pkg/detectors/skrappio/skrappio.go index 500c98f0de96..f248d20dfbf3 100644 --- a/pkg/detectors/skrappio/skrappio.go +++ b/pkg/detectors/skrappio/skrappio.go @@ -2,10 +2,11 @@ package skrappio import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-Access-Key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/slack/slack.go b/pkg/detectors/slack/slack.go index 1a5cb9513469..caf22d1671e2 100644 --- a/pkg/detectors/slack/slack.go +++ b/pkg/detectors/slack/slack.go @@ -82,7 +82,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() var authResponse authRes if err := json.NewDecoder(res.Body).Decode(&authResponse); err != nil { err = fmt.Errorf("failed to decode auth response: %w", err) diff --git a/pkg/detectors/slackwebhook/slackwebhook.go b/pkg/detectors/slackwebhook/slackwebhook.go index c81c33fc1607..1f5800d8a862 100644 --- a/pkg/detectors/slackwebhook/slackwebhook.go +++ b/pkg/detectors/slackwebhook/slackwebhook.go @@ -73,13 +73,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { continue } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() switch { case res.StatusCode >= http.StatusOK && res.StatusCode < http.StatusMultipleChoices: diff --git a/pkg/detectors/smartystreets/smartystreets.go b/pkg/detectors/smartystreets/smartystreets.go index 4e7228f72a59..9cea9e76417d 100644 --- a/pkg/detectors/smartystreets/smartystreets.go +++ b/pkg/detectors/smartystreets/smartystreets.go @@ -3,10 +3,11 @@ package smartystreets import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -59,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/smooch/smooch.go b/pkg/detectors/smooch/smooch.go index 85209aecc366..5a2dd9db2def 100644 --- a/pkg/detectors/smooch/smooch.go +++ b/pkg/detectors/smooch/smooch.go @@ -4,10 +4,11 @@ import ( "context" b64 "encoding/base64" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -68,7 +69,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", sEnc)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/snipcart/snipcart.go b/pkg/detectors/snipcart/snipcart.go index ebcb5733418d..ba9b8432a03d 100644 --- a/pkg/detectors/snipcart/snipcart.go +++ b/pkg/detectors/snipcart/snipcart.go @@ -4,10 +4,11 @@ import ( "context" b64 "encoding/base64" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -57,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", sEnc)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/snowflake/snowflake.go b/pkg/detectors/snowflake/snowflake.go index 7466baf0404a..1b559eb8aa65 100644 --- a/pkg/detectors/snowflake/snowflake.go +++ b/pkg/detectors/snowflake/snowflake.go @@ -173,7 +173,7 @@ func verifyMatch(ctx context.Context, account, username, password string) (bool, if err != nil { return false, fmt.Errorf("failed to send request: %w", err) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() body, err := io.ReadAll(resp.Body) if err != nil { diff --git a/pkg/detectors/snykkey/snykkey.go b/pkg/detectors/snykkey/snykkey.go index afe4afdd6157..3ae0995cfab9 100644 --- a/pkg/detectors/snykkey/snykkey.go +++ b/pkg/detectors/snykkey/snykkey.go @@ -80,7 +80,8 @@ func (s Scanner) doVerification(ctx context.Context, token string) (bool, map[st _, _ = io.Copy(io.Discard, res.Body) _ = res.Body.Close() }() - if res.StatusCode == http.StatusOK { + switch res.StatusCode { + case http.StatusOK: userDetails := userDetailsResponse{} err := json.NewDecoder(res.Body).Decode(&userDetails) if err != nil { @@ -103,10 +104,10 @@ func (s Scanner) doVerification(ctx context.Context, token string) (bool, map[st extraData["Organizations"] = strings.Join(orgs, ",") } return true, extraData, nil - } else if res.StatusCode == http.StatusUnauthorized { + case http.StatusUnauthorized: // The secret is determinately not verified (nothing to do) return false, nil, nil - } else { + default: err = fmt.Errorf("unexpected HTTP response status %d", res.StatusCode) return false, nil, err } diff --git a/pkg/detectors/sourcegraph/sourcegraph.go b/pkg/detectors/sourcegraph/sourcegraph.go index 53b1987c466c..81b6e453022a 100644 --- a/pkg/detectors/sourcegraph/sourcegraph.go +++ b/pkg/detectors/sourcegraph/sourcegraph.go @@ -65,7 +65,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true diff --git a/pkg/detectors/sourcegraphcody/sourcegraphcody.go b/pkg/detectors/sourcegraphcody/sourcegraphcody.go index b26882d05a9a..304e0aebc291 100644 --- a/pkg/detectors/sourcegraphcody/sourcegraphcody.go +++ b/pkg/detectors/sourcegraphcody/sourcegraphcody.go @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode == 403 || res.StatusCode == 401 { diff --git a/pkg/detectors/sparkpost/sparkpost.go b/pkg/detectors/sparkpost/sparkpost.go index d5e39e1fd02e..b6e2f8fe3188 100644 --- a/pkg/detectors/sparkpost/sparkpost.go +++ b/pkg/detectors/sparkpost/sparkpost.go @@ -2,10 +2,11 @@ package sparkpost import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/speechtextai/speechtextai.go b/pkg/detectors/speechtextai/speechtextai.go index c090483c5ac8..71419880c5c6 100644 --- a/pkg/detectors/speechtextai/speechtextai.go +++ b/pkg/detectors/speechtextai/speechtextai.go @@ -3,10 +3,11 @@ package speechtextai import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -56,7 +57,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/splunkobservabilitytoken/splunkobservabilitytoken.go b/pkg/detectors/splunkobservabilitytoken/splunkobservabilitytoken.go index a15becbaed77..3c6b13da1d8c 100644 --- a/pkg/detectors/splunkobservabilitytoken/splunkobservabilitytoken.go +++ b/pkg/detectors/splunkobservabilitytoken/splunkobservabilitytoken.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Set("X-Sf-Token", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/spoonacular/spoonacular.go b/pkg/detectors/spoonacular/spoonacular.go index ee383d620145..45867a66d325 100644 --- a/pkg/detectors/spoonacular/spoonacular.go +++ b/pkg/detectors/spoonacular/spoonacular.go @@ -3,10 +3,11 @@ package spoonacular import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/sportsmonk/sportsmonk.go b/pkg/detectors/sportsmonk/sportsmonk.go index 63fe85e6686e..5d8894e5296e 100644 --- a/pkg/detectors/sportsmonk/sportsmonk.go +++ b/pkg/detectors/sportsmonk/sportsmonk.go @@ -2,10 +2,11 @@ package sportsmonk import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -51,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/sqlserver/sqlserver.go b/pkg/detectors/sqlserver/sqlserver.go index 220974d8f48e..5466578f1914 100644 --- a/pkg/detectors/sqlserver/sqlserver.go +++ b/pkg/detectors/sqlserver/sqlserver.go @@ -138,7 +138,7 @@ var ping = func(ctx context.Context, config msdsn.Config) (bool, error) { if err != nil { return false, err } - defer tcpConn.Close() + defer func() { _ = tcpConn.Close() }() cleanConfig := msdsn.Config{} cleanConfig.Host = config.Host diff --git a/pkg/detectors/square/square.go b/pkg/detectors/square/square.go index 536191ba25ec..4f5eb1c97004 100644 --- a/pkg/detectors/square/square.go +++ b/pkg/detectors/square/square.go @@ -69,7 +69,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result // req.Header.Add("Square-Version", "2020-08-12") res, err := client.Do(req) if err == nil { - res.Body.Close() // The request body is unused. + _ = res.Body.Close() // The request body is unused. // 200 means good key and has `merchants` scope - default allowed by square // 401 is bad key diff --git a/pkg/detectors/squarespace/squarespace.go b/pkg/detectors/squarespace/squarespace.go index bad86c3c5d5a..aa37fe2ab33c 100644 --- a/pkg/detectors/squarespace/squarespace.go +++ b/pkg/detectors/squarespace/squarespace.go @@ -3,10 +3,11 @@ package squarespace import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/sslmate/sslmate.go b/pkg/detectors/sslmate/sslmate.go index ea931dd9853e..1075b5e0580b 100644 --- a/pkg/detectors/sslmate/sslmate.go +++ b/pkg/detectors/sslmate/sslmate.go @@ -3,10 +3,11 @@ package sslmate import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/statuscake/statuscake.go b/pkg/detectors/statuscake/statuscake.go index 0eb8f395ef0d..a65c314ed7ec 100644 --- a/pkg/detectors/statuscake/statuscake.go +++ b/pkg/detectors/statuscake/statuscake.go @@ -3,10 +3,11 @@ package statuscake import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/statuspage/statuspage.go b/pkg/detectors/statuspage/statuspage.go index bab989d218ac..df02537e257b 100644 --- a/pkg/detectors/statuspage/statuspage.go +++ b/pkg/detectors/statuspage/statuspage.go @@ -2,10 +2,11 @@ package statuspage import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/statuspal/statuspal.go b/pkg/detectors/statuspal/statuspal.go index a7ab099baacd..85d3b92a0d7f 100644 --- a/pkg/detectors/statuspal/statuspal.go +++ b/pkg/detectors/statuspal/statuspal.go @@ -2,10 +2,11 @@ package statuspal import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/stitchdata/stitchdata.go b/pkg/detectors/stitchdata/stitchdata.go index dfd5a3f99900..fb1814236630 100644 --- a/pkg/detectors/stitchdata/stitchdata.go +++ b/pkg/detectors/stitchdata/stitchdata.go @@ -3,10 +3,11 @@ package stitchdata import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/stockdata/stockdata.go b/pkg/detectors/stockdata/stockdata.go index d8de59edf306..da836d9259fe 100644 --- a/pkg/detectors/stockdata/stockdata.go +++ b/pkg/detectors/stockdata/stockdata.go @@ -2,10 +2,11 @@ package stockdata import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -51,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/storecove/storecove.go b/pkg/detectors/storecove/storecove.go index a019b323a6ed..2fc7ea01c8df 100644 --- a/pkg/detectors/storecove/storecove.go +++ b/pkg/detectors/storecove/storecove.go @@ -3,10 +3,11 @@ package storecove import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/stormboard/stormboard.go b/pkg/detectors/stormboard/stormboard.go index e7b2ede18f49..dc8d40e2850f 100644 --- a/pkg/detectors/stormboard/stormboard.go +++ b/pkg/detectors/stormboard/stormboard.go @@ -2,10 +2,11 @@ package stormboard import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-API-Key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/stormglass/stormglass.go b/pkg/detectors/stormglass/stormglass.go index 7bad5e5cc181..3bdf9809db76 100644 --- a/pkg/detectors/stormglass/stormglass.go +++ b/pkg/detectors/stormglass/stormglass.go @@ -2,10 +2,11 @@ package stormglass import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/storychief/storychief.go b/pkg/detectors/storychief/storychief.go index 94c371d7c3b5..57dbe62db194 100644 --- a/pkg/detectors/storychief/storychief.go +++ b/pkg/detectors/storychief/storychief.go @@ -3,10 +3,11 @@ package storychief import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/strava/strava.go b/pkg/detectors/strava/strava.go index bcb11cc8676a..aecf2691116f 100644 --- a/pkg/detectors/strava/strava.go +++ b/pkg/detectors/strava/strava.go @@ -2,10 +2,11 @@ package strava import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -70,7 +71,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/x-www-form-urlencoded") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/streak/streak.go b/pkg/detectors/streak/streak.go index 4d16eb95818a..f4fe12a6a341 100644 --- a/pkg/detectors/streak/streak.go +++ b/pkg/detectors/streak/streak.go @@ -4,10 +4,11 @@ import ( "context" b64 "encoding/base64" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -56,7 +57,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", sEnc)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/stripe/stripe.go b/pkg/detectors/stripe/stripe.go index 807f5fa5e5be..c3116a1069b9 100644 --- a/pkg/detectors/stripe/stripe.go +++ b/pkg/detectors/stripe/stripe.go @@ -60,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - res.Body.Close() // The request body is unused. + _ = res.Body.Close() // The request body is unused. if res.StatusCode == http.StatusOK || res.StatusCode == http.StatusForbidden { result.Verified = true diff --git a/pkg/detectors/stripo/stripo.go b/pkg/detectors/stripo/stripo.go index 02e42976e27a..d500b2c42c12 100644 --- a/pkg/detectors/stripo/stripo.go +++ b/pkg/detectors/stripo/stripo.go @@ -3,10 +3,11 @@ package stripo import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -57,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Stripo-Api-Auth", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode == 401 { diff --git a/pkg/detectors/stytch/stytch.go b/pkg/detectors/stytch/stytch.go index 00c25fb6fd93..e5aa7decdbd0 100644 --- a/pkg/detectors/stytch/stytch.go +++ b/pkg/detectors/stytch/stytch.go @@ -2,10 +2,11 @@ package stytch import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -58,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.SetBasicAuth(userPatMatch, tokenPatMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/sugester/sugester.go b/pkg/detectors/sugester/sugester.go index 8f75b4463a0b..9fd9a611d8ab 100644 --- a/pkg/detectors/sugester/sugester.go +++ b/pkg/detectors/sugester/sugester.go @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Accept", "application/vnd.sugester+json; version=3") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/supabasetoken/supabasetoken.go b/pkg/detectors/supabasetoken/supabasetoken.go index 35c54bf292cb..3e42704fd1bd 100644 --- a/pkg/detectors/supabasetoken/supabasetoken.go +++ b/pkg/detectors/supabasetoken/supabasetoken.go @@ -3,10 +3,11 @@ package supabasetoken import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/supernotesapi/supernotesapi.go b/pkg/detectors/supernotesapi/supernotesapi.go index de4410245132..7dfed4e501e8 100644 --- a/pkg/detectors/supernotesapi/supernotesapi.go +++ b/pkg/detectors/supernotesapi/supernotesapi.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Api-Key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/surveyanyplace/surveyanyplace.go b/pkg/detectors/surveyanyplace/surveyanyplace.go index f24eaa544b75..7705f2eaa5e2 100644 --- a/pkg/detectors/surveyanyplace/surveyanyplace.go +++ b/pkg/detectors/surveyanyplace/surveyanyplace.go @@ -3,10 +3,11 @@ package surveyanyplace import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -67,7 +68,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/surveybot/surveybot.go b/pkg/detectors/surveybot/surveybot.go index 232722d0a7ce..8f828d9a4e1a 100644 --- a/pkg/detectors/surveybot/surveybot.go +++ b/pkg/detectors/surveybot/surveybot.go @@ -3,10 +3,11 @@ package surveybot import ( "context" "encoding/json" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -58,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-Api-Key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { var r response if err := json.NewDecoder(res.Body).Decode(&r); err != nil { diff --git a/pkg/detectors/surveysparrow/surveysparrow.go b/pkg/detectors/surveysparrow/surveysparrow.go index 1edd6f0133b5..67ed2496fd90 100644 --- a/pkg/detectors/surveysparrow/surveysparrow.go +++ b/pkg/detectors/surveysparrow/surveysparrow.go @@ -3,10 +3,11 @@ package surveysparrow import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/survicate/survicate.go b/pkg/detectors/survicate/survicate.go index 4003418523c8..5fa3e85ae415 100644 --- a/pkg/detectors/survicate/survicate.go +++ b/pkg/detectors/survicate/survicate.go @@ -3,10 +3,11 @@ package survicate import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/swell/swell.go b/pkg/detectors/swell/swell.go index 585e41579a8c..d7ffeffab64b 100644 --- a/pkg/detectors/swell/swell.go +++ b/pkg/detectors/swell/swell.go @@ -2,10 +2,11 @@ package swell import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -59,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.SetBasicAuth(userPatMatch, tokenPatMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/swiftype/swiftype.go b/pkg/detectors/swiftype/swiftype.go index acd67dab0774..dd74df69bc0e 100644 --- a/pkg/detectors/swiftype/swiftype.go +++ b/pkg/detectors/swiftype/swiftype.go @@ -2,10 +2,11 @@ package swiftype import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/tailscale/tailscale.go b/pkg/detectors/tailscale/tailscale.go index e155c5312730..696400afa760 100644 --- a/pkg/detectors/tailscale/tailscale.go +++ b/pkg/detectors/tailscale/tailscale.go @@ -3,11 +3,12 @@ package tailscale import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "net/url" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -56,7 +57,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Set("Content-Type", "application/x-www-form-urlencoded") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() switch res.StatusCode { case http.StatusNoContent: s1.Verified = true diff --git a/pkg/detectors/tallyfy/tallyfy.go b/pkg/detectors/tallyfy/tallyfy.go index cfb003bae761..401a9cacc641 100644 --- a/pkg/detectors/tallyfy/tallyfy.go +++ b/pkg/detectors/tallyfy/tallyfy.go @@ -57,7 +57,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/tatumio/tatumio.go b/pkg/detectors/tatumio/tatumio.go index 9c0494b45474..7fac9fc5854b 100644 --- a/pkg/detectors/tatumio/tatumio.go +++ b/pkg/detectors/tatumio/tatumio.go @@ -2,10 +2,11 @@ package tatumio import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("x-api-key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/taxjar/taxjar.go b/pkg/detectors/taxjar/taxjar.go index 3707612a9fc9..08ba1f81d955 100644 --- a/pkg/detectors/taxjar/taxjar.go +++ b/pkg/detectors/taxjar/taxjar.go @@ -3,10 +3,11 @@ package taxjar import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/teamgate/teamgate.go b/pkg/detectors/teamgate/teamgate.go index dc87d52b79ac..36f95166641b 100644 --- a/pkg/detectors/teamgate/teamgate.go +++ b/pkg/detectors/teamgate/teamgate.go @@ -2,10 +2,11 @@ package teamgate import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -61,7 +62,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/teamworkcrm/teamworkcrm.go b/pkg/detectors/teamworkcrm/teamworkcrm.go index 6f5387d46e1c..5f651bc67814 100644 --- a/pkg/detectors/teamworkcrm/teamworkcrm.go +++ b/pkg/detectors/teamworkcrm/teamworkcrm.go @@ -3,10 +3,11 @@ package teamworkcrm import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/teamworkdesk/teamworkdesk.go b/pkg/detectors/teamworkdesk/teamworkdesk.go index 507171c299b6..dc96b4360541 100644 --- a/pkg/detectors/teamworkdesk/teamworkdesk.go +++ b/pkg/detectors/teamworkdesk/teamworkdesk.go @@ -3,10 +3,11 @@ package teamworkdesk import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/teamworkspaces/teamworkspaces.go b/pkg/detectors/teamworkspaces/teamworkspaces.go index c2fcd8d2aaa5..cf77e426aedb 100644 --- a/pkg/detectors/teamworkspaces/teamworkspaces.go +++ b/pkg/detectors/teamworkspaces/teamworkspaces.go @@ -3,10 +3,11 @@ package teamworkspaces import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/technicalanalysisapi/technicalanalysisapi.go b/pkg/detectors/technicalanalysisapi/technicalanalysisapi.go index 2ec3dbdf183f..1f9bbadbafd5 100644 --- a/pkg/detectors/technicalanalysisapi/technicalanalysisapi.go +++ b/pkg/detectors/technicalanalysisapi/technicalanalysisapi.go @@ -3,11 +3,12 @@ package technicalanalysisapi import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" "time" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -55,7 +56,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/tefter/tefter.go b/pkg/detectors/tefter/tefter.go index 93eba4b0b26f..79ae9ec55c88 100644 --- a/pkg/detectors/tefter/tefter.go +++ b/pkg/detectors/tefter/tefter.go @@ -3,11 +3,12 @@ package tefter import ( "context" "encoding/json" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -61,7 +62,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } validResponse := json.Valid(bodyBytes) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 && validResponse { s1.Verified = true } diff --git a/pkg/detectors/telegrambottoken/telegrambottoken.go b/pkg/detectors/telegrambottoken/telegrambottoken.go index 6010fadbcd13..f68b17fb5b00 100644 --- a/pkg/detectors/telegrambottoken/telegrambottoken.go +++ b/pkg/detectors/telegrambottoken/telegrambottoken.go @@ -60,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true diff --git a/pkg/detectors/teletype/teletype.go b/pkg/detectors/teletype/teletype.go index 7368e6516825..1580f4beaa58 100644 --- a/pkg/detectors/teletype/teletype.go +++ b/pkg/detectors/teletype/teletype.go @@ -2,11 +2,12 @@ package teletype import ( "context" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -62,7 +63,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `"code":401`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { s1.Verified = false diff --git a/pkg/detectors/telnyx/telnyx.go b/pkg/detectors/telnyx/telnyx.go index d6af0965c523..b2ed2bd9e0c7 100644 --- a/pkg/detectors/telnyx/telnyx.go +++ b/pkg/detectors/telnyx/telnyx.go @@ -3,10 +3,11 @@ package telnyx import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/terraformcloudpersonaltoken/terraformcloudpersonaltoken.go b/pkg/detectors/terraformcloudpersonaltoken/terraformcloudpersonaltoken.go index 5c1adf13ccb1..d72af7032df1 100644 --- a/pkg/detectors/terraformcloudpersonaltoken/terraformcloudpersonaltoken.go +++ b/pkg/detectors/terraformcloudpersonaltoken/terraformcloudpersonaltoken.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/textmagic/textmagic.go b/pkg/detectors/textmagic/textmagic.go index 3efefa83442e..c81b68dc0dee 100644 --- a/pkg/detectors/textmagic/textmagic.go +++ b/pkg/detectors/textmagic/textmagic.go @@ -4,10 +4,11 @@ import ( "context" b64 "encoding/base64" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -68,7 +69,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", sEnc)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/theoddsapi/theoddsapi.go b/pkg/detectors/theoddsapi/theoddsapi.go index 60ee52ec40c9..80ee5d994562 100644 --- a/pkg/detectors/theoddsapi/theoddsapi.go +++ b/pkg/detectors/theoddsapi/theoddsapi.go @@ -2,10 +2,11 @@ package theoddsapi import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -51,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/thinkific/thinkific.go b/pkg/detectors/thinkific/thinkific.go index bdbcbcb3420f..50deded997e4 100644 --- a/pkg/detectors/thinkific/thinkific.go +++ b/pkg/detectors/thinkific/thinkific.go @@ -62,7 +62,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { continue diff --git a/pkg/detectors/thousandeyes/thousandeyes.go b/pkg/detectors/thousandeyes/thousandeyes.go index 7bc3df09ccb9..b246247cdb6f 100644 --- a/pkg/detectors/thousandeyes/thousandeyes.go +++ b/pkg/detectors/thousandeyes/thousandeyes.go @@ -2,10 +2,11 @@ package thousandeyes import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -60,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.SetBasicAuth(userPatMatch, tokenPatMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/ticketmaster/ticketmaster.go b/pkg/detectors/ticketmaster/ticketmaster.go index e7c68dcce448..b097ac36f017 100644 --- a/pkg/detectors/ticketmaster/ticketmaster.go +++ b/pkg/detectors/ticketmaster/ticketmaster.go @@ -3,10 +3,11 @@ package ticketmaster import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/tiingo/tiingo.go b/pkg/detectors/tiingo/tiingo.go index 3a1e124ea8cc..3bc121876d05 100644 --- a/pkg/detectors/tiingo/tiingo.go +++ b/pkg/detectors/tiingo/tiingo.go @@ -3,10 +3,11 @@ package tiingo import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Token %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/timecamp/timecamp.go b/pkg/detectors/timecamp/timecamp.go index 168b6e3331ba..51f7fd1d5f5e 100644 --- a/pkg/detectors/timecamp/timecamp.go +++ b/pkg/detectors/timecamp/timecamp.go @@ -2,10 +2,11 @@ package timecamp import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/timezoneapi/timezoneapi.go b/pkg/detectors/timezoneapi/timezoneapi.go index a1433612c4d5..5b243e87aed8 100644 --- a/pkg/detectors/timezoneapi/timezoneapi.go +++ b/pkg/detectors/timezoneapi/timezoneapi.go @@ -2,10 +2,11 @@ package timezoneapi import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -56,7 +57,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err != nil { return nil, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 && verifiedBodyResponse { s1.Verified = true } diff --git a/pkg/detectors/tineswebhook/tineswebhook.go b/pkg/detectors/tineswebhook/tineswebhook.go index 55415b2ccc37..333db9d9e79a 100644 --- a/pkg/detectors/tineswebhook/tineswebhook.go +++ b/pkg/detectors/tineswebhook/tineswebhook.go @@ -52,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/tly/tly.go b/pkg/detectors/tly/tly.go index 8e38eafe9f26..d756125e41c0 100644 --- a/pkg/detectors/tly/tly.go +++ b/pkg/detectors/tly/tly.go @@ -2,10 +2,11 @@ package tly import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -51,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/tmetric/tmetric.go b/pkg/detectors/tmetric/tmetric.go index c9d6e8b0ebb0..703ed4b82b7d 100644 --- a/pkg/detectors/tmetric/tmetric.go +++ b/pkg/detectors/tmetric/tmetric.go @@ -3,10 +3,11 @@ package tmetric import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/todoist/todoist.go b/pkg/detectors/todoist/todoist.go index 6181f9d72aa1..612ad84103e6 100644 --- a/pkg/detectors/todoist/todoist.go +++ b/pkg/detectors/todoist/todoist.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/toggltrack/toggltrack.go b/pkg/detectors/toggltrack/toggltrack.go index d646f1af626a..0e7ba2f902e9 100644 --- a/pkg/detectors/toggltrack/toggltrack.go +++ b/pkg/detectors/toggltrack/toggltrack.go @@ -4,10 +4,11 @@ import ( "context" b64 "encoding/base64" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -57,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", sEnc)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/tokeet/tokeet.go b/pkg/detectors/tokeet/tokeet.go index e0823f10a3f0..f658716db1a0 100644 --- a/pkg/detectors/tokeet/tokeet.go +++ b/pkg/detectors/tokeet/tokeet.go @@ -3,10 +3,11 @@ package tokeet import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -60,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/tomorrowio/tomorrowio.go b/pkg/detectors/tomorrowio/tomorrowio.go index 4a9011ac87c9..6252d21313aa 100644 --- a/pkg/detectors/tomorrowio/tomorrowio.go +++ b/pkg/detectors/tomorrowio/tomorrowio.go @@ -3,10 +3,11 @@ package tomorrowio import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/tomtom/tomtom.go b/pkg/detectors/tomtom/tomtom.go index 007f1eeb07d6..e3085e26b4c5 100644 --- a/pkg/detectors/tomtom/tomtom.go +++ b/pkg/detectors/tomtom/tomtom.go @@ -51,7 +51,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/tradier/tradier.go b/pkg/detectors/tradier/tradier.go index dedd679e9bb6..0bb66bb35381 100644 --- a/pkg/detectors/tradier/tradier.go +++ b/pkg/detectors/tradier/tradier.go @@ -3,10 +3,11 @@ package tradier import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/transferwise/transferwise.go b/pkg/detectors/transferwise/transferwise.go index 1fa16c9e837c..d2d1ae2e7033 100644 --- a/pkg/detectors/transferwise/transferwise.go +++ b/pkg/detectors/transferwise/transferwise.go @@ -3,10 +3,11 @@ package transferwise import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/travelpayouts/travelpayouts.go b/pkg/detectors/travelpayouts/travelpayouts.go index aaee81115cd9..a663ba0dbfc7 100644 --- a/pkg/detectors/travelpayouts/travelpayouts.go +++ b/pkg/detectors/travelpayouts/travelpayouts.go @@ -3,10 +3,11 @@ package travelpayouts import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/travisci/travisci.go b/pkg/detectors/travisci/travisci.go index bcfbbd033adc..5597a45b096b 100644 --- a/pkg/detectors/travisci/travisci.go +++ b/pkg/detectors/travisci/travisci.go @@ -3,10 +3,11 @@ package travisci import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Travis-API-Version", "3") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/trelloapikey/trelloapikey.go b/pkg/detectors/trelloapikey/trelloapikey.go index ed6962486310..76ef96d4def4 100644 --- a/pkg/detectors/trelloapikey/trelloapikey.go +++ b/pkg/detectors/trelloapikey/trelloapikey.go @@ -2,10 +2,11 @@ package trelloapikey import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -58,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/tru/tru.go b/pkg/detectors/tru/tru.go index 3ba432c3566d..45eb53b4a371 100644 --- a/pkg/detectors/tru/tru.go +++ b/pkg/detectors/tru/tru.go @@ -4,10 +4,11 @@ import ( "context" b64 "encoding/base64" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -68,7 +69,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", baseToken)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/trufflehogenterprise/trufflehogenterprise.go b/pkg/detectors/trufflehogenterprise/trufflehogenterprise.go index d0415b3c8995..248336e1fe4f 100644 --- a/pkg/detectors/trufflehogenterprise/trufflehogenterprise.go +++ b/pkg/detectors/trufflehogenterprise/trufflehogenterprise.go @@ -3,10 +3,11 @@ package trufflehogenterprise import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -75,7 +76,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return nil, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 && verifiedBodyResponse { s1.Verified = true diff --git a/pkg/detectors/twelvedata/twelvedata.go b/pkg/detectors/twelvedata/twelvedata.go index 5f779eea7e7e..a6df49260904 100644 --- a/pkg/detectors/twelvedata/twelvedata.go +++ b/pkg/detectors/twelvedata/twelvedata.go @@ -2,11 +2,12 @@ package twelvedata import ( "context" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { continue diff --git a/pkg/detectors/twist/twist.go b/pkg/detectors/twist/twist.go index c59f90cf8526..24d4f20db8fc 100644 --- a/pkg/detectors/twist/twist.go +++ b/pkg/detectors/twist/twist.go @@ -3,10 +3,11 @@ package twist import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -58,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", setAuth)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/twitch/twitch.go b/pkg/detectors/twitch/twitch.go index c5276b9b4706..e6ef01968fcb 100644 --- a/pkg/detectors/twitch/twitch.go +++ b/pkg/detectors/twitch/twitch.go @@ -108,7 +108,7 @@ func verifyTwitch(ctx context.Context, client *http.Client, resMatch string, res if err != nil { return false, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() switch res.StatusCode { case http.StatusOK: diff --git a/pkg/detectors/twitter/v1/twitter_v1.go b/pkg/detectors/twitter/v1/twitter_v1.go index 094288f185a1..12f686b2c2b5 100644 --- a/pkg/detectors/twitter/v1/twitter_v1.go +++ b/pkg/detectors/twitter/v1/twitter_v1.go @@ -94,7 +94,7 @@ func (s Scanner) VerifyTwitterToken(ctx context.Context, client *http.Client, to return false, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() switch res.StatusCode { case http.StatusOK: return true, nil diff --git a/pkg/detectors/twitterconsumerkey/twitterconsumerkey.go b/pkg/detectors/twitterconsumerkey/twitterconsumerkey.go index 3a6687b9be6d..9e0b2b20c47d 100644 --- a/pkg/detectors/twitterconsumerkey/twitterconsumerkey.go +++ b/pkg/detectors/twitterconsumerkey/twitterconsumerkey.go @@ -103,7 +103,7 @@ func verifyBearerToken(ctx context.Context, client *http.Client, token string) ( req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() switch res.StatusCode { case http.StatusOK, http.StatusForbidden: // 403 indicates lack of permission, but valid token (could be due to twitter free tier) @@ -132,7 +132,7 @@ func fetchBearerToken(ctx context.Context, client *http.Client, key, secret stri if err != nil { return "", err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() switch res.StatusCode { case http.StatusOK: diff --git a/pkg/detectors/tyntec/tyntec.go b/pkg/detectors/tyntec/tyntec.go index 692fa4907ee3..fc81b1d28bb0 100644 --- a/pkg/detectors/tyntec/tyntec.go +++ b/pkg/detectors/tyntec/tyntec.go @@ -2,10 +2,11 @@ package tyntec import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("apiKey", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/typeform/v2/typeform.go b/pkg/detectors/typeform/v2/typeform.go index 89885dc0888e..d44bd65bf124 100644 --- a/pkg/detectors/typeform/v2/typeform.go +++ b/pkg/detectors/typeform/v2/typeform.go @@ -100,16 +100,17 @@ func verifyMatch(ctx context.Context, client *http.Client, secret string) (bool, _ = res.Body.Close() }() - if res.StatusCode == 200 { + switch res.StatusCode { + case 200: var response *TypeFormResponse if err = json.NewDecoder(res.Body).Decode(&response); err != nil { return false, nil, err } return true, response, nil - } else if res.StatusCode == 401 || res.StatusCode == 403 { + case 401, 403: return false, nil, nil - } else { + default: return false, nil, fmt.Errorf("unexpected status code %d", res.StatusCode) } } diff --git a/pkg/detectors/typetalk/typetalk.go b/pkg/detectors/typetalk/typetalk.go index c27764be4d80..d7938aac97d8 100644 --- a/pkg/detectors/typetalk/typetalk.go +++ b/pkg/detectors/typetalk/typetalk.go @@ -3,10 +3,11 @@ package typetalk import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -59,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/ubidots/ubidots.go b/pkg/detectors/ubidots/ubidots.go index b18ea4e18798..a6f7e28e4f81 100644 --- a/pkg/detectors/ubidots/ubidots.go +++ b/pkg/detectors/ubidots/ubidots.go @@ -2,10 +2,11 @@ package ubidots import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-Auth-Token", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/uclassify/uclassify.go b/pkg/detectors/uclassify/uclassify.go index c97189fe7b92..21710289d838 100644 --- a/pkg/detectors/uclassify/uclassify.go +++ b/pkg/detectors/uclassify/uclassify.go @@ -3,10 +3,11 @@ package uclassify import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -55,7 +56,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Token %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/unifyid/unifyid.go b/pkg/detectors/unifyid/unifyid.go index 25a4b2ad5dd7..991b31d96b66 100644 --- a/pkg/detectors/unifyid/unifyid.go +++ b/pkg/detectors/unifyid/unifyid.go @@ -2,11 +2,12 @@ package unifyid import ( "context" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -55,7 +56,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("X-API-Key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { continue diff --git a/pkg/detectors/unplugg/unplugg.go b/pkg/detectors/unplugg/unplugg.go index 981d9381f0b8..1d90993a1fd1 100644 --- a/pkg/detectors/unplugg/unplugg.go +++ b/pkg/detectors/unplugg/unplugg.go @@ -2,10 +2,11 @@ package unplugg import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("x-access-token", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/unsplash/unsplash.go b/pkg/detectors/unsplash/unsplash.go index fce5168664b9..7638ab3c245a 100644 --- a/pkg/detectors/unsplash/unsplash.go +++ b/pkg/detectors/unsplash/unsplash.go @@ -2,10 +2,11 @@ package unsplash import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -51,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/upcdatabase/upcdatabase.go b/pkg/detectors/upcdatabase/upcdatabase.go index b0227be30d56..b6f60110a556 100644 --- a/pkg/detectors/upcdatabase/upcdatabase.go +++ b/pkg/detectors/upcdatabase/upcdatabase.go @@ -3,11 +3,12 @@ package upcdatabase import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -57,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err == nil { bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `added_time`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { s1.Verified = true diff --git a/pkg/detectors/uplead/uplead.go b/pkg/detectors/uplead/uplead.go index 536300baa040..da41156eb488 100644 --- a/pkg/detectors/uplead/uplead.go +++ b/pkg/detectors/uplead/uplead.go @@ -2,10 +2,11 @@ package uplead import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/uploadcare/uploadcare.go b/pkg/detectors/uploadcare/uploadcare.go index 12ba6f78e1f4..d05452fae381 100644 --- a/pkg/detectors/uploadcare/uploadcare.go +++ b/pkg/detectors/uploadcare/uploadcare.go @@ -3,10 +3,11 @@ package uploadcare import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -60,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Uploadcare.Simple %s:%s", publicKeyMatch, resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/uptimerobot/uptimerobot.go b/pkg/detectors/uptimerobot/uptimerobot.go index 18c372f8a1f7..76bddc3aca15 100644 --- a/pkg/detectors/uptimerobot/uptimerobot.go +++ b/pkg/detectors/uptimerobot/uptimerobot.go @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `"ok"`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { s1.Verified = true diff --git a/pkg/detectors/upwave/upwave.go b/pkg/detectors/upwave/upwave.go index 95d22f6505d6..ecf542db48ce 100644 --- a/pkg/detectors/upwave/upwave.go +++ b/pkg/detectors/upwave/upwave.go @@ -3,10 +3,11 @@ package upwave import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Token %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/urlscan/urlscan.go b/pkg/detectors/urlscan/urlscan.go index 2291df6afde9..05ec485ff107 100644 --- a/pkg/detectors/urlscan/urlscan.go +++ b/pkg/detectors/urlscan/urlscan.go @@ -2,10 +2,11 @@ package urlscan import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("API-Key", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/user/user.go b/pkg/detectors/user/user.go index 50c2242264f7..953610140160 100644 --- a/pkg/detectors/user/user.go +++ b/pkg/detectors/user/user.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Token %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/userflow/userflow.go b/pkg/detectors/userflow/userflow.go index 118ce97f6f51..7982fa5d4e33 100644 --- a/pkg/detectors/userflow/userflow.go +++ b/pkg/detectors/userflow/userflow.go @@ -3,10 +3,11 @@ package userflow import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/userstack/userstack.go b/pkg/detectors/userstack/userstack.go index 6d0a201a43d2..8132d716b0d9 100644 --- a/pkg/detectors/userstack/userstack.go +++ b/pkg/detectors/userstack/userstack.go @@ -3,11 +3,12 @@ package userstack import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -57,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err == nil { bodyString := string(bodyBytes) valid := strings.Contains(bodyString, `is_mobile_device`) || strings.Contains(bodyString, `"info":"Access Restricted - Your current Subscription Plan does not support HTTPS Encryption."`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if valid { s1.Verified = true } else { diff --git a/pkg/detectors/vagrantcloudpersonaltoken/vagrantcloudpersonaltoken.go b/pkg/detectors/vagrantcloudpersonaltoken/vagrantcloudpersonaltoken.go index 3dd2cf7e8d90..f38a71631e83 100644 --- a/pkg/detectors/vagrantcloudpersonaltoken/vagrantcloudpersonaltoken.go +++ b/pkg/detectors/vagrantcloudpersonaltoken/vagrantcloudpersonaltoken.go @@ -60,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode == 401 { diff --git a/pkg/detectors/vatlayer/vatlayer.go b/pkg/detectors/vatlayer/vatlayer.go index 3f16298915bc..d0022ce5e951 100644 --- a/pkg/detectors/vatlayer/vatlayer.go +++ b/pkg/detectors/vatlayer/vatlayer.go @@ -3,11 +3,12 @@ package vatlayer import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -57,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if err == nil { bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `vat_number`) || strings.Contains(bodyString, `"info":"Access Restricted - Your current Subscription Plan does not support HTTPS Encryption."`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { s1.Verified = true diff --git a/pkg/detectors/vbout/vbout.go b/pkg/detectors/vbout/vbout.go index 477e2dee690f..0738b6686eac 100644 --- a/pkg/detectors/vbout/vbout.go +++ b/pkg/detectors/vbout/vbout.go @@ -3,10 +3,11 @@ package vbout import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/vercel/vercel.go b/pkg/detectors/vercel/vercel.go index 336ed1d4b718..fb443fed9f97 100644 --- a/pkg/detectors/vercel/vercel.go +++ b/pkg/detectors/vercel/vercel.go @@ -3,10 +3,11 @@ package vercel import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/verifier/verifier.go b/pkg/detectors/verifier/verifier.go index d13df44c1511..61218168ee51 100644 --- a/pkg/detectors/verifier/verifier.go +++ b/pkg/detectors/verifier/verifier.go @@ -61,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/verimail/verimail.go b/pkg/detectors/verimail/verimail.go index 24c2fc95891a..b1e7c79576fd 100644 --- a/pkg/detectors/verimail/verimail.go +++ b/pkg/detectors/verimail/verimail.go @@ -52,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/veriphone/veriphone.go b/pkg/detectors/veriphone/veriphone.go index 447437d87335..09855e65a7dc 100644 --- a/pkg/detectors/veriphone/veriphone.go +++ b/pkg/detectors/veriphone/veriphone.go @@ -52,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/versioneye/versioneye.go b/pkg/detectors/versioneye/versioneye.go index e32474089521..880fb7d8389c 100644 --- a/pkg/detectors/versioneye/versioneye.go +++ b/pkg/detectors/versioneye/versioneye.go @@ -2,10 +2,11 @@ package versioneye import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("apiKey", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/viewneo/viewneo.go b/pkg/detectors/viewneo/viewneo.go index eb3381567988..7916f16bf96a 100644 --- a/pkg/detectors/viewneo/viewneo.go +++ b/pkg/detectors/viewneo/viewneo.go @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/virustotal/virustotal.go b/pkg/detectors/virustotal/virustotal.go index 591d8de9f154..7937f380681a 100644 --- a/pkg/detectors/virustotal/virustotal.go +++ b/pkg/detectors/virustotal/virustotal.go @@ -2,10 +2,11 @@ package virustotal import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -64,7 +65,7 @@ func verifyToken(ctx context.Context, client *http.Client, token string) bool { if err != nil { return false } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode < 200 || res.StatusCode >= 300 { return false diff --git a/pkg/detectors/visualcrossing/visualcrossing.go b/pkg/detectors/visualcrossing/visualcrossing.go index 01eded31e824..24844e07cd2f 100644 --- a/pkg/detectors/visualcrossing/visualcrossing.go +++ b/pkg/detectors/visualcrossing/visualcrossing.go @@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/voiceflow/voiceflow.go b/pkg/detectors/voiceflow/voiceflow.go index 59ba768a0020..30d6d3462fef 100644 --- a/pkg/detectors/voiceflow/voiceflow.go +++ b/pkg/detectors/voiceflow/voiceflow.go @@ -67,11 +67,12 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - if res.StatusCode == http.StatusOK { + switch res.StatusCode { + case http.StatusOK: s1.Verified = true - } else if res.StatusCode == http.StatusUnauthorized { + case http.StatusUnauthorized: // The secret is determinately not verified (nothing to do) - } else { + default: var buf bytes.Buffer var bodyString string _, err = io.Copy(&buf, res.Body) diff --git a/pkg/detectors/voicegain/voicegain.go b/pkg/detectors/voicegain/voicegain.go index 538b103b64cc..efa81366d12a 100644 --- a/pkg/detectors/voicegain/voicegain.go +++ b/pkg/detectors/voicegain/voicegain.go @@ -3,10 +3,11 @@ package voicegain import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/voodoosms/voodoosms.go b/pkg/detectors/voodoosms/voodoosms.go index 5fe86f6d969a..ce0dfe6979ae 100644 --- a/pkg/detectors/voodoosms/voodoosms.go +++ b/pkg/detectors/voodoosms/voodoosms.go @@ -3,10 +3,11 @@ package voodoosms import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/vouchery/vouchery.go b/pkg/detectors/vouchery/vouchery.go index cf2f3369c171..1cb4324fd3d6 100644 --- a/pkg/detectors/vouchery/vouchery.go +++ b/pkg/detectors/vouchery/vouchery.go @@ -3,10 +3,11 @@ package vouchery import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -65,7 +66,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/vpnapi/vpnapi.go b/pkg/detectors/vpnapi/vpnapi.go index 9cc630afa009..29138432a887 100644 --- a/pkg/detectors/vpnapi/vpnapi.go +++ b/pkg/detectors/vpnapi/vpnapi.go @@ -2,10 +2,11 @@ package vpnapi import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -51,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/vultrapikey/vultrapikey.go b/pkg/detectors/vultrapikey/vultrapikey.go index d3210ec93875..7beca19b9e81 100644 --- a/pkg/detectors/vultrapikey/vultrapikey.go +++ b/pkg/detectors/vultrapikey/vultrapikey.go @@ -3,10 +3,11 @@ package vultrapikey import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/vyte/vyte.go b/pkg/detectors/vyte/vyte.go index 5127a9ebb780..c166a1c31613 100644 --- a/pkg/detectors/vyte/vyte.go +++ b/pkg/detectors/vyte/vyte.go @@ -2,10 +2,11 @@ package vyte import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", resMatch) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/walkscore/walkscore.go b/pkg/detectors/walkscore/walkscore.go index 3b6f26951c28..4608c6fda1f0 100644 --- a/pkg/detectors/walkscore/walkscore.go +++ b/pkg/detectors/walkscore/walkscore.go @@ -3,11 +3,12 @@ package walkscore import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { continue diff --git a/pkg/detectors/weatherbit/weatherbit.go b/pkg/detectors/weatherbit/weatherbit.go index 02b7e6b29f6f..4c07720e9042 100644 --- a/pkg/detectors/weatherbit/weatherbit.go +++ b/pkg/detectors/weatherbit/weatherbit.go @@ -3,10 +3,11 @@ package weatherbit import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/weatherstack/weatherstack.go b/pkg/detectors/weatherstack/weatherstack.go index 685d360d710d..a33098f6db2e 100644 --- a/pkg/detectors/weatherstack/weatherstack.go +++ b/pkg/detectors/weatherstack/weatherstack.go @@ -3,11 +3,12 @@ package weatherstack import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { continue diff --git a/pkg/detectors/web3storage/web3storage.go b/pkg/detectors/web3storage/web3storage.go index 06516a6629ce..988fabecfa9d 100644 --- a/pkg/detectors/web3storage/web3storage.go +++ b/pkg/detectors/web3storage/web3storage.go @@ -3,10 +3,11 @@ package web3storage import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -58,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode == 401 { diff --git a/pkg/detectors/webex/webex.go b/pkg/detectors/webex/webex.go index 67bacc452cbe..e3e9ec382c63 100644 --- a/pkg/detectors/webex/webex.go +++ b/pkg/detectors/webex/webex.go @@ -3,11 +3,12 @@ package webex import ( "context" "encoding/json" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -60,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { body, err := io.ReadAll(res.Body) - res.Body.Close() + _ = res.Body.Close() if err == nil { var message struct { Message string `json:"message"` diff --git a/pkg/detectors/webflow/webflow.go b/pkg/detectors/webflow/webflow.go index 3a65cb603a94..3dd5236893ee 100644 --- a/pkg/detectors/webflow/webflow.go +++ b/pkg/detectors/webflow/webflow.go @@ -3,10 +3,11 @@ package webflow import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/webscraper/webscraper.go b/pkg/detectors/webscraper/webscraper.go index 13319c8fdd89..b03edf540c1e 100644 --- a/pkg/detectors/webscraper/webscraper.go +++ b/pkg/detectors/webscraper/webscraper.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/webscraping/webscraping.go b/pkg/detectors/webscraping/webscraping.go index ebf57bee609c..f34dbe58ce46 100644 --- a/pkg/detectors/webscraping/webscraping.go +++ b/pkg/detectors/webscraping/webscraping.go @@ -2,11 +2,12 @@ package webscraping import ( "context" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { continue diff --git a/pkg/detectors/websitepulse/websitepulse.go b/pkg/detectors/websitepulse/websitepulse.go index 2a84454eddf0..5e23b2675ee9 100644 --- a/pkg/detectors/websitepulse/websitepulse.go +++ b/pkg/detectors/websitepulse/websitepulse.go @@ -3,11 +3,12 @@ package websitepulse import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -58,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { continue diff --git a/pkg/detectors/wepay/wepay.go b/pkg/detectors/wepay/wepay.go index 6c231601416a..341f960c29c4 100644 --- a/pkg/detectors/wepay/wepay.go +++ b/pkg/detectors/wepay/wepay.go @@ -2,10 +2,11 @@ package wepay import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -66,7 +67,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/whoxy/whoxy.go b/pkg/detectors/whoxy/whoxy.go index f84e7efe9e95..4e7af4e9ac4b 100644 --- a/pkg/detectors/whoxy/whoxy.go +++ b/pkg/detectors/whoxy/whoxy.go @@ -3,11 +3,12 @@ package whoxy import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "io" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -54,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { continue diff --git a/pkg/detectors/wistia/wistia.go b/pkg/detectors/wistia/wistia.go index 846565df1b90..80c7cda03ca7 100644 --- a/pkg/detectors/wistia/wistia.go +++ b/pkg/detectors/wistia/wistia.go @@ -2,10 +2,11 @@ package wistia import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -51,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/wit/wit.go b/pkg/detectors/wit/wit.go index fb1829a0d432..a6a259d3dcfb 100644 --- a/pkg/detectors/wit/wit.go +++ b/pkg/detectors/wit/wit.go @@ -3,10 +3,11 @@ package wit import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/worksnaps/worksnaps.go b/pkg/detectors/worksnaps/worksnaps.go index 8753398356e5..2ebef27265af 100644 --- a/pkg/detectors/worksnaps/worksnaps.go +++ b/pkg/detectors/worksnaps/worksnaps.go @@ -4,10 +4,11 @@ import ( "context" b64 "encoding/base64" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -56,7 +57,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Basic %s", sEnc)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/workstack/workstack.go b/pkg/detectors/workstack/workstack.go index 37883a01a940..0a3d38b32d4e 100644 --- a/pkg/detectors/workstack/workstack.go +++ b/pkg/detectors/workstack/workstack.go @@ -2,10 +2,11 @@ package workstack import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -52,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Accept", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/worldcoinindex/worldcoinindex.go b/pkg/detectors/worldcoinindex/worldcoinindex.go index 92783c8e719a..1a74179a0c2e 100644 --- a/pkg/detectors/worldcoinindex/worldcoinindex.go +++ b/pkg/detectors/worldcoinindex/worldcoinindex.go @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `"Markets"`) - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { s1.Verified = true diff --git a/pkg/detectors/worldweather/worldweather.go b/pkg/detectors/worldweather/worldweather.go index 596c2d2d03a6..bba10a2cb693 100644 --- a/pkg/detectors/worldweather/worldweather.go +++ b/pkg/detectors/worldweather/worldweather.go @@ -3,10 +3,11 @@ package worldweather import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Content-Type", "application/json") res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/wrike/wrike.go b/pkg/detectors/wrike/wrike.go index a0017ab1c0c8..146b00c8e158 100644 --- a/pkg/detectors/wrike/wrike.go +++ b/pkg/detectors/wrike/wrike.go @@ -3,10 +3,11 @@ package wrike import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/yandex/yandex.go b/pkg/detectors/yandex/yandex.go index a021e52042c0..91e06b68c4db 100644 --- a/pkg/detectors/yandex/yandex.go +++ b/pkg/detectors/yandex/yandex.go @@ -2,10 +2,11 @@ package yandex import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -51,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/yelp/yelp.go b/pkg/detectors/yelp/yelp.go index a5577b6670de..b287afd8eb53 100644 --- a/pkg/detectors/yelp/yelp.go +++ b/pkg/detectors/yelp/yelp.go @@ -62,7 +62,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else if res.StatusCode == 401 || res.StatusCode == 403 { diff --git a/pkg/detectors/youneedabudget/youneedabudget.go b/pkg/detectors/youneedabudget/youneedabudget.go index 49a83193e610..3cb64d8e000a 100644 --- a/pkg/detectors/youneedabudget/youneedabudget.go +++ b/pkg/detectors/youneedabudget/youneedabudget.go @@ -3,10 +3,11 @@ package youneedabudget import ( "context" "fmt" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -53,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/yousign/yousign.go b/pkg/detectors/yousign/yousign.go index 973fd4b59029..546fa4250b3b 100644 --- a/pkg/detectors/yousign/yousign.go +++ b/pkg/detectors/yousign/yousign.go @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } else { @@ -71,7 +71,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch)) res, err = client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/detectors/youtubeapikey/youtubeapikey.go b/pkg/detectors/youtubeapikey/youtubeapikey.go index d0f6dffa12e7..3f28f63601ec 100644 --- a/pkg/detectors/youtubeapikey/youtubeapikey.go +++ b/pkg/detectors/youtubeapikey/youtubeapikey.go @@ -2,10 +2,11 @@ package youtubeapikey import ( "context" - regexp "github.com/wasilibs/go-re2" "net/http" "strings" + regexp "github.com/wasilibs/go-re2" + "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb" @@ -58,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } res, err := client.Do(req) if err == nil { - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { s1.Verified = true } diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index 180e9e18900c..729190dd850b 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -39,8 +39,8 @@ import ( var detectionTimeout = detectors.DefaultResponseTimeout var errOverlap = errors.New( - "More than one detector has found this result. For your safety, verification has been disabled." + - "You can override this behavior by using the --allow-verification-overlap flag.", + "more than one detector has found this result; for your safety, verification has been disabled. " + + "You can override this behavior by using the --allow-verification-overlap flag", ) // Metrics for the scan engine for external consumption. @@ -829,11 +829,11 @@ func iterativeDecode(chunk *sources.Chunk, allDecoders []decoders.Decoder, maxDe if depth+1 < maxDepth && decoder.Type() != detectorspb.DecoderType_PLAIN && - !bytes.Equal(decoded.Chunk.Data, data) && - !slices.ContainsFunc(seen, func(s []byte) bool { return bytes.Equal(s, decoded.Chunk.Data) }) { + !bytes.Equal(decoded.Data, data) && + !slices.ContainsFunc(seen, func(s []byte) bool { return bytes.Equal(s, decoded.Data) }) { - seen = append(seen, decoded.Chunk.Data) - nextInputs = append(nextInputs, decoded.Chunk.Data) + seen = append(seen, decoded.Data) + nextInputs = append(nextInputs, decoded.Data) } } } @@ -859,7 +859,7 @@ func (e *Engine) scannerWorker(ctx context.Context) { decoded := iterativeDecode(chunk, e.decoders, e.maxDecodeDepth) for _, d := range decoded { - matchingDetectors := e.AhoCorasickCore.FindDetectorMatches(d.Chunk.Data) + matchingDetectors := e.AhoCorasickCore.FindDetectorMatches(d.Data) if len(matchingDetectors) > 1 && !e.verificationOverlap { wgVerificationOverlap.Add(1) e.verificationOverlapChunksChan <- verificationOverlapChunk{ @@ -1056,7 +1056,7 @@ func (e *Engine) verificationOverlapWorker(ctx context.Context) { res, chunk.chunk, chunk.decoder, - detector.Detector.Description(), + detector.Description(), isFalsePositive, ) @@ -1183,7 +1183,7 @@ func (e *Engine) detectChunk(ctx context.Context, data detectableChunk) { } for _, res := range results { - e.processResult(ctx, res, data.chunk, data.decoder, data.detector.Detector.Description(), isFalsePositive) + e.processResult(ctx, res, data.chunk, data.decoder, data.detector.Description(), isFalsePositive) } } diff --git a/pkg/engine/engine_test.go b/pkg/engine/engine_test.go index e5ca7ef95733..0ee930e3d4f1 100644 --- a/pkg/engine/engine_test.go +++ b/pkg/engine/engine_test.go @@ -415,7 +415,7 @@ even more`, tmpFile, err := os.CreateTemp("", "test_aws_credentials") assert.NoError(t, err) - defer os.Remove(tmpFile.Name()) + defer func() { _ = os.Remove(tmpFile.Name()) }() err = os.WriteFile(tmpFile.Name(), []byte(tt.content), os.ModeAppend) assert.NoError(t, err) @@ -463,10 +463,10 @@ func TestEngine_VersionedDetectorsVerifiedSecrets(t *testing.T) { tmpFile, err := os.CreateTemp("", "testfile") assert.Nil(t, err) - defer tmpFile.Close() - defer os.Remove(tmpFile.Name()) + defer func() { _ = tmpFile.Close() }() + defer func() { _ = os.Remove(tmpFile.Name()) }() - _, err = tmpFile.WriteString(fmt.Sprintf("test data using keyword %s", fakeDetectorKeyword)) + _, err = fmt.Fprintf(tmpFile, "test data using keyword %s", fakeDetectorKeyword) assert.NoError(t, err) const defaultOutputBufferSize = 64 @@ -507,8 +507,8 @@ func TestEngine_VersionedDetectorsVerifiedSecrets(t *testing.T) { func TestEngine_CustomDetectorsDetectorsVerifiedSecrets(t *testing.T) { tmpFile, err := os.CreateTemp("", "testfile") assert.Nil(t, err) - defer tmpFile.Close() - defer os.Remove(tmpFile.Name()) + defer func() { _ = tmpFile.Close() }() + defer func() { _ = os.Remove(tmpFile.Name()) }() _, err = tmpFile.WriteString("test stuff") assert.Nil(t, err) @@ -1444,7 +1444,7 @@ def test_something(): tmpFile, err := os.CreateTemp("", "test_creds") assert.NoError(t, err) - defer os.Remove(tmpFile.Name()) + defer func() { _ = os.Remove(tmpFile.Name()) }() err = os.WriteFile(tmpFile.Name(), []byte(tt.content), os.ModeAppend) assert.NoError(t, err) @@ -1557,7 +1557,7 @@ func TestEngine_DetectChunk_UsesVerifyFlag(t *testing.T) { // Assert: Confirm that a result was generated and that it has the expected verify flag. select { case result := <-e.results: - assert.Equal(t, tc.verify, result.Result.Verified) + assert.Equal(t, tc.verify, result.Verified) default: t.Errorf("expected a result but did not get one") } @@ -1679,7 +1679,7 @@ func TestEngine_VerificationOverlapWorker_DetectableChunkHasCorrectVerifyFlag(t // Assert: Confirm that every generated result is unverified (because overlap detection precluded it). for result := range e.results { - assert.False(t, result.Result.Verified) + assert.False(t, result.Verified) } // Assert: Confirm that every generated detectable chunk's Chunk.SourceVerify flag is unchanged and that its diff --git a/pkg/engine/git_test.go b/pkg/engine/git_test.go index e1b6ce51d9da..cdbc96de0a99 100644 --- a/pkg/engine/git_test.go +++ b/pkg/engine/git_test.go @@ -41,7 +41,7 @@ func TestGitEngine(t *testing.T) { if err != nil { t.Error(err) } - defer os.RemoveAll(path) + defer func() { _ = os.RemoveAll(path) }() ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -130,7 +130,7 @@ func TestGitEngineWithMirrorAndBareClones(t *testing.T) { if err != nil { t.Fail() } - defer os.RemoveAll(parent) + defer func() { _ = os.RemoveAll(parent) }() localRepo := filepath.Join(parent, "test_keys.git") cloneCtx, cancel := context.WithTimeout(ctx, 10*time.Second) defer cancel() diff --git a/pkg/gitparse/gitparse.go b/pkg/gitparse/gitparse.go index 3c6a0c804500..01fe53cbb100 100644 --- a/pkg/gitparse/gitparse.go +++ b/pkg/gitparse/gitparse.go @@ -371,10 +371,7 @@ func (c *Parser) FromReader(ctx context.Context, stdOut io.Reader, diffChan chan defer common.RecoverWithExit(ctx) defer close(diffChan) - for { - if common.IsDone(ctx) { - break - } + for !common.IsDone(ctx) { line, err := outReader.ReadBytes([]byte("\n")[0]) if err != nil && len(line) == 0 { @@ -616,15 +613,15 @@ func isMergeLine(isStaged bool, latestState ParseState, line []byte) bool { // commit 7a95bbf0199e280a0e42dbb1d1a3f56cdd0f6e05 func isCommitLine(isStaged bool, latestState ParseState, line []byte) bool { - if isStaged || !(latestState == Initial || - latestState == MessageStartLine || - latestState == MessageEndLine || - latestState == ModeLine || - latestState == IndexLine || - latestState == BinaryFileLine || - latestState == ToFileLine || - latestState == HunkContentLine || - latestState == ParseFailure) { + if isStaged || (latestState != Initial && + latestState != MessageStartLine && + latestState != MessageEndLine && + latestState != ModeLine && + latestState != IndexLine && + latestState != BinaryFileLine && + latestState != ToFileLine && + latestState != HunkContentLine && + latestState != ParseFailure) { return false } @@ -636,7 +633,7 @@ func isCommitLine(isStaged bool, latestState ParseState, line []byte) bool { // Author: Bill Rich func isAuthorLine(isStaged bool, latestState ParseState, line []byte) bool { - if isStaged || !(latestState == CommitLine || latestState == MergeLine) { + if isStaged || (latestState != CommitLine && latestState != MergeLine) { return false } if len(line) > 8 && bytes.Equal(line[:7], []byte("Author:")) { @@ -692,7 +689,7 @@ func isMessageStartLine(isStaged bool, latestState ParseState, line []byte) bool // Line that starts with 4 spaces func isMessageLine(isStaged bool, latestState ParseState, line []byte) bool { - if isStaged || !(latestState == MessageStartLine || latestState == MessageLine) { + if isStaged || (latestState != MessageStartLine && latestState != MessageLine) { return false } if len(line) > 4 && bytes.Equal(line[:4], []byte(" ")) { @@ -726,7 +723,7 @@ func isNotesStartLine(isStaged bool, latestState ParseState, line []byte) bool { // Line after NotesStartLine that starts with 4 spaces func isNotesLine(isStaged bool, latestState ParseState, line []byte) bool { - if isStaged || !(latestState == NotesStartLine || latestState == NotesLine) { + if isStaged || (latestState != NotesStartLine && latestState != NotesLine) { return false } if len(line) > 4 && bytes.Equal(line[:4], []byte(" ")) { @@ -748,15 +745,15 @@ func isNotesEndLine(isStaged bool, latestState ParseState, line []byte) bool { // diff --git a/internal/addrs/move_endpoint_module.go b/internal/addrs/move_endpoint_module.go func isDiffLine(isStaged bool, latestState ParseState, line []byte) bool { - if !(latestState == MessageStartLine || // Empty commit messages can go from MessageStart->Diff - latestState == MessageEndLine || - latestState == NotesEndLine || - latestState == BinaryFileLine || - latestState == ModeLine || - latestState == IndexLine || - latestState == HunkContentLine || - latestState == ParseFailure) { - if !(isStaged && latestState == Initial) { + if latestState != MessageStartLine && + latestState != MessageEndLine && + latestState != NotesEndLine && + latestState != BinaryFileLine && + latestState != ModeLine && + latestState != IndexLine && + latestState != HunkContentLine && + latestState != ParseFailure { + if !isStaged || latestState != Initial { return false } } @@ -774,7 +771,7 @@ func isDiffLine(isStaged bool, latestState ParseState, line []byte) bool { // rename to new.txt // deleted file mode 100644 func isModeLine(latestState ParseState, line []byte) bool { - if !(latestState == DiffLine || latestState == ModeLine) { + if latestState != DiffLine && latestState != ModeLine { return false } // This could probably be better written. @@ -793,7 +790,7 @@ func isModeLine(latestState ParseState, line []byte) bool { // index 1ed6fbee1..aea1e643a 100644 // index 00000000..e69de29b func isIndexLine(latestState ParseState, line []byte) bool { - if !(latestState == DiffLine || latestState == ModeLine) { + if latestState != DiffLine && latestState != ModeLine { return false } if len(line) > 6 && bytes.Equal(line[:6], []byte("index ")) { @@ -848,7 +845,7 @@ func pathFromBinaryLine(line []byte) (string, bool) { // --- a/internal/addrs/move_endpoint_module.go // --- /dev/null func isFromFileLine(latestState ParseState, line []byte) bool { - if !(latestState == IndexLine || latestState == ModeLine) { + if latestState != IndexLine && latestState != ModeLine { return false } if len(line) >= 6 && bytes.Equal(line[:4], []byte("--- ")) { @@ -906,7 +903,7 @@ func pathFromToFileLine(line []byte) (string, bool) { // @@ -298 +298 @@ func maxRetryErrorHandler(resp *http.Response, err error, numTries int) func isHunkLineNumberLine(latestState ParseState, line []byte) bool { - if !(latestState == ToFileLine || latestState == HunkContentLine) { + if latestState != ToFileLine && latestState != HunkContentLine { return false } if len(line) >= 8 && bytes.Equal(line[:2], []byte("@@")) { @@ -918,7 +915,7 @@ func isHunkLineNumberLine(latestState ParseState, line []byte) bool { // fmt.Println("ok") // (There's a space before `fmt` that gets removed by the formatter.) func isHunkContextLine(latestState ParseState, line []byte) bool { - if !(latestState == HunkLineNumberLine || latestState == HunkContentLine) { + if latestState != HunkLineNumberLine && latestState != HunkContentLine { return false } if len(line) >= 1 && bytes.Equal(line[:1], []byte(" ")) { @@ -929,7 +926,7 @@ func isHunkContextLine(latestState ParseState, line []byte) bool { // +fmt.Println("ok") func isHunkPlusLine(latestState ParseState, line []byte) bool { - if !(latestState == HunkLineNumberLine || latestState == HunkContentLine) { + if latestState != HunkLineNumberLine && latestState != HunkContentLine { return false } if len(line) >= 1 && bytes.Equal(line[:1], []byte("+")) { @@ -940,7 +937,7 @@ func isHunkPlusLine(latestState ParseState, line []byte) bool { // -fmt.Println("ok") func isHunkMinusLine(latestState ParseState, line []byte) bool { - if !(latestState == HunkLineNumberLine || latestState == HunkContentLine) { + if latestState != HunkLineNumberLine && latestState != HunkContentLine { return false } if len(line) >= 1 && bytes.Equal(line[:1], []byte("-")) { @@ -965,7 +962,7 @@ func isHunkNewlineWarningLine(latestState ParseState, line []byte) bool { // // commit 00920984e3435057f09cee5468850f7546dfa637 (tag: v3.42.0) func isHunkEmptyLine(latestState ParseState, line []byte) bool { - if !(latestState == HunkLineNumberLine || latestState == HunkContentLine) { + if latestState != HunkLineNumberLine && latestState != HunkContentLine { return false } // TODO: Can this also be `\n\r`? diff --git a/pkg/giturl/giturl.go b/pkg/giturl/giturl.go index ad8574bb0f7b..dbd9bc019031 100644 --- a/pkg/giturl/giturl.go +++ b/pkg/giturl/giturl.go @@ -219,9 +219,9 @@ var ( // UpdateLinkLineNumber updates the line number in a repository link. // Used post-link generation to refine reported issue locations within large scanned blocks. func UpdateLinkLineNumber(ctx context.Context, link string, newLine int64) string { - link = strings.Replace(link, "%", "%25", -1) - link = strings.Replace(link, "[", "%5B", -1) - link = strings.Replace(link, "]", "%5D", -1) + link = strings.ReplaceAll(link, "%", "%25") + link = strings.ReplaceAll(link, "[", "%5B") + link = strings.ReplaceAll(link, "]", "%5D") parsedURL, err := url.Parse(link) if err != nil { ctx.Logger().Error(err, "unable to parse link to update line number", "link", link) diff --git a/pkg/handlers/apk.go b/pkg/handlers/apk.go index 858161e53a95..8bc4d1acd1bd 100644 --- a/pkg/handlers/apk.go +++ b/pkg/handlers/apk.go @@ -241,10 +241,10 @@ func (h *apkHandler) processFile( if err != nil { return fmt.Errorf("failed to read file %s: %w", file.Name, err) } - defer f.Close() + defer func() { _ = f.Close() }() rdr := iobuf.NewBufferedReaderSeeker(f) - defer rdr.Close() + defer func() { _ = rdr.Close() }() var contentReader io.Reader // Decode the file based on its extension @@ -306,7 +306,7 @@ func parseResTable(zipReader *zip.Reader) (*apkparser.ResourceTable, error) { } resTable, err := apkparser.ParseResourceTable(rdr) - rdr.Close() + _ = rdr.Close() if err != nil { return nil, err } diff --git a/pkg/handlers/apk_test.go b/pkg/handlers/apk_test.go index b8ca00530a0e..d23dd64ec484 100644 --- a/pkg/handlers/apk_test.go +++ b/pkg/handlers/apk_test.go @@ -34,7 +34,7 @@ func TestAPKHandler(t *testing.T) { resp, err := http.Get(testCase.archiveURL) assert.NoError(t, err) assert.Equal(t, http.StatusOK, resp.StatusCode) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() handler := newAPKHandler() @@ -42,7 +42,7 @@ func TestAPKHandler(t *testing.T) { if err != nil { t.Errorf("error creating reusable reader: %s", err) } - defer newReader.Close() + defer func() { _ = newReader.Close() }() archiveChan := handler.HandleFile(context.Background(), newReader) @@ -76,7 +76,7 @@ func TestOpenInvalidAPK(t *testing.T) { rdr, err := newFileReader(ctx, io.NopCloser(reader)) assert.NoError(t, err) - defer rdr.Close() + defer func() { _ = rdr.Close() }() archiveChan := make(chan DataOrErr) @@ -91,7 +91,7 @@ func TestOpenValidZipInvalidAPK(t *testing.T) { resp, err := http.Get(validZipURL) assert.NoError(t, err) assert.Equal(t, http.StatusOK, resp.StatusCode) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() handler := newAPKHandler() @@ -100,7 +100,7 @@ func TestOpenValidZipInvalidAPK(t *testing.T) { t.Errorf("error creating reusable reader: %s", err) } assert.NoError(t, err) - defer newReader.Close() + defer func() { _ = newReader.Close() }() archiveChan := make(chan DataOrErr) ctx := context.AddLogger(context.Background()) diff --git a/pkg/handlers/ar_test.go b/pkg/handlers/ar_test.go index 2f908e4d7c64..64cb694318fe 100644 --- a/pkg/handlers/ar_test.go +++ b/pkg/handlers/ar_test.go @@ -13,14 +13,14 @@ import ( func TestHandleARFile(t *testing.T) { file, err := os.Open("testdata/test.deb") assert.Nil(t, err) - defer file.Close() + defer func() { _ = file.Close() }() ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) defer cancel() rdr, err := newFileReader(ctx, file) assert.NoError(t, err) - defer rdr.Close() + defer func() { _ = rdr.Close() }() handler := newARHandler() dataOrErrChan := handler.HandleFile(context.AddLogger(ctx), rdr) diff --git a/pkg/handlers/archive.go b/pkg/handlers/archive.go index c3bf11de7adc..374144ab5053 100644 --- a/pkg/handlers/archive.go +++ b/pkg/handlers/archive.go @@ -140,7 +140,7 @@ func (h *archiveHandler) openArchive( if err != nil { return fmt.Errorf("error opening decompressor with format: %s %w", reader.format.MediaType(), err) } - defer compReader.Close() + defer func() { _ = compReader.Close() }() rdr, err := newFileReader(ctx, compReader) if err != nil { @@ -154,7 +154,7 @@ func (h *archiveHandler) openArchive( err, ) } - defer rdr.Close() + defer func() { _ = rdr.Close() }() return h.openArchive(ctx, depth+1, rdr, dataOrErrChan) case archives.Extractor: @@ -211,7 +211,7 @@ func (h *archiveHandler) extractorHandler(dataOrErrChan chan DataOrErr) func(con if err != nil { return fmt.Errorf("error opening file %s: %w", file.Name(), err) } - defer f.Close() + defer func() { _ = f.Close() }() // Archiver v4 is in alpha and using an experimental version of // rardecode. There is a bug somewhere with rar decoder format 29 @@ -237,7 +237,7 @@ func (h *archiveHandler) extractorHandler(dataOrErrChan chan DataOrErr) func(con } return fmt.Errorf("error creating reader for file %s: %w", file.Name(), err) } - defer rdr.Close() + defer func() { _ = rdr.Close() }() h.metrics.incFilesProcessed() h.metrics.observeFileSize(fileSize) diff --git a/pkg/handlers/archive_test.go b/pkg/handlers/archive_test.go index 7b82b1ebaa8f..aee1cc583d71 100644 --- a/pkg/handlers/archive_test.go +++ b/pkg/handlers/archive_test.go @@ -81,7 +81,7 @@ func TestArchiveHandler(t *testing.T) { resp, err := http.Get(testCase.archiveURL) assert.NoError(t, err) assert.Equal(t, http.StatusOK, resp.StatusCode) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() handler := newArchiveHandler() @@ -89,7 +89,7 @@ func TestArchiveHandler(t *testing.T) { if err != nil { t.Errorf("error creating reusable reader: %s", err) } - defer newReader.Close() + defer func() { _ = newReader.Close() }() dataOrErrChan := handler.HandleFile(logContext.Background(), newReader) if testCase.expectErr { @@ -121,7 +121,7 @@ func TestOpenInvalidArchive(t *testing.T) { rdr, err := newFileReader(ctx, io.NopCloser(reader)) assert.NoError(t, err) - defer rdr.Close() + defer func() { _ = rdr.Close() }() dataOrErrChan := make(chan DataOrErr) diff --git a/pkg/handlers/default_test.go b/pkg/handlers/default_test.go index 9220e182aa56..37e5dc5c93b0 100644 --- a/pkg/handlers/default_test.go +++ b/pkg/handlers/default_test.go @@ -16,14 +16,14 @@ import ( func TestHandleNonArchiveFile(t *testing.T) { file, err := os.Open("testdata/nonarchive.txt") assert.Nil(t, err) - defer file.Close() + defer func() { _ = file.Close() }() ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) defer cancel() rdr, err := newFileReader(ctx, file) assert.NoError(t, err) - defer rdr.Close() + defer func() { _ = rdr.Close() }() handler := newDefaultHandler(defaultHandlerType) dataOrErrChan := handler.HandleFile(context.AddLogger(ctx), rdr) diff --git a/pkg/handlers/handlers_test.go b/pkg/handlers/handlers_test.go index 7d8218fc3dc4..a738622e6461 100644 --- a/pkg/handlers/handlers_test.go +++ b/pkg/handlers/handlers_test.go @@ -44,7 +44,7 @@ func TestHandleFile(t *testing.T) { assert.NoError(t, err) defer func() { if resp != nil && resp.Body != nil { - resp.Body.Close() + _ = resp.Body.Close() } }() @@ -58,7 +58,7 @@ func TestHandleHTTPJson(t *testing.T) { assert.NoError(t, err) defer func() { if resp != nil && resp.Body != nil { - resp.Body.Close() + _ = resp.Body.Close() } }() @@ -82,7 +82,7 @@ func TestHandleHTTPJsonZip(t *testing.T) { assert.NoError(t, err) defer func() { if resp != nil && resp.Body != nil { - resp.Body.Close() + _ = resp.Body.Close() } }() @@ -110,7 +110,7 @@ func BenchmarkHandleHTTPJsonZip(b *testing.B) { defer func() { if resp != nil && resp.Body != nil { - resp.Body.Close() + _ = resp.Body.Close() } }() @@ -134,7 +134,7 @@ func BenchmarkHandleHTTPJsonZip(b *testing.B) { func BenchmarkHandleFile(b *testing.B) { file, err := os.Open("testdata/test.tgz") assert.Nil(b, err) - defer file.Close() + defer func() { _ = file.Close() }() b.ReportAllocs() for i := 0; i < b.N; i++ { @@ -323,7 +323,7 @@ func TestHandleFileDOC(t *testing.T) { func BenchmarkHandleAR(b *testing.B) { file, err := os.Open("testdata/test.deb") assert.Nil(b, err) - defer file.Close() + defer func() { _ = file.Close() }() b.ReportAllocs() for i := 0; i < b.N; i++ { @@ -382,7 +382,7 @@ func TestExtractTarContentWithEmptyFile(t *testing.T) { func TestHandleTar(t *testing.T) { file, err := os.Open("testdata/test.tar") assert.Nil(t, err) - defer file.Close() + defer func() { _ = file.Close() }() chunkCh := make(chan *sources.Chunk, 1) go func() { @@ -402,7 +402,7 @@ func TestHandleTar(t *testing.T) { func BenchmarkHandleTar(b *testing.B) { file, err := os.Open("testdata/test.tar") assert.Nil(b, err) - defer file.Close() + defer func() { _ = file.Close() }() b.ReportAllocs() for i := 0; i < b.N; i++ { @@ -432,7 +432,7 @@ func TestHandleLargeHTTPJson(t *testing.T) { defer func() { if resp != nil && resp.Body != nil { - resp.Body.Close() + _ = resp.Body.Close() } }() @@ -455,10 +455,10 @@ func TestHandlePipe(t *testing.T) { r, w := io.Pipe() go func() { - defer w.Close() + defer func() { _ = w.Close() }() file, err := os.Open("testdata/test.tar") assert.NoError(t, err) - defer file.Close() + defer func() { _ = file.Close() }() _, err = io.Copy(w, file) assert.NoError(t, err) }() @@ -543,7 +543,7 @@ func TestHandleGitCatFile(t *testing.T) { } else { gitDir = setupTempGitRepoWithUnsupportedFile(t, tt.fileName, tt.fileSize) } - defer os.RemoveAll(gitDir) + defer func() { _ = os.RemoveAll(gitDir) }() cmd := exec.Command("git", "-C", gitDir, "rev-parse", "HEAD") hashBytes, err := cmd.Output() @@ -634,7 +634,7 @@ func setupTempGitRepoCommon(t *testing.T, fileName string, fileSize int, isUnsup if err != nil { t.Fatalf("Failed to create file: %v", err) } - defer f.Close() + defer func() { _ = f.Close() }() if isUnsupported { // Write ELF header for unsupported file. @@ -758,7 +758,7 @@ func TestHandleGitCatFileWithPipeError(t *testing.T) { simulatedError := errors.New("simulated error during newFileReader") gitDir := setupTempGitRepo(t, fileName, fileSize) - defer os.RemoveAll(gitDir) + defer func() { _ = os.RemoveAll(gitDir) }() commitHash := getGitCommitHash(t, gitDir) diff --git a/pkg/handlers/rpm_test.go b/pkg/handlers/rpm_test.go index ba4d5d622369..a48d8d83daac 100644 --- a/pkg/handlers/rpm_test.go +++ b/pkg/handlers/rpm_test.go @@ -13,14 +13,14 @@ import ( func TestHandleRPMFile(t *testing.T) { file, err := os.Open("testdata/test.rpm") assert.Nil(t, err) - defer file.Close() + defer func() { _ = file.Close() }() ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) defer cancel() rdr, err := newFileReader(ctx, file) assert.NoError(t, err) - defer rdr.Close() + defer func() { _ = rdr.Close() }() handler := newRPMHandler() dataOrErrChan := handler.HandleFile(context.AddLogger(ctx), rdr) diff --git a/pkg/iobuf/bufferedreaderseeker.go b/pkg/iobuf/bufferedreaderseeker.go index b42ff72b8d1b..4fbfbd886cf9 100644 --- a/pkg/iobuf/bufferedreaderseeker.go +++ b/pkg/iobuf/bufferedreaderseeker.go @@ -390,7 +390,7 @@ func (br *BufferedReadSeeker) Close() error { } if br.tempFile != nil { - br.tempFile.Close() + _ = br.tempFile.Close() return os.Remove(br.tempFileName) } return nil diff --git a/pkg/output/github_actions.go b/pkg/output/github_actions.go index 878a2de725d3..c83c7badfd72 100644 --- a/pkg/output/github_actions.go +++ b/pkg/output/github_actions.go @@ -18,10 +18,10 @@ type GitHubActionsPrinter struct{ mu sync.Mutex } func (p *GitHubActionsPrinter) Print(_ context.Context, r *detectors.ResultWithMetadata) error { out := gitHubActionsOutputFormat{ - DetectorType: r.Result.DetectorType.String(), + DetectorType: r.DetectorType.String(), DetectorDescription: r.DetectorDescription, DecoderType: r.DecoderType.String(), - Verified: r.Result.Verified, + Verified: r.Verified, } meta, err := structToMap(r.SourceMetadata.Data) @@ -61,7 +61,7 @@ func (p *GitHubActionsPrinter) Print(_ context.Context, r *detectors.ResultWithM dedupeCache[key] = struct{}{} name := "" - if nameValue, ok := r.Result.ExtraData["name"]; ok { + if nameValue, ok := r.ExtraData["name"]; ok { name = fmt.Sprintf(" (%s)", nameValue) } diff --git a/pkg/output/legacy_json.go b/pkg/output/legacy_json.go index 74683f4573f9..5f3cf3ff6ea1 100644 --- a/pkg/output/legacy_json.go +++ b/pkg/output/legacy_json.go @@ -85,7 +85,7 @@ func convertToLegacyJSON(r *detectors.ResultWithMetadata, repoPath string) (*Leg diff := GenerateDiff(commit, fileName) - foundString := string(r.Result.Raw) + foundString := string(r.Raw) // Add highlighting to the offending bit of string. printableDiff := strings.ReplaceAll(diff, foundString, fmt.Sprintf("\u001b[93m%s\u001b[0m", foundString)) @@ -99,7 +99,7 @@ func convertToLegacyJSON(r *detectors.ResultWithMetadata, repoPath string) (*Leg Diff: diff, Path: fileName, PrintDiff: printableDiff, - Reason: r.Result.DetectorType.String(), + Reason: r.DetectorType.String(), StringsFound: []string{foundString}, } return output, nil diff --git a/pkg/output/plain.go b/pkg/output/plain.go index 04a9e216df9a..08583c5c111e 100644 --- a/pkg/output/plain.go +++ b/pkg/output/plain.go @@ -30,16 +30,16 @@ type PlainPrinter struct{ mu sync.Mutex } func (p *PlainPrinter) Print(_ context.Context, r *detectors.ResultWithMetadata) error { out := outputFormat{ - DetectorType: r.Result.DetectorType.String(), + DetectorType: r.DetectorType.String(), DecoderType: r.DecoderType.String(), - Verified: r.Result.Verified, - VerificationError: r.Result.VerificationError(), + Verified: r.Verified, + VerificationError: r.VerificationError(), MetaData: r.SourceMetadata, - Raw: strings.TrimSpace(string(r.Result.Raw)), + Raw: strings.TrimSpace(string(r.Raw)), DetectorDescription: r.DetectorDescription, } - meta, err := structToMap(out.MetaData.Data) + meta, err := structToMap(out.Data) if err != nil { return fmt.Errorf("could not marshal result: %w", err) } @@ -49,41 +49,41 @@ func (p *PlainPrinter) Print(_ context.Context, r *detectors.ResultWithMetadata) defer p.mu.Unlock() if out.Verified { - boldGreenPrinter.Print("✅ Found verified result 🐷🔑\n") + _, _ = boldGreenPrinter.Print("✅ Found verified result 🐷🔑\n") } else { printer = whitePrinter - boldWhitePrinter.Print("Found unverified result 🐷🔑❓\n") + _, _ = boldWhitePrinter.Print("Found unverified result 🐷🔑❓\n") if out.VerificationError != nil { - yellowPrinter.Printf("Verification issue: %s\n", out.VerificationError) + _, _ = yellowPrinter.Printf("Verification issue: %s\n", out.VerificationError) } } if r.VerificationFromCache { - cyanPrinter.Print("(Verification info cached)\n") + _, _ = cyanPrinter.Print("(Verification info cached)\n") } - printer.Printf("Detector Type: %s\n", out.DetectorType) - printer.Printf("Decoder Type: %s\n", out.DecoderType) - printer.Printf("Raw result: %s\n", whitePrinter.Sprint(out.Raw)) + _, _ = printer.Printf("Detector Type: %s\n", out.DetectorType) + _, _ = printer.Printf("Decoder Type: %s\n", out.DecoderType) + _, _ = printer.Printf("Raw result: %s\n", whitePrinter.Sprint(out.Raw)) - for k, v := range r.Result.ExtraData { - printer.Printf( + for k, v := range r.ExtraData { + _, _ = printer.Printf( "%s: %v\n", cases.Title(language.AmericanEnglish).String(k), v) } - if r.Result.StructuredData != nil { - for idx, v := range r.Result.StructuredData.GithubSshKey { - printer.Printf("GithubSshKey %d User: %s\n", idx, v.User) + if r.StructuredData != nil { + for idx, v := range r.StructuredData.GithubSshKey { + _, _ = printer.Printf("GithubSshKey %d User: %s\n", idx, v.User) if v.PublicKeyFingerprint != "" { - printer.Printf("GithubSshKey %d Fingerprint: %s\n", idx, v.PublicKeyFingerprint) + _, _ = printer.Printf("GithubSshKey %d Fingerprint: %s\n", idx, v.PublicKeyFingerprint) } } - for idx, v := range r.Result.StructuredData.TlsPrivateKey { - printer.Printf("TlsPrivateKey %d Fingerprint: %s\n", idx, v.CertificateFingerprint) - printer.Printf("TlsPrivateKey %d Verification URL: %s\n", idx, v.VerificationUrl) - printer.Printf("TlsPrivateKey %d Expiration: %d\n", idx, v.ExpirationTimestamp) + for idx, v := range r.StructuredData.TlsPrivateKey { + _, _ = printer.Printf("TlsPrivateKey %d Fingerprint: %s\n", idx, v.CertificateFingerprint) + _, _ = printer.Printf("TlsPrivateKey %d Verification URL: %s\n", idx, v.VerificationUrl) + _, _ = printer.Printf("TlsPrivateKey %d Expiration: %d\n", idx, v.ExpirationTimestamp) } } @@ -98,12 +98,12 @@ func (p *PlainPrinter) Print(_ context.Context, r *detectors.ResultWithMetadata) } sort.Strings(aggregateDataKeys) for _, k := range aggregateDataKeys { - printer.Printf("%s: %v\n", cases.Title(language.AmericanEnglish).String(k), aggregateData[k]) + _, _ = printer.Printf("%s: %v\n", cases.Title(language.AmericanEnglish).String(k), aggregateData[k]) } // if analysis info is not nil, means the detector added key for analyzer and result is verified - if r.Result.SecretParts != nil && r.Result.Verified { - printer.Printf("Analyze: Run `trufflehog analyze` to analyze this key's permissions\n") + if r.SecretParts != nil && r.Verified { + _, _ = printer.Printf("Analyze: Run `trufflehog analyze` to analyze this key's permissions\n") } fmt.Println("") diff --git a/pkg/roundtripper/roundtripper.go b/pkg/roundtripper/roundtripper.go index d81b7a89a97b..acaec85b171e 100644 --- a/pkg/roundtripper/roundtripper.go +++ b/pkg/roundtripper/roundtripper.go @@ -73,7 +73,7 @@ func (r *RoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { ) if r.BasicAuthRoundTripper != nil { - req.SetBasicAuth(r.BasicAuthRoundTripper.username, r.BasicAuthRoundTripper.password) + req.SetBasicAuth(r.username, r.password) } authMethod := determineAuth(req) @@ -94,9 +94,9 @@ func (r *RoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { ) } - reason, shouldRetry, duration := r.RetryableRoundtripper.shouldRetryRequest(response, err) + reason, shouldRetry, duration := r.shouldRetryRequest(response, err) if shouldRetry { - if retries >= int(r.RetryableRoundtripper.maxRetries) { + if retries >= int(r.maxRetries) { r.logger.V(2).Info("max retries reached", "host", req.Host, "reason", reason, diff --git a/pkg/sanitizer/utf8.go b/pkg/sanitizer/utf8.go index 8ebe39834c93..7fe8b7957ad7 100644 --- a/pkg/sanitizer/utf8.go +++ b/pkg/sanitizer/utf8.go @@ -5,5 +5,5 @@ import ( ) func UTF8(in string) string { - return strings.Replace(strings.ToValidUTF8(in, "❗"), "\x00", "", -1) + return strings.ReplaceAll(strings.ToValidUTF8(in, "❗"), "\x00", "") } diff --git a/pkg/sources/chunker_test.go b/pkg/sources/chunker_test.go index ce14cd269ed2..e04fb4539336 100644 --- a/pkg/sources/chunker_test.go +++ b/pkg/sources/chunker_test.go @@ -159,7 +159,7 @@ type panicReader struct{} var _ io.Reader = (*panicReader)(nil) -func (_ panicReader) Read([]byte) (int, error) { +func (panicReader) Read([]byte) (int, error) { panic("panic for testing") } diff --git a/pkg/sources/docker/docker.go b/pkg/sources/docker/docker.go index 135bb10c40a1..ea376610ac95 100644 --- a/pkg/sources/docker/docker.go +++ b/pkg/sources/docker/docker.go @@ -382,7 +382,7 @@ func (s *Source) processLayer(ctx context.Context, layer v1.Layer, imgInfo image if err != nil { return err } - defer rc.Close() + defer func() { _ = rc.Close() }() // Configure parallel gzip decompression for better performance const ( @@ -394,7 +394,7 @@ func (s *Source) processLayer(ctx context.Context, layer v1.Layer, imgInfo image if err != nil { return err } - defer gzipReader.Close() + defer func() { _ = gzipReader.Close() }() // Layers are tar archives, so we read them as tar files tarReader := tar.NewReader(gzipReader) diff --git a/pkg/sources/docker/docker_test.go b/pkg/sources/docker/docker_test.go index b8cfb689472c..b3a89d07143e 100644 --- a/pkg/sources/docker/docker_test.go +++ b/pkg/sources/docker/docker_test.go @@ -267,7 +267,7 @@ func TestDockerImageScanFromLocalDaemon(t *testing.T) { return } - defer resp.Close() + defer func() { _ = resp.Close() }() // if we don't read the response, the image will not be available in the local Docker daemon _, err = io.ReadAll(resp) diff --git a/pkg/sources/elasticsearch/api.go b/pkg/sources/elasticsearch/api.go index 02a2480d8984..c75b283150f0 100644 --- a/pkg/sources/elasticsearch/api.go +++ b/pkg/sources/elasticsearch/api.go @@ -145,7 +145,7 @@ func makeElasticSearchRequest( return nil, err } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() rawData, err := io.ReadAll(res.Body) if err != nil { @@ -216,17 +216,17 @@ func fetchIndexDocumentCount( hits, ok := data["hits"].(map[string]any) if !ok { - return 0, errors.New("No hits in response") + return 0, errors.New("no hits in response") } total, ok := hits["total"].(map[string]any) if !ok { - return 0, errors.New("No total in hits") + return 0, errors.New("no total in hits") } count, ok := total["value"].(float64) if !ok { - return 0, errors.New("No value in total") + return 0, errors.New("no value in total") } return int(count), nil @@ -249,7 +249,7 @@ func createPITForSearch( pitID, ok := data["id"].(string) if !ok { - return "", errors.New("No id in response") + return "", errors.New("no id in response") } return pitID, nil @@ -321,7 +321,7 @@ func processSearchedDocuments( if !ok { apiErr, ok := searchResults["error"].(map[string]any) if ok { - return 0, fmt.Errorf("Error fetching search results: %v\n", apiErr) + return 0, fmt.Errorf("error fetching search results: %v", apiErr) } continue } diff --git a/pkg/sources/elasticsearch/elasticsearch_integration_test.go b/pkg/sources/elasticsearch/elasticsearch_integration_test.go index cc7b821d084f..4062f79c6fbf 100644 --- a/pkg/sources/elasticsearch/elasticsearch_integration_test.go +++ b/pkg/sources/elasticsearch/elasticsearch_integration_test.go @@ -86,7 +86,7 @@ func TestSource_ElasticAPI(t *testing.T) { if err != nil { t.Fatal(err) } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() t.Run( "Adding a document to a new index creates a single index", @@ -126,7 +126,7 @@ func TestSource_ElasticAPI(t *testing.T) { if err != nil { t.Fatal(err) } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() t.Run( "Indices have the correct document count", @@ -349,7 +349,7 @@ func TestSource_ElasticAPI(t *testing.T) { if err != nil { t.Fatal(err) } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() } docSearch := DocumentSearch{ diff --git a/pkg/sources/errors_test.go b/pkg/sources/errors_test.go index e7b9d3a035a3..a01ccaaa6a86 100644 --- a/pkg/sources/errors_test.go +++ b/pkg/sources/errors_test.go @@ -7,7 +7,7 @@ import ( "testing" ) -var testError = fmt.Errorf("simulated failure") +var errTest = fmt.Errorf("simulated failure") func TestNewScanErrors(t *testing.T) { testCases := []struct { @@ -86,7 +86,7 @@ func TestScanErrorsAdd(t *testing.T) { wg.Add(1) go func() { for j := 0; j < tc.wantErr/tc.concurrency; j++ { - se.Add(testError) + se.Add(errTest) } wg.Done() }() @@ -137,7 +137,7 @@ func TestScanErrorsCount(t *testing.T) { wg.Add(1) go func() { for j := 0; j < tc.wantErrCnt/tc.concurrency; j++ { - se.Add(testError) + se.Add(errTest) } wg.Done() }() @@ -153,8 +153,8 @@ func TestScanErrorsCount(t *testing.T) { func TestScanErrorsString(t *testing.T) { se := NewScanErrors() - se.Add(testError) - want := `["` + testError.Error() + `"]` + se.Add(errTest) + want := `["` + errTest.Error() + `"]` if got := fmt.Sprintf("%v", se); got != want { t.Errorf("got %q, want %q", got, want) } diff --git a/pkg/sources/filesystem/filesystem.go b/pkg/sources/filesystem/filesystem.go index 5aced6666eb0..e88c94a4c254 100644 --- a/pkg/sources/filesystem/filesystem.go +++ b/pkg/sources/filesystem/filesystem.go @@ -362,7 +362,7 @@ func (s *Source) scanFile(ctx trContext.Context, chunksChan chan *sources.Chunk, if err != nil { return fmt.Errorf("unable to open file: %w", err) } - defer inputFile.Close() + defer func() { _ = inputFile.Close() }() fileCtx.Logger().V(3).Info("scanning file") diff --git a/pkg/sources/filesystem/filesystem_test.go b/pkg/sources/filesystem/filesystem_test.go index 5a964d6714b6..ab77cbd010e2 100644 --- a/pkg/sources/filesystem/filesystem_test.go +++ b/pkg/sources/filesystem/filesystem_test.go @@ -132,7 +132,7 @@ func TestScanFile(t *testing.T) { func TestScanBinaryFile(t *testing.T) { tmpfile, err := os.CreateTemp("", "example.bin") require.NoError(t, err) - defer os.Remove(tmpfile.Name()) + defer func() { _ = os.Remove(tmpfile.Name()) }() // binary data that decodes to "TuffleHog" fileContents := []byte{0x54, 0x75, 0x66, 0x66, 0x6C, 0x65, 0x48, 0x6F, 0x67} @@ -171,7 +171,7 @@ func TestEnumerate(t *testing.T) { // Setup the connection to test enumeration. dir, err := os.MkdirTemp("", "trufflehog-test-enumerate") assert.NoError(t, err) - defer os.RemoveAll(dir) + defer func() { _ = os.RemoveAll(dir) }() units := []string{ "/one", "/two", "/three", @@ -184,14 +184,14 @@ func TestEnumerate(t *testing.T) { if i < 3 { f, err := os.Create(fullPath) assert.NoError(t, err) - f.Close() + _ = f.Close() } else { assert.NoError(t, os.MkdirAll(fullPath, 0755)) // Create a file in the directory for enumeration to find. f, err := os.CreateTemp(fullPath, "file") assert.NoError(t, err) units[i] = f.Name() - f.Close() + _ = f.Close() } } conn, err := anypb.New(&sourcespb.Filesystem{ @@ -309,7 +309,7 @@ func TestChunkUnitReporterErr(t *testing.T) { if err != nil { t.Fatal(err) } - defer os.Remove(tmpfile.Name()) + defer func() { _ = os.Remove(tmpfile.Name()) }() fileContents := []byte("TestChunkUnit") _, err = tmpfile.Write(fileContents) @@ -383,7 +383,7 @@ func TestScanSubDirFile(t *testing.T) { testDir := filepath.Join(os.TempDir(), "trufflehog-test") err := os.MkdirAll(testDir, 0755) require.NoError(t, err) - defer os.RemoveAll(testDir) + defer func() { _ = os.RemoveAll(testDir) }() // Create a subdirectory and file childDir := filepath.Join(testDir, "child") @@ -422,7 +422,7 @@ func TestSkipBinaries(t *testing.T) { // Create a temporary directory for testing tempDir, err := os.MkdirTemp("", "trufflehog_test") require.NoError(t, err) - defer os.RemoveAll(tempDir) + defer func() { _ = os.RemoveAll(tempDir) }() // Create a binary file (executable) binaryFile := filepath.Join(tempDir, "test.exe") diff --git a/pkg/sources/gcs/gcs.go b/pkg/sources/gcs/gcs.go index 413dde690dae..571c0ac7049b 100644 --- a/pkg/sources/gcs/gcs.go +++ b/pkg/sources/gcs/gcs.go @@ -99,7 +99,7 @@ func newPersistableCache(increment int, cache cache.Cache[string], p *sources.Pr func (c *persistableCache) Set(key string, val string) { c.Cache.Set(key, val) if ok, contents := c.shouldPersist(); ok { - c.Progress.EncodedResumeInfo = contents + c.EncodedResumeInfo = contents } } @@ -261,7 +261,7 @@ func (s *Source) Chunks(ctx context.Context, chunksChan chan *sources.Chunk, _ . return fmt.Errorf("error listing objects: %w", err) } s.chunksCh = chunksChan - s.Progress.Message = "starting to process objects..." + s.Message = "starting to process objects..." var wg sync.WaitGroup for obj := range objectCh { @@ -295,8 +295,8 @@ func (s *Source) Chunks(ctx context.Context, chunksChan chan *sources.Chunk, _ . func (s *Source) setupCache(ctx context.Context) *persistableCache { var c cache.Cache[string] - if s.Progress.EncodedResumeInfo != "" { - keys := strings.Split(s.Progress.EncodedResumeInfo, ",") + if s.EncodedResumeInfo != "" { + keys := strings.Split(s.EncodedResumeInfo, ",") entries := make([]simple.CacheEntry[string], len(keys)) for i, val := range keys { entries[i] = simple.CacheEntry[string]{Key: val, Value: val} @@ -321,14 +321,14 @@ func (s *Source) setProgress(ctx context.Context, md5, objName string, cache cac s.SectionsCompleted++ cache.Set(md5, md5) - s.Progress.SectionsRemaining = int32(s.stats.numObjects) - s.Progress.PercentComplete = int64(float64(s.SectionsCompleted) / float64(s.stats.numObjects) * 100) + s.SectionsRemaining = int32(s.stats.numObjects) + s.PercentComplete = int64(float64(s.SectionsCompleted) / float64(s.stats.numObjects) * 100) } func (s *Source) completeProgress(ctx context.Context) { msg := fmt.Sprintf("GCS source finished processing %d objects", s.stats.numObjects) ctx.Logger().Info(msg) - s.Progress.Message = msg + s.Message = msg } func (s *Source) processObject(ctx context.Context, o object) error { diff --git a/pkg/sources/gcs/gcs_test.go b/pkg/sources/gcs/gcs_test.go index 9cde72ffe444..7d3dc65cb801 100644 --- a/pkg/sources/gcs/gcs_test.go +++ b/pkg/sources/gcs/gcs_test.go @@ -400,14 +400,14 @@ func TestSourceChunks_ProgressSet(t *testing.T) { // Test that the resume progress is set. var progress strings.Builder for i := range got { - progress.WriteString(fmt.Sprintf("md5hash%d", i)) + fmt.Fprintf(&progress, "md5hash%d", i) // Add a comma if not the last element. if i != len(got)-1 { progress.WriteString(",") } } - encodeResume := strings.Split(source.Progress.EncodedResumeInfo, ",") + encodeResume := strings.Split(source.EncodedResumeInfo, ",") sort.Slice(encodeResume, func(i, j int) bool { numI, _ := strconv.Atoi(strings.TrimPrefix(encodeResume[i], "md5hash")) numJ, _ := strconv.Atoi(strings.TrimPrefix(encodeResume[j], "md5hash")) @@ -415,9 +415,9 @@ func TestSourceChunks_ProgressSet(t *testing.T) { }) assert.Equal(t, progress.String(), strings.Join(encodeResume, ",")) - assert.Equal(t, int32(defaultCachePersistIncrement), source.Progress.SectionsCompleted) - assert.Equal(t, int64(100), source.Progress.PercentComplete) - assert.Equal(t, fmt.Sprintf("GCS source finished processing %d objects", defaultCachePersistIncrement), source.Progress.Message) + assert.Equal(t, int32(defaultCachePersistIncrement), source.SectionsCompleted) + assert.Equal(t, int64(100), source.PercentComplete) + assert.Equal(t, fmt.Sprintf("GCS source finished processing %d objects", defaultCachePersistIncrement), source.Message) } func TestSource_CachePersistence(t *testing.T) { @@ -457,8 +457,8 @@ func TestSource_CachePersistence(t *testing.T) { // Test that the resume progress is empty. // The cache should not have been persisted. - assert.Equal(t, "", source.Progress.EncodedResumeInfo) - assert.Equal(t, int32(wantObjCnt), source.Progress.SectionsCompleted) - assert.Equal(t, int64(100), source.Progress.PercentComplete) - assert.Equal(t, fmt.Sprintf("GCS source finished processing %d objects", wantObjCnt), source.Progress.Message) + assert.Equal(t, "", source.EncodedResumeInfo) + assert.Equal(t, int32(wantObjCnt), source.SectionsCompleted) + assert.Equal(t, int64(100), source.PercentComplete) + assert.Equal(t, fmt.Sprintf("GCS source finished processing %d objects", wantObjCnt), source.Message) } diff --git a/pkg/sources/git/git.go b/pkg/sources/git/git.go index 57f3498961f6..53489b2e08ab 100644 --- a/pkg/sources/git/git.go +++ b/pkg/sources/git/git.go @@ -319,7 +319,7 @@ func (s *Source) scanRepo(ctx context.Context, repoURI string, reporter sources. // if legacy JSON is enabled, don't remove the directory because we need it for outputting legacy JSON. if !s.conn.GetPrintLegacyJson() { if strings.HasPrefix(path, filepath.Join(os.TempDir(), "trufflehog")) || (!s.conn.GetNoCleanup() && s.conn.GetClonePath() != "") { - defer os.RemoveAll(path) + defer func() { _ = os.RemoveAll(path) }() } } @@ -373,7 +373,7 @@ func (s *Source) scanDir(ctx context.Context, gitDir string, reporter sources.Ch // if legacy JSON is enabled, don't remove the directory because we need it for outputting legacy JSON. if !s.conn.GetPrintLegacyJson() { if strings.HasPrefix(gitDir, filepath.Join(os.TempDir(), "trufflehog")) || (!s.conn.GetNoCleanup() && s.conn.GetClonePath() != "") { - defer os.RemoveAll(gitDir) + defer func() { _ = os.RemoveAll(gitDir) }() } } @@ -404,7 +404,7 @@ func RepoFromPath(path string) (*git.Repository, error) { func CleanOnError(err *error, path string) { if *err != nil { - os.RemoveAll(path) + _ = os.RemoveAll(path) } } @@ -863,7 +863,7 @@ func (s *Git) ScanCommits(ctx context.Context, repo *git.Repository, path string ) return nil } - defer reader.Close() + defer func() { _ = reader.Close() }() data := make([]byte, d.Len()) if _, err := io.ReadFull(reader, data); err != nil { @@ -898,7 +898,7 @@ func (s *Git) gitChunk(ctx context.Context, diff *gitparse.Diff, fileName, email ctx.Logger().Error(err, "error creating reader for chunk", "filename", fileName, "commit", hash, "file", diff.PathB) return } - defer reader.Close() + defer func() { _ = reader.Close() }() originalChunk := bufio.NewScanner(reader) newChunkBuffer := bytes.Buffer{} @@ -1115,7 +1115,7 @@ func (s *Git) ScanStaged(ctx context.Context, repo *git.Repository, path string, logger.Error(err, "error creating reader for staged") return nil } - defer reader.Close() + defer func() { _ = reader.Close() }() data := make([]byte, d.Len()) if _, err := reader.Read(data); err != nil { diff --git a/pkg/sources/git/git_test.go b/pkg/sources/git/git_test.go index f419eee5e0fd..7b8ccf3575fe 100644 --- a/pkg/sources/git/git_test.go +++ b/pkg/sources/git/git_test.go @@ -986,7 +986,7 @@ func TestPrepareRepoWithNormalization(t *testing.T) { } if path != repoPath && path != "" { - os.RemoveAll(path) + _ = os.RemoveAll(path) } }) } @@ -1028,7 +1028,7 @@ func TestPrepareRepoWithNormalization(t *testing.T) { } if path != repoPath && path != "" { - os.RemoveAll(path) + _ = os.RemoveAll(path) } }) } @@ -1104,7 +1104,7 @@ func TestPrepareRepoWithNormalizationBare(t *testing.T) { } if path != bareRepoPath && path != "" { - os.RemoveAll(path) + _ = os.RemoveAll(path) } }) } @@ -1158,7 +1158,7 @@ func TestPrepareRepoWithNormalizationBare(t *testing.T) { } if path != bareRepoPath && path != "" { - os.RemoveAll(path) + _ = os.RemoveAll(path) } }) } diff --git a/pkg/sources/github/github.go b/pkg/sources/github/github.go index 4106e97e2d08..51d70da8bdcf 100644 --- a/pkg/sources/github/github.go +++ b/pkg/sources/github/github.go @@ -761,7 +761,7 @@ func (s *Source) cloneAndScanRepo(ctx context.Context, repoURL string, repoInfo // if legacy JSON is enabled, don't remove the directory because we need it for outputting legacy JSON. if !s.conn.GetPrintLegacyJson() { if strings.HasPrefix(path, filepath.Join(os.TempDir(), "trufflehog")) || (!s.conn.NoCleanup && s.conn.GetClonePath() != "") { - defer os.RemoveAll(path) + defer func() { _ = os.RemoveAll(path) }() } } @@ -1355,7 +1355,7 @@ func (s *Source) processIssues(ctx context.Context, repoInfo repoInfo, reporter return err } - bodyTextsOpts.ListOptions.Page++ + bodyTextsOpts.Page++ if len(issues) < defaultPagination { break @@ -1423,7 +1423,7 @@ func (s *Source) processIssueComments(ctx context.Context, repoInfo repoInfo, re return err } - issueOpts.ListOptions.Page++ + issueOpts.Page++ if len(issueComments) < defaultPagination { break } @@ -1491,7 +1491,7 @@ func (s *Source) processPRs(ctx context.Context, repoInfo repoInfo, reporter sou return err } - prOpts.ListOptions.Page++ + prOpts.Page++ if len(prs) < defaultPagination { break @@ -1523,7 +1523,7 @@ func (s *Source) processPRComments(ctx context.Context, repoInfo repoInfo, repor return err } - prOpts.ListOptions.Page++ + prOpts.Page++ if len(prComments) < defaultPagination { break @@ -1659,7 +1659,7 @@ func (s *Source) scanTarget(ctx context.Context, target sources.ChunkingTarget, // As of this writing, if the returned readCloser is not nil, it's just the Body of the returned github.Response, so // there's no need to independently close it. if resp != nil && resp.Body != nil { - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } if err != nil { return fmt.Errorf("could not download file for scan: %w", err) @@ -1676,7 +1676,7 @@ func (s *Source) scanCommitMetadata(ctx context.Context, owner, repo string, met // fetch the commit commit, resp, err := s.connector.APIClient().Repositories.GetCommit(ctx, owner, repo, meta.GetCommit(), nil) if resp != nil && resp.Body != nil { - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } if err != nil { return fmt.Errorf("could not fetch commit for metadata scan: %w", err) diff --git a/pkg/sources/github_experimental/object_discovery.go b/pkg/sources/github_experimental/object_discovery.go index a09d8415e00e..991ec46a6680 100644 --- a/pkg/sources/github_experimental/object_discovery.go +++ b/pkg/sources/github_experimental/object_discovery.go @@ -209,7 +209,7 @@ func writeCommitsToDisk(commits []string, commitsType, folder string) error { if err != nil { return err } - defer file.Close() + defer func() { _ = file.Close() }() for _, commit := range commits { if _, err := file.WriteString(commit + "\n"); err != nil { @@ -413,7 +413,7 @@ func checkHashes(ctx context.Context, client *github.Client, owner, repo string, if err != nil { return nil, fmt.Errorf("python request error: %w", err) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() body, err := io.ReadAll(resp.Body) if err != nil { @@ -564,7 +564,7 @@ func (s *Source) EnumerateAndScanAllObjects(ctx context.Context, chunksChan chan return fmt.Errorf("failed to clone the repository: %w", err) } - defer os.RemoveAll(path) + defer func() { _ = os.RemoveAll(path) }() // count total valid hashes validHashes, err := getExistingHashes(path) diff --git a/pkg/sources/gitlab/gitlab.go b/pkg/sources/gitlab/gitlab.go index c13cda6f8d77..733792a99f60 100644 --- a/pkg/sources/gitlab/gitlab.go +++ b/pkg/sources/gitlab/gitlab.go @@ -977,7 +977,7 @@ func (s *Source) scanRepos(ctx context.Context, chunksChan chan *sources.Chunk) // if legacy JSON is enabled, don't remove the directory because we need it for outputting legacy JSON. if !s.printLegacyJSON { if strings.HasPrefix(path, filepath.Join(os.TempDir(), "trufflehog")) || (!s.noCleanup && s.clonePath != "") { - defer os.RemoveAll(path) + defer func() { _ = os.RemoveAll(path) }() } } @@ -1180,7 +1180,7 @@ func (s *Source) ChunkUnit(ctx context.Context, unit sources.SourceUnit, reporte // if legacy JSON is enabled, don't remove the directory because we need it for outputting legacy JSON. if !s.printLegacyJSON { if strings.HasPrefix(path, filepath.Join(os.TempDir(), "trufflehog")) || (!s.noCleanup && s.clonePath != "") { - defer os.RemoveAll(path) + defer func() { _ = os.RemoveAll(path) }() } } diff --git a/pkg/sources/huggingface/client.go b/pkg/sources/huggingface/client.go index d236265803b4..e2f10522fa6a 100644 --- a/pkg/sources/huggingface/client.go +++ b/pkg/sources/huggingface/client.go @@ -157,7 +157,7 @@ func (c *HFClient) get(ctx context.Context, url string, target interface{}) erro return errors.New("access to this repo is restricted and you are not in the authorized list. Visit the repository to ask for access") } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() return json.NewDecoder(resp.Body).Decode(target) } diff --git a/pkg/sources/huggingface/huggingface.go b/pkg/sources/huggingface/huggingface.go index 133510020eab..57d6a1a0e0a2 100644 --- a/pkg/sources/huggingface/huggingface.go +++ b/pkg/sources/huggingface/huggingface.go @@ -599,7 +599,7 @@ func (s *Source) cloneAndScanRepo(ctx context.Context, repoURL string, repoInfo if err != nil { return 0, err } - defer os.RemoveAll(path) + defer func() { _ = os.RemoveAll(path) }() var logger logr.Logger logger.V(2).Info("scanning %s", repoInfo.resourceType) diff --git a/pkg/sources/jenkins/jenkins.go b/pkg/sources/jenkins/jenkins.go index e51805555d24..22c5f4e45cba 100644 --- a/pkg/sources/jenkins/jenkins.go +++ b/pkg/sources/jenkins/jenkins.go @@ -250,7 +250,7 @@ func (s *Source) GetJenkinsObjectsForPath(ctx context.Context, absolutePath stri if err != nil { return res, errors.WrapPrefix(err, "Failed to do get jenkins jobs request", 0) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode != http.StatusOK { return res, errors.New(fmt.Sprintf("Received non-200 status from get jenkins jobs request: %d", resp.StatusCode)) @@ -297,7 +297,7 @@ func (s *Source) GetJenkinsBuilds(ctx context.Context, jobAbsolutePath string) ( if err != nil { return builds, errors.WrapPrefix(err, "Failed to do get jenkins builds request", 0) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode != http.StatusOK { return builds, errors.New(fmt.Sprintf("Received non-200 status from get jenkins builds request: %d", resp.StatusCode)) @@ -404,7 +404,7 @@ func (s *Source) chunkBuild( if err != nil { return fmt.Errorf("could not retrieve build log from %q: %w", buildLogURL.String(), err) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode >= 400 { return fmt.Errorf("got unexpected HTTP status code %v when trying to retrieve build log from %q", diff --git a/pkg/sources/jenkins/jenkins_test.go b/pkg/sources/jenkins/jenkins_test.go index 90461805e584..3598df30caf7 100644 --- a/pkg/sources/jenkins/jenkins_test.go +++ b/pkg/sources/jenkins/jenkins_test.go @@ -58,10 +58,10 @@ func createMockJenkinsServer(jobName string, buildNumber int, logContent string) response := fmt.Sprintf( `{"jobs":[{"_class":"org.jenkinsci.plugins.workflow.job.WorkflowJob",`+ `"name":"%s","url":"%s/job/%s/"}]}`, jobName, server.URL, jobName) - fmt.Fprint(w, response) + _, _ = fmt.Fprint(w, response) } else { w.Header().Set("Content-Type", "application/json") - fmt.Fprint(w, `{"jobs":[]}`) + _, _ = fmt.Fprint(w, `{"jobs":[]}`) } }) @@ -71,10 +71,10 @@ func createMockJenkinsServer(jobName string, buildNumber int, logContent string) w.Header().Set("Content-Type", "application/json") response := fmt.Sprintf( `{"builds":[{"number":%d,"url":"%s/job/%s/%d/"}]}`, buildNumber, server.URL, jobName, buildNumber) - fmt.Fprint(w, response) + _, _ = fmt.Fprint(w, response) } else { w.Header().Set("Content-Type", "application/json") - fmt.Fprint(w, `{"builds":[]}`) + _, _ = fmt.Fprint(w, `{"builds":[]}`) } }) @@ -82,7 +82,7 @@ func createMockJenkinsServer(jobName string, buildNumber int, logContent string) // This is where the test data payload is served to verify chunking behavior. mux.HandleFunc(fmt.Sprintf("/job/%s/%d/consoleText", jobName, buildNumber), func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/plain") - fmt.Fprint(w, logContent) + _, _ = fmt.Fprint(w, logContent) }) return server @@ -224,7 +224,7 @@ func TestJenkinsChunkBuildDirect(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if strings.HasSuffix(r.URL.Path, "/consoleText") { w.Header().Set("Content-Type", "text/plain") - fmt.Fprint(w, largeLogContent) + _, _ = fmt.Fprint(w, largeLogContent) } else { http.NotFound(w, r) } diff --git a/pkg/sources/json_enumerator/json_enumerator.go b/pkg/sources/json_enumerator/json_enumerator.go index a82cea96d131..991d9fb529ed 100644 --- a/pkg/sources/json_enumerator/json_enumerator.go +++ b/pkg/sources/json_enumerator/json_enumerator.go @@ -198,7 +198,7 @@ func (s *Source) chunkJSONEnumerator( if err != nil { return fmt.Errorf("unable to open file: %w", err) } - defer enumeratorFile.Close() + defer func() { _ = enumeratorFile.Close() }() return s.chunkJSONEnumeratorReader(ctx, enumeratorFile, chunksChan) } diff --git a/pkg/sources/postman/postman.go b/pkg/sources/postman/postman.go index b6e6140afe7c..c0a7fccc19ae 100644 --- a/pkg/sources/postman/postman.go +++ b/pkg/sources/postman/postman.go @@ -430,7 +430,7 @@ func (s *Source) scanItem(ctx context.Context, chunksChan chan *sources.Chunk, c metadata.FolderID = item.Uid // check if there are any requests in the folder if item.Request.Method != "" { - metadata.FolderName = strings.Replace(metadata.FolderName, (" > " + item.Name), "", -1) + metadata.FolderName = strings.ReplaceAll(metadata.FolderName, (" > " + item.Name), "") metadata.FolderID = parentItemId if metadata.FolderID == "" { metadata.FolderName = "" @@ -470,7 +470,7 @@ func (s *Source) scanEvent(ctx context.Context, chunksChan chan *sources.Chunk, // Prep direct links. Ignore updating link if it's a local JSON file if !metadata.fromLocal { - metadata.Link = LINK_BASE_URL + (strings.Replace(metadata.Type, " > event", "", -1)) + "/" + metadata.FullID + metadata.Link = LINK_BASE_URL + (strings.ReplaceAll(metadata.Type, " > event", "")) + "/" + metadata.FullID if event.Listen == "prerequest" { metadata.Link += "?tab=pre-request-scripts" } else { @@ -817,13 +817,13 @@ func unpackWorkspace(workspacePath string) (Workspace, error) { if err != nil { return workspace, err } - defer r.Close() + defer func() { _ = r.Close() }() for _, file := range r.File { rc, err := file.Open() if err != nil { return workspace, err } - defer rc.Close() + defer func() { _ = rc.Close() }() contents, err := io.ReadAll(rc) if err != nil { return workspace, err diff --git a/pkg/sources/postman/postman_client.go b/pkg/sources/postman/postman_client.go index 6ecb9f44067f..8379e8c56891 100644 --- a/pkg/sources/postman/postman_client.go +++ b/pkg/sources/postman/postman_client.go @@ -283,7 +283,7 @@ func (c *Client) getPostmanResponseBodyBytes(ctx trContext.Context, urlString st } return nil, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() c.Metrics.apiRequests.WithLabelValues(urlString).Inc() diff --git a/pkg/sources/s3/s3.go b/pkg/sources/s3/s3.go index 8b0939f2045f..7dd27fb5bef4 100644 --- a/pkg/sources/s3/s3.go +++ b/pkg/sources/s3/s3.go @@ -326,7 +326,7 @@ func (s *Source) scanBuckets( bucketIdx, len(bucketsToScan), fmt.Sprintf("Bucket: %s", bucket), - s.Progress.EncodedResumeInfo, + s.EncodedResumeInfo, ) var startAfter *string @@ -554,7 +554,7 @@ func (s *Source) pageChunker( // It's uncertain if the body will be nil in such cases, // but we'll close it if it's not. if res != nil && res.Body != nil { - res.Body.Close() + _ = res.Body.Close() } nErr, ok := state.errorCount.Load(prefix) @@ -573,7 +573,7 @@ func (s *Source) pageChunker( } return nil } - defer res.Body.Close() + defer func() { _ = res.Body.Close() }() email := "Unknown" if obj.Owner != nil { @@ -748,7 +748,7 @@ func (s *Source) ChunkUnit(ctx context.Context, unit sources.SourceUnit, reporte checkpointer := NewCheckpointer(ctx, &s.Progress, true) var startAfterPtr *string - startAfter := s.Progress.GetEncodedResumeInfoFor(unitID) + startAfter := s.GetEncodedResumeInfoFor(unitID) if startAfter != "" { ctx.Logger().V(3).Info( "Resuming unit scan", @@ -757,7 +757,7 @@ func (s *Source) ChunkUnit(ctx context.Context, unit sources.SourceUnit, reporte ) startAfterPtr = &startAfter } - defer s.Progress.ClearEncodedResumeInfoFor(unitID) + defer s.ClearEncodedResumeInfoFor(unitID) s.scanBucket(ctx, defaultClient, s3unit.Role, s3unit.Bucket, reporter, startAfterPtr, checkpointer) return nil } diff --git a/pkg/sources/source_manager.go b/pkg/sources/source_manager.go index 562a93947762..5b5078b2bdd6 100644 --- a/pkg/sources/source_manager.go +++ b/pkg/sources/source_manager.go @@ -408,7 +408,7 @@ func (s *SourceManager) enumerate(ctx context.Context, source Source, report *Jo ctx.Logger().Info("running source", "with_units", true) return s.enumerateWithUnits(ctx, enumChunker, report, reporter) } - return fmt.Errorf("Enumeration not supported or configured for source: %s", source.Type().String()) + return fmt.Errorf("enumeration not supported or configured for source: %s", source.Type().String()) } // scan runs a scan against a single SourceUnit as its only job. This method diff --git a/pkg/sources/syslog/syslog.go b/pkg/sources/syslog/syslog.go index dc1a1af6c446..6e8bf1905eb9 100644 --- a/pkg/sources/syslog/syslog.go +++ b/pkg/sources/syslog/syslog.go @@ -83,13 +83,13 @@ func (s *Source) Validate(ctx context.Context) []error { if err != nil { errs = append(errs, fmt.Errorf("error listening on tcp socket: %s", err)) } - srv.Close() + _ = srv.Close() case "udp": srv, err := net.ListenPacket(s.conn.Protocol, s.conn.ListenAddress) if err != nil { errs = append(errs, fmt.Errorf("error listening on udp socket: %s", err)) } - srv.Close() + _ = srv.Close() } } if s.conn.Protocol != "tcp" && s.conn.Protocol != "udp" { @@ -198,7 +198,7 @@ func (s *Source) Chunks(ctx context.Context, chunksChan chan *sources.Chunk, _ . if err != nil { return errors.WrapPrefix(err, "error creating TLS listener", 0) } - defer lis.Close() + defer func() { _ = lis.Close() }() return s.acceptTCPConnections(ctx, lis, chunksChan) case s.conn.Protocol == "tcp": @@ -206,7 +206,7 @@ func (s *Source) Chunks(ctx context.Context, chunksChan chan *sources.Chunk, _ . if err != nil { return errors.WrapPrefix(err, "error creating TCP listener", 0) } - defer lis.Close() + defer func() { _ = lis.Close() }() return s.acceptTCPConnections(ctx, lis, chunksChan) case s.conn.Protocol == "udp": @@ -218,7 +218,7 @@ func (s *Source) Chunks(ctx context.Context, chunksChan chan *sources.Chunk, _ . if err != nil { return errors.WrapPrefix(err, "could not set UDP deadline", 0) } - defer lis.Close() + defer func() { _ = lis.Close() }() return s.acceptUDPConnections(ctx, lis, chunksChan) default: diff --git a/pkg/sources/test_helpers.go b/pkg/sources/test_helpers.go index 25f59af8ae09..e1df37480957 100644 --- a/pkg/sources/test_helpers.go +++ b/pkg/sources/test_helpers.go @@ -8,7 +8,7 @@ import ( type ChunkFunc func(chunk *Chunk) error -var MatchError = errors.New("chunk doesn't match") +var errMatch = errors.New("chunk doesn't match") func HandleTestChannel(chunksCh chan *Chunk, cf ChunkFunc) error { for { @@ -16,7 +16,7 @@ func HandleTestChannel(chunksCh chan *Chunk, cf ChunkFunc) error { case gotChunk := <-chunksCh: err := cf(gotChunk) if err != nil { - if errors.Is(err, MatchError) { + if errors.Is(err, errMatch) { continue } return err diff --git a/pkg/tui/common/style.go b/pkg/tui/common/style.go index 2003869add3e..3260eebbec69 100644 --- a/pkg/tui/common/style.go +++ b/pkg/tui/common/style.go @@ -18,7 +18,7 @@ func StyleConfig() gansi.StyleConfig { s.H1.Prefix = "# " s.H1.Suffix = "" s.H1.Color = strptr("39") - s.Document.StylePrimitive.Color = noColor + s.Document.Color = noColor s.CodeBlock.Chroma.Text.Color = noColor s.CodeBlock.Chroma.Name.Color = noColor // This fixes an issue with the default style config. For example diff --git a/pkg/tui/components/selector/selector.go b/pkg/tui/components/selector/selector.go index 3b1b2ebb08e0..d1c908c978d2 100644 --- a/pkg/tui/components/selector/selector.go +++ b/pkg/tui/components/selector/selector.go @@ -50,22 +50,22 @@ func New(common common.Common, items []IdentifiableItem, delegate ItemDelegate) // PerPage returns the number of items per page. func (s *Selector) PerPage() int { - return s.Model.Paginator.PerPage + return s.Paginator.PerPage } // SetPage sets the current page. func (s *Selector) SetPage(page int) { - s.Model.Paginator.Page = page + s.Paginator.Page = page } // Page returns the current page. func (s *Selector) Page() int { - return s.Model.Paginator.Page + return s.Paginator.Page } // TotalPages returns the total number of pages. func (s *Selector) TotalPages() int { - return s.Model.Paginator.TotalPages + return s.Paginator.TotalPages } // Select selects the item at the given index. @@ -138,7 +138,7 @@ func (s *Selector) Update(msg tea.Msg) (tea.Model, tea.Cmd) { cmds := make([]tea.Cmd, 0) switch msg := msg.(type) { case tea.KeyMsg: - filterState := s.Model.FilterState() + filterState := s.FilterState() switch { case key.Matches(msg, s.common.KeyMap.Help): if filterState == list.Filtering { @@ -158,7 +158,7 @@ func (s *Selector) Update(msg tea.Msg) (tea.Model, tea.Cmd) { cmds = append(cmds, cmd) } // Track filter state and update active item when filter state changes. - filterState := s.Model.FilterState() + filterState := s.FilterState() if s.filterState != filterState { cmds = append(cmds, s.activeFilterCmd) } @@ -182,7 +182,7 @@ func (s *Selector) SelectItem() tea.Msg { } func (s *Selector) selectCmd() tea.Msg { - item := s.Model.SelectedItem() + item := s.SelectedItem() i, ok := item.(IdentifiableItem) if !ok { return SelectMsg{} @@ -191,7 +191,7 @@ func (s *Selector) selectCmd() tea.Msg { } func (s *Selector) activeCmd() tea.Msg { - item := s.Model.SelectedItem() + item := s.SelectedItem() i, ok := item.(IdentifiableItem) if !ok { return ActiveMsg{} @@ -203,7 +203,7 @@ func (s *Selector) activeFilterCmd() tea.Msg { // Here we use VisibleItems because when list.FilterMatchesMsg is sent, // VisibleItems is the only way to get the list of filtered items. The list // bubble should export something like list.FilterMatchesMsg.Items(). - items := s.Model.VisibleItems() + items := s.VisibleItems() if len(items) == 0 { return nil } diff --git a/pkg/tui/components/viewport/viewport.go b/pkg/tui/components/viewport/viewport.go index 77fa618285b7..df95cb10522f 100644 --- a/pkg/tui/components/viewport/viewport.go +++ b/pkg/tui/components/viewport/viewport.go @@ -25,8 +25,8 @@ func New(c common.Common) *Viewport { // SetSize implements common.Component. func (v *Viewport) SetSize(width, height int) { v.common.SetSize(width, height) - v.Model.Width = width - v.Model.Height = height + v.Width = width + v.Height = height } // Init implements tea.Model. diff --git a/pkg/tui/pages/analyze_form/analyze_form.go b/pkg/tui/pages/analyze_form/analyze_form.go index 6448a3f974b7..177db9c93468 100644 --- a/pkg/tui/pages/analyze_form/analyze_form.go +++ b/pkg/tui/pages/analyze_form/analyze_form.go @@ -188,7 +188,7 @@ func (ui *AnalyzeForm) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return ui, nil case tea.KeyMsg: switch { - case key.Matches(msg, ui.Common.KeyMap.Back): + case key.Matches(msg, ui.KeyMap.Back): return nil, tea.Quit } } diff --git a/pkg/tui/pages/analyze_keys/analyze_keys.go b/pkg/tui/pages/analyze_keys/analyze_keys.go index d85bc6e85602..082a630f711e 100644 --- a/pkg/tui/pages/analyze_keys/analyze_keys.go +++ b/pkg/tui/pages/analyze_keys/analyze_keys.go @@ -62,9 +62,9 @@ func (ui *AnalyzeKeyPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) { ui.list.SetSize(msg.Width-h, msg.Height-v) case tea.KeyMsg: switch { - case key.Matches(msg, ui.Common.KeyMap.Back): + case key.Matches(msg, ui.KeyMap.Back): return nil, tea.Quit - case key.Matches(msg, ui.Common.KeyMap.Select): + case key.Matches(msg, ui.KeyMap.Select): chosenAnalyzer := ui.list.SelectedItem().(KeyTypeItem) return ui, func() tea.Msg { diff --git a/pkg/tui/pages/wizard_intro/item.go b/pkg/tui/pages/wizard_intro/item.go index 7fbefa704dec..5ae19e2c4fc6 100644 --- a/pkg/tui/pages/wizard_intro/item.go +++ b/pkg/tui/pages/wizard_intro/item.go @@ -129,7 +129,7 @@ func (d ItemDelegate) Render(w io.Writer, m list.Model, index int, listItem list cmd = styles.Command.Render(cmd) s.WriteString(cmd) - fmt.Fprint(w, + _, _ = fmt.Fprint(w, d.common.Zone.Mark(i.ID(), styles.Base.Render(s.String()), ), diff --git a/pkg/tui/pages/wizard_intro/wizard_intro.go b/pkg/tui/pages/wizard_intro/wizard_intro.go index 4e54e9dfea1e..861e132b8484 100644 --- a/pkg/tui/pages/wizard_intro/wizard_intro.go +++ b/pkg/tui/pages/wizard_intro/wizard_intro.go @@ -101,8 +101,8 @@ func (m *WizardIntro) View() string { func (m *WizardIntro) ShortHelp() []key.Binding { kb := make([]key.Binding, 0) kb = append(kb, - m.Common.KeyMap.UpDown, - m.Common.KeyMap.Section, + m.KeyMap.UpDown, + m.KeyMap.Section, ) return kb } diff --git a/pkg/updater/updater.go b/pkg/updater/updater.go index b8ad42020dbe..a1b06a440c0b 100644 --- a/pkg/updater/updater.go +++ b/pkg/updater/updater.go @@ -75,7 +75,7 @@ func (g *OSS) Fetch() (io.Reader, error) { if err != nil || resp == nil { return nil, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode == http.StatusNoContent { return nil, errors.New("already up to date") @@ -105,7 +105,7 @@ func (g *OSS) Fetch() (io.Reader, error) { if err != nil { return nil, errors.Errorf("Failed to read gzip archive: %s", err) } - defer gzipReader.Close() + defer func() { _ = gzipReader.Close() }() tarReader := tar.NewReader(gzipReader) for { header, err := tarReader.Next() diff --git a/pkg/writers/buffered_file_writer/bufferedfilewriter.go b/pkg/writers/buffered_file_writer/bufferedfilewriter.go index 49c3afa9a8e8..e603f1580984 100644 --- a/pkg/writers/buffered_file_writer/bufferedfilewriter.go +++ b/pkg/writers/buffered_file_writer/bufferedfilewriter.go @@ -132,7 +132,7 @@ func (w *BufferedFileWriter) String() (string, error) { if err != nil { return "", fmt.Errorf("failed to open file: %w", err) } - defer file.Close() + defer func() { _ = file.Close() }() var buf bytes.Buffer // Read the file contents into the buffer. @@ -312,6 +312,6 @@ func newAutoDeletingFileReader(file *os.File) *autoDeletingFileReader { // Close implements the io.Closer interface, deletes the file after closing. func (r *autoDeletingFileReader) Close() error { - defer os.Remove(r.Name()) // Delete the file after closing + defer func() { _ = os.Remove(r.Name()) }() // Delete the file after closing return r.File.Close() } diff --git a/pkg/writers/buffered_file_writer/bufferedfilewriter_test.go b/pkg/writers/buffered_file_writer/bufferedfilewriter_test.go index 193c398f27cb..61863dbd8cb9 100644 --- a/pkg/writers/buffered_file_writer/bufferedfilewriter_test.go +++ b/pkg/writers/buffered_file_writer/bufferedfilewriter_test.go @@ -118,7 +118,7 @@ func BenchmarkBufferedFileWriterString_BufferOnly_Small(b *testing.B) { rc, err := writer.ReadCloser() assert.NoError(b, err) - rc.Close() + _ = rc.Close() } func BenchmarkBufferedFileWriterString_BufferOnly_Medium(b *testing.B) { @@ -135,7 +135,7 @@ func BenchmarkBufferedFileWriterString_BufferOnly_Medium(b *testing.B) { rc, err := writer.ReadCloser() assert.NoError(b, err) - rc.Close() + _ = rc.Close() } func BenchmarkBufferedFileWriterString_OnlyFile_Small(b *testing.B) { @@ -153,7 +153,7 @@ func BenchmarkBufferedFileWriterString_OnlyFile_Small(b *testing.B) { rc, err := writer.ReadCloser() assert.NoError(b, err) - rc.Close() + _ = rc.Close() } func BenchmarkBufferedFileWriterString_OnlyFile_Medium(b *testing.B) { @@ -171,7 +171,7 @@ func BenchmarkBufferedFileWriterString_OnlyFile_Medium(b *testing.B) { rc, err := writer.ReadCloser() assert.NoError(b, err) - rc.Close() + _ = rc.Close() } func BenchmarkBufferedFileWriterString_BufferWithFile_Small(b *testing.B) { @@ -193,7 +193,7 @@ func BenchmarkBufferedFileWriterString_BufferWithFile_Small(b *testing.B) { rc, err := writer.ReadCloser() assert.NoError(b, err) - rc.Close() + _ = rc.Close() } func BenchmarkBufferedFileWriterString_BufferWithFile_Medium(b *testing.B) { @@ -215,7 +215,7 @@ func BenchmarkBufferedFileWriterString_BufferWithFile_Medium(b *testing.B) { rc, err := writer.ReadCloser() assert.NoError(b, err) - rc.Close() + _ = rc.Close() } func benchmarkBufferedFileWriterString(b *testing.B, w *BufferedFileWriter) { @@ -458,7 +458,7 @@ func BenchmarkBufferedFileWriterWriteLarge(b *testing.B) { rc, err := writer.ReadCloser() assert.NoError(b, err) - rc.Close() + _ = rc.Close() } } @@ -487,7 +487,7 @@ func BenchmarkBufferedFileWriterWriteSmall(b *testing.B) { rc, err := writer.ReadCloser() assert.NoError(b, err) - rc.Close() + _ = rc.Close() } } @@ -512,7 +512,7 @@ func TestBufferWriterCloseForWritingWithFile(t *testing.T) { rdr, err := writer.ReadCloser() assert.NoError(t, err) - defer rdr.Close() + defer func() { _ = rdr.Close() }() // Get a buffer from the pool and check if it is the same buffer used in the writer. bufFromPool := bufPool.Get() @@ -584,7 +584,7 @@ func TestBufferedFileWriter_ReadFrom(t *testing.T) { rc, err := writer.ReadCloser() assert.NoError(t, err) - defer rc.Close() + defer func() { _ = rc.Close() }() var result bytes.Buffer diff --git a/scripts/lint.sh b/scripts/lint.sh index 9e889b2e3517..bb60c83ef1a1 100755 --- a/scripts/lint.sh +++ b/scripts/lint.sh @@ -4,8 +4,7 @@ set -euo pipefail # NOTE: Version and args must match .github/workflows/lint.yml GOLANGCI_LINT_VERSION="v2.11.4" -# TODO: Re-enable errcheck and staticcheck once pre-existing issues are resolved. -LINT_ARGS="--disable errcheck,staticcheck --enable bodyclose,copyloopvar,misspell --timeout 10m" +LINT_ARGS="--enable bodyclose,copyloopvar,misspell --timeout 10m" GOBIN="$(go env GOPATH)/bin" GOLANGCI_LINT="${GOBIN}/golangci-lint" From 2304ee19c8971c819857bdd608eb0ab5a0c39e6f Mon Sep 17 00:00:00 2001 From: Aman Ullah Date: Mon, 4 May 2026 15:09:23 +0500 Subject: [PATCH 2/4] fix new lint issues --- pkg/detectors/http.go | 2 +- pkg/detectors/http_test.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/detectors/http.go b/pkg/detectors/http.go index 8624d8346b42..1a2ba817c1de 100644 --- a/pkg/detectors/http.go +++ b/pkg/detectors/http.go @@ -226,7 +226,7 @@ func (t *singleflightTransport) RoundTrip(req *http.Request) (*http.Response, er if err != nil { return nil, err } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() body, err := io.ReadAll(resp.Body) if err != nil { diff --git a/pkg/detectors/http_test.go b/pkg/detectors/http_test.go index c6a7c0d7f9db..a2596785cff4 100644 --- a/pkg/detectors/http_test.go +++ b/pkg/detectors/http_test.go @@ -114,7 +114,7 @@ func TestDoWithDedup_Singleflight(t *testing.T) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { n := atomic.AddInt32(&requestCount, 1) time.Sleep(20 * time.Millisecond) - fmt.Fprintf(w, `{"request":%d}`, n) + _, _ = fmt.Fprintf(w, `{"request":%d}`, n) })) defer server.Close() @@ -140,7 +140,7 @@ func TestDoWithDedup_Singleflight(t *testing.T) { errs[i] = err return } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() var buf [512]byte n, _ := resp.Body.Read(buf[:]) bodies[i] = string(buf[:n]) @@ -201,7 +201,7 @@ func TestDoWithDedup_WaiterContextCancelled(t *testing.T) { results[i] = result{err: err} return } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() results[i] = result{status: resp.StatusCode} }(i, ctx) } @@ -249,7 +249,7 @@ func TestDoWithDedup_FirstCallerContextCancelled(t *testing.T) { firstErr = err return } - resp.Body.Close() + _ = resp.Body.Close() }() // Cancel the first caller once the server is processing, then immediately @@ -268,7 +268,7 @@ func TestDoWithDedup_FirstCallerContextCancelled(t *testing.T) { secondErr = err return } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() secondStatus = resp.StatusCode }() @@ -300,7 +300,7 @@ func TestDoWithDedup_DeadlinePreserved(t *testing.T) { start := time.Now() resp, err := DoWithDedup(client, detector_typepb.DetectorType_Meraki, "cred", req) if err == nil { - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() } elapsed := time.Since(start) From 0c63f0a30957e629b338311df6fd2741ef0a350b Mon Sep 17 00:00:00 2001 From: Aman Ullah Date: Fri, 8 May 2026 22:09:04 +0500 Subject: [PATCH 3/4] fix: missing bracket in log --- pkg/output/plain.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/output/plain.go b/pkg/output/plain.go index 878a8eb66bc1..14f972120a13 100644 --- a/pkg/output/plain.go +++ b/pkg/output/plain.go @@ -59,7 +59,7 @@ func (p *PlainPrinter) Print(_ context.Context, r *detectors.ResultWithMetadata) } if r.VerificationFromCache { - _, _ = cyanPrinter.Print("🔍 Using cached verification)\n") + _, _ = cyanPrinter.Print("(🔍 Using cached verification)\n") } _, _ = printer.Printf("Detector Type: %s\n", out.DetectorType) _, _ = printer.Printf("Decoder Type: %s\n", out.DecoderType) From 84c292e5edb00e91234c0072778f0994db254f34 Mon Sep 17 00:00:00 2001 From: Aman Ullah Date: Wed, 13 May 2026 21:24:49 +0500 Subject: [PATCH 4/4] skip lint on intentional reference of deprecated DetectorType values --- pkg/engine/defaults/defaults_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/engine/defaults/defaults_test.go b/pkg/engine/defaults/defaults_test.go index 7e3521ea599d..bdaf062aba54 100644 --- a/pkg/engine/defaults/defaults_test.go +++ b/pkg/engine/defaults/defaults_test.go @@ -111,6 +111,7 @@ func TestAllDetectorTypesAreInDefaultList(t *testing.T) { // // TODO: audit this list periodically — entries in the "mistakenly missed" group // should be removed once the corresponding detector is added to defaults.go. +//nolint:staticcheck // SA1019: intentionally references deprecated DetectorType values to keep them excluded. var excludedFromDefaultList = map[detector_typepb.DetectorType]struct{}{ // TODO: these detectors have implementations but were mistakenly never added // to buildDetectorList() — discovered by TestAllDetectorTypesAreInDefaultList.