
एंटरप्राइज़ के अनुकूल तरीके से कोड में गुप्त जानकारी का पता लगाना और उसे रोकना।
detect-secrets एक उपयुक्त नाम वाला मॉड्यूल है जो (आश्चर्य, आश्चर्य) रहस्यों का पता लगाने के लिए है
एक कोड बेस के भीतर।
हालाँकि, अन्य समान पैकेजों के विपरीत जो केवल रहस्यों को खोजने पर ध्यान केंद्रित करते हैं, यह पैकेज एंटरप्राइज़ क्लाइंट को ध्यान में रखकर डिज़ाइन किया गया है: एक , व्यवस्थित साधन प्रदान करता है:
इस तरह, आप एक चिंता का पृथक्करण बनाते हैं: यह स्वीकार करना कि आपके बड़े रिपॉजिटरी में वर्तमान में रहस्य छिपे हो सकते हैं (इसे हम बेसलाइन कहते हैं), लेकिन इस समस्या को और बढ़ने से रोकना, मौजूदा रहस्यों को हटाने के संभावित विशाल प्रयास से निपटने के बिना।
यह अनुमानित रूप से तैयार किए गए रेगेक्स स्टेटमेंट के विरुद्ध आवधिक डिफ आउटपुट चलाकर ऐसा करता है, यह पहचानने के लिए कि क्या कोई नया रहस्य प्रतिबद्ध किया गया है। इस तरह, यह सभी गिट हिस्ट्री खंगालने के ओवरहेड से बचता है, साथ ही हर बार पूरे रिपॉजिटरी को स्कैन करने की आवश्यकता से भी बचता है।
हाल के बदलावों को देखने के लिए, कृपया देखें CHANGELOG.md।
यदि आप योगदान देना चाहते हैं, तो कृपया देखें CONTRIBUTING.md।
अधिक विस्तृत दस्तावेज़ीकरण के लिए, हमारे अन्य दस्तावेज़ देखें।
अपने गिट रिपॉजिटरी में वर्तमान में पाए गए संभावित रहस्यों का एक बेसलाइन बनाएँ।```bash $ detect-secrets scan > .secrets.baseline
या, किसी भिन्न निर्देशिका से चलाने के लिए:```bash
$ detect-secrets -C /path/to/directory scan > /path/to/directory/.secrets.baseline
गैर-गिट ट्रैक की गई फ़ाइलों को स्कैन करना:```bash $ detect-secrets scan test_data/ --all-files > .secrets.baseline
### बेसलाइन में नए रहस्य जोड़ना:
यह आपके कोडबेस को पुनः स्कैन करेगा, और:
1. नवीनतम संस्करण के साथ संगत होने के लिए आपकी बेसलाइन को अपडेट/अपग्रेड करेगा,
2. आपकी बेसलाइन में मिलने वाले किसी भी नए रहस्य को जोड़ेगा,
3. आपके कोडबेस से अब हटाए गए किसी भी रहस्य को हटाएगा
यह आपके द्वारा लेबल किए गए किसी भी रहस्य को भी संरक्षित करेगा।```bash
$ detect-secrets scan --baseline .secrets.baseline
संस्करण 0.9 से पुराने बेसलाइन्स के लिए, बस इसे पुनः बनाएं।
केवल स्टेज की गई फ़ाइलों को स्कैन करना:```bash $ git diff --staged --name-only -z | xargs -0 detect-secrets-hook --baseline .secrets.baseline
**सभी ट्रैक की गई फ़ाइलों को स्कैन करना:**```bash
$ git ls-files -z | xargs -0 detect-secrets-hook --baseline .secrets.baseline
$ detect-secrets scan --list-all-plugins ArtifactoryDetector AWSKeyDetector AzureStorageKeyDetector BasicAuthDetector CloudantDetector DiscordBotTokenDetector GitHubTokenDetector GitLabTokenDetector Base64HighEntropyString HexHighEntropyString IbmCloudIamDetector IbmCosHmacDetector IPPublicDetector JwtTokenDetector KeywordDetector MailchimpDetector NpmDetector OpenAIDetector PrivateKeyDetector PypiTokenDetector SendGridDetector SlackDetector SoftlayerDetector SquareOAuthDetector StripeDetector TelegramBotTokenDetector TwilioKeyDetector
### प्लगइन्स को अक्षम करना:```bash
$ detect-secrets scan --disable-plugin KeywordDetector --disable-plugin AWSKeyDetector
यदि आप केवल एक विशिष्ट प्लगइन चलाना चाहते हैं, तो आप ऐसा कर सकते हैं:```bash
$ detect-secrets scan --list-all-plugins |
grep -v 'BasicAuthDetector' |
sed "s#^#--disable-plugin #g" |
xargs detect-secrets scan test_data
### आधार रेखा का ऑडिट करना:
यह आपकी आधार रेखा में परिणामों को लेबल करने का एक वैकल्पिक कदम है। इसका उपयोग माइग्रेट करने के लिए रहस्यों की अपनी चेकलिस्ट को संकीर्ण करने,
या अपने प्लगइन्स को बेहतर ढंग से कॉन्फ़िगर करने के लिए किया जा सकता है ताकि इसका सिग्नल-टू-शोर
अनुपात बेहतर हो सके।```bash
$ detect-secrets audit .secrets.baseline
मूल उपयोग:```python from detect_secrets import SecretsCollection from detect_secrets.settings import default_settings
secrets = SecretsCollection() with default_settings(): secrets.scan_file('test_data/config.ini')
import json print(json.dumps(secrets.json(), indent=2))
**अधिक उन्नत कॉन्फ़िगरेशन:**```python
from detect_secrets import SecretsCollection
from detect_secrets.settings import transient_settings
secrets = SecretsCollection()
with transient_settings({
# Only run scans with only these plugins.
# This format is the same as the one that is saved in the generated baseline.
'plugins_used': [
# Example of configuring a built-in plugin
{
'name': 'Base64HighEntropyString',
'limit': 5.0,
},
# Example of using a custom plugin
{
'name': 'HippoDetector',
'path': 'file:///Users/aaronloo/Documents/github/detect-secrets/testing/plugins.py',
},
],
# We can also specify whichever additional filters we want.
# This is an example of using the function `is_identified_by_ML_model` within the
# local file `./private-filters/example.py`.
'filters_used': [
{
'path': 'file://private-filters/example.py::is_identified_by_ML_model',
},
]
}) as settings:
# If we want to make any further adjustments to the created settings object (e.g.
# disabling default filters), we can do so as such.
settings.disable_filters(
'detect_secrets.filters.heuristic.is_prefixed_with_dollar_sign',
'detect_secrets.filters.heuristic.is_likely_id_string',
)
secrets.scan_file('test_data/config.ini')
$ pip install detect-secrets ✨🍰✨
[brew](https://brew.sh/) के माध्यम से इंस्टॉल करें:```bash
$ brew install detect-secrets
detect-secrets तीन अलग-अलग उपकरणों के साथ आता है, और अक्सर इस बात को लेकर भ्रम होता है कि किसका उपयोग करना चाहिए। आपकी सहायता के लिए यह सुविधाजनक चेकलिस्ट का उपयोग करें:
detect-secrets scan का उपयोग करें।detect-secrets-hook का उपयोग करें।detect-secrets audit का उपयोग करें।$ detect-secrets scan --help usage: detect-secrets scan [-h] [--string [STRING]] [--only-allowlisted] [--all-files] [--baseline FILENAME] [--force-use-all-plugins] [--slim] [--list-all-plugins] [-p PLUGIN] [--base64-limit [BASE64_LIMIT]] [--hex-limit [HEX_LIMIT]] [--disable-plugin DISABLE_PLUGIN] [-n | --only-verified] [--exclude-lines EXCLUDE_LINES] [--exclude-files EXCLUDE_FILES] [--exclude-secrets EXCLUDE_SECRETS] [--word-list WORD_LIST_FILE] [-f FILTER] [--disable-filter DISABLE_FILTER] [path [path ...]]
Scans a repository for secrets in code. The generated output is compatible
with detect-secrets-hook --baseline.
positional arguments: path Scans the entire codebase and outputs a snapshot of currently identified secrets.
optional arguments:
-h, --help show this help message and exit
--string [STRING] Scans an individual string, and displays configured
plugins' verdict.
--only-allowlisted Only scans the lines that are flagged with allowlist secret. This helps verify that individual exceptions
are indeed non-secrets.
scan options:
--all-files Scan all files recursively (as compared to only
scanning git tracked files).
--baseline FILENAME If provided, will update existing baseline by
importing settings from it.
--force-use-all-plugins
If a baseline is provided, detect-secrets will default
to loading the plugins specified by that baseline.
However, this may also mean it doesn't perform the
scan with the latest plugins. If this flag is
provided, it will always use the latest plugins
--slim Slim baselines are created with the intention of
minimizing differences between commits. However, they
are not compatible with the audit functionality, and
slim baselines will need to be remade to be audited.
plugin options: Configure settings for each secret scanning ruleset. By default, all plugins are enabled unless explicitly disabled.
--list-all-plugins Lists all plugins that will be used for the scan. -p PLUGIN, --plugin PLUGIN Specify path to custom secret detector plugin. --base64-limit [BASE64_LIMIT] Sets the entropy limit for high entropy strings. Value must be between 0.0 and 8.0, defaults to 4.5. --hex-limit [HEX_LIMIT] Sets the entropy limit for high entropy strings. Value must be between 0.0 and 8.0, defaults to 3.0. --disable-plugin DISABLE_PLUGIN Plugin class names to disable. e.g. Base64HighEntropyString
filter options: Configure settings for filtering out secrets after they are flagged by the engine.
-n, --no-verify Disables additional verification of secrets via network call. --only-verified Only flags secrets that can be verified. --exclude-lines EXCLUDE_LINES If lines match this regex, it will be ignored. --exclude-files EXCLUDE_FILES If filenames match this regex, it will be ignored. --exclude-secrets EXCLUDE_SECRETS If secrets match this regex, it will be ignored. --word-list WORD_LIST_FILE Text file with a list of words, if a secret contains a word in the list we ignore it. -f FILTER, --filter FILTER Specify path to custom filter. May be a python module path (e.g. detect_secrets.filters.common.is_invalid_file) or a local file path (e.g. file://path/to/file.py::function_name). --disable-filter DISABLE_FILTER Specify filter to disable. e.g. detect_secrets.filters.common.is_invalid_file
### बेसलाइन में नहीं हैं गुप्त जानकारियों को ब्लॉक करना```
$ detect-secrets-hook --help
usage: detect-secrets-hook [-h] [-v] [--version] [--baseline FILENAME]
[--list-all-plugins] [-p PLUGIN]
[--base64-limit [BASE64_LIMIT]]
[--hex-limit [HEX_LIMIT]]
[--disable-plugin DISABLE_PLUGIN]
[-n | --only-verified]
[--exclude-lines EXCLUDE_LINES]
[--exclude-files EXCLUDE_FILES]
[--exclude-secrets EXCLUDE_SECRETS]
[--word-list WORD_LIST_FILE] [-f FILTER]
[--disable-filter DISABLE_FILTER]
[filenames [filenames ...]]
positional arguments:
filenames Filenames to check.
optional arguments:
-h, --help show this help message and exit
-v, --verbose Verbose mode.
--version Display version information.
--json Print detect-secrets-hook output as JSON
--baseline FILENAME Explicitly ignore secrets through a baseline generated
by `detect-secrets scan`
plugin options:
Configure settings for each secret scanning ruleset. By default, all
plugins are enabled unless explicitly disabled.
--list-all-plugins Lists all plugins that will be used for the scan.
-p PLUGIN, --plugin PLUGIN
Specify path to custom secret detector plugin.
--base64-limit [BASE64_LIMIT]
Sets the entropy limit for high entropy strings. Value
must be between 0.0 and 8.0, defaults to 4.5.
--hex-limit [HEX_LIMIT]
Sets the entropy limit for high entropy strings. Value
must be between 0.0 and 8.0, defaults to 3.0.
--disable-plugin DISABLE_PLUGIN
Plugin class names to disable. e.g.
Base64HighEntropyString
filter options:
Configure settings for filtering out secrets after they are flagged by the
engine.
-n, --no-verify Disables additional verification of secrets via
network call.
--only-verified Only flags secrets that can be verified.
--exclude-lines EXCLUDE_LINES
If lines match this regex, it will be ignored.
--exclude-files EXCLUDE_FILES
If filenames match this regex, it will be ignored.
--exclude-secrets EXCLUDE_SECRETS
If secrets match this regex, it will be ignored.
-f FILTER, --filter FILTER
Specify path to custom filter. May be a python module
path (e.g.
detect_secrets.filters.common.is_invalid_file) or a
local file path (e.g.
file://path/to/file.py::function_name).
--disable-filter DISABLE_FILTER
Specify filter to disable. e.g.
detect_secrets.filters.common.is_invalid_file
हम इसे प्री-कमिट हुक के रूप में सेट करने की सलाह देते हैं। ऐसा करने का एक तरीका pre-commit फ्रेमवर्क का उपयोग करना है:```yaml
repos:
#### इनलाइन अनुमति सूची
कभी-कभी हम किसी झूठे सकारात्मक (false positive) को कमिट को ब्लॉक करने से बाहर करना चाहते हैं, बिना कोई बेसलाइन बनाए। ऐसा आप इस प्रकार एक टिप्पणी जोड़कर कर सकते हैं:```python
secret = "hunter2" # pragma: allowlist secret
या```javascript // pragma: allowlist nextline secret const secret = "hunter2";
### बेसलाइन में गुप्त जानकारी का ऑडिट```bash
$ detect-secrets audit --help
usage: detect-secrets audit [-h] [--diff] [--stats]
[--report] [--only-real | --only-false]
[--json]
filename [filename ...]
Auditing a baseline allows analysts to label results, and optimize plugins for
the highest signal-to-noise ratio for their environment.
positional arguments:
filename Audit a given baseline file to distinguish the difference
between false and true positives.
optional arguments:
-h, --help show this help message and exit
--diff Allows the comparison of two baseline files, in order to
effectively distinguish the difference between various plugin
configurations.
--stats Displays the results of an interactive auditing session which
have been saved to a baseline file.
--report Displays a report with the secrets detected
reporting:
Display a summary with all the findings and the made decisions. To be used with the report mode (--report).
--only-real Only includes real secrets in the report
--only-false Only includes false positives in the report
analytics:
Quantify the success of your plugins based on the labelled results in your
baseline. To be used with the statistics mode (--stats).
--json Outputs results in a machine-readable format.
यह टूल प्लगइन्स और फ़िल्टर की प्रणाली के माध्यम से काम करता है।
आप अपनी परिशुद्धता/प्रभाविता (precision/recall) आवश्यकताओं के अनुसार दोनों को समायोजित कर सकते हैं।
कोड में रहस्य खोजने के लिए हम तीन अलग-अलग रणनीतियाँ अपनाते हैं:
Regex-आधारित नियम
ये सबसे सामान्य प्रकार के प्लगइन हैं, और अच्छी तरह से संरचित रहस्यों के साथ अच्छा काम करते हैं। इन रहस्यों को वैकल्पिक रूप से सत्यापित किया जा सकता है, जो स्कैनिंग परिशुद्धता बढ़ाता है। हालाँकि, केवल इन पर निर्भर रहने से आपके स्कैन की प्रभाविता (recall) पर नकारात्मक प्रभाव पड़ सकता है।
एंट्रॉपी डिटेक्टर
यह विभिन्न अनुमानात्मक दृष्टिकोणों के माध्यम से "गुप्त-दिखने वाले" स्ट्रिंग्स की खोज करता है। यह गैर-संरचित रहस्यों के लिए बहुत अच्छा है, लेकिन स्कैनिंग परिशुद्धता को समायोजित करने के लिए ट्यूनिंग की आवश्यकता हो सकती है।
कीवर्ड डिटेक्टर
यह गुप्त मान को अनदेखा करता है, और उन चर नामों की खोज करता है जो अक्सर हार्ड-कोडेड मानों के साथ रहस्यों को निर्दिष्ट करने से जुड़े होते हैं। यह "गैर-गुप्त-दिखने वाले" स्ट्रिंग्स (जैसे le3tc0de पासवर्ड) के लिए बहुत अच्छा है, लेकिन स्कैनिंग परिशुद्धता को समायोजित करने के लिए फ़िल्टर ट्यूनिंग की आवश्यकता हो सकती है।
क्या आप ऐसा रहस्य ढूंढना चाहते हैं जिसे हम वर्तमान में नहीं पकड़ते? आप (आसानी से) अपना स्वयं का प्लगइन विकसित कर सकते हैं, और इसे इंजन के साथ उपयोग कर सकते हैं! अधिक जानकारी के लिए, प्लगइन दस्तावेज़ीकरण देखें।
detect-secrets में कई अलग-अलग अंतर्निर्मित फ़िल्टर हैं जो आपकी आवश्यकताओं के अनुरूप हो सकते हैं।
कभी-कभी, आप अपने स्कैन में कुछ पंक्तियों को वैश्विक रूप से अनुमति देना चाहते हैं, यदि वे किसी विशिष्ट पैटर्न से मेल खाती हैं। आप एक regex नियम इस प्रकार निर्दिष्ट कर सकते हैं:```bash $ detect-secrets scan --exclude-lines 'password = (blah|fake)'
या आप इस प्रकार एकाधिक regex नियम निर्दिष्ट कर सकते हैं:```bash
$ detect-secrets scan --exclude-lines 'password = blah' --exclude-lines 'password = fake'
कभी-कभी, आप अपने स्कैन में कुछ फाइलों को अनदेखा करना चाहते हैं। ऐसा करने के लिए आप एक regex पैटर्न निर्दिष्ट कर सकते हैं, और यदि फ़ाइल का नाम इस regex पैटर्न से मेल खाता है, तो उसे स्कैन नहीं किया जाएगा:```bash $ detect-secrets scan --exclude-files '.*.signature$'
या आप एकाधिक regex पैटर्न इस प्रकार निर्दिष्ट कर सकते हैं:```bash
$ detect-secrets scan --exclude-files '.*\.signature$' --exclude-files '.*/i18n/.*'
कभी-कभी, आप अपने स्कैन में कुछ गुप्त मानों को अनदेखा करना चाहते हैं। आप इस प्रकार एक regex नियम निर्दिष्ट कर सकते हैं:```bash $ detect-secrets scan --exclude-secrets '(fakesecret|${.*})'
या आप इस प्रकार कई regex नियम निर्दिष्ट कर सकते हैं:```bash
$ detect-secrets scan --exclude-secrets 'fakesecret' --exclude-secrets '\${.*})'
कभी-कभी, आप किसी विशिष्ट पंक्ति पर एक बहिष्करण लागू करना चाहते हैं, न कि वैश्विक रूप से बहिष्कृत करना। आप इसे इनलाइन अनुमति सूची के माध्यम से इस प्रकार कर सकते हैं:```python API_KEY = 'this-will-ordinarily-be-detected-by-a-plugin' # pragma: allowlist secret
ये टिप्पणियाँ कई भाषाओं में समर्थित हैं। जैसे.```java
const GoogleCredentialPassword = "something-secret-here"; // pragma: allowlist secret
आप इसका भी उपयोग कर सकते हैं:```python
API_KEY = 'WillAlsoBeIgnored'
यह आपके लिए रहस्यों को अनदेखा करने का एक सुविधाजनक तरीका हो सकता है, बिना पूरी बेसलाइन को फिर से उत्पन्न करने की आवश्यकता के। यदि आपको इन अनुमत सूचीबद्ध रहस्यों को स्पष्ट रूप से खोजने की आवश्यकता है, तो आप ऐसा भी कर सकते हैं:```bash
$ detect-secrets scan --only-allowlisted
अधिक कस्टम लॉजिक लिखकर झूठी सकारात्मकताओं को फ़िल्टर करना चाहते हैं? हमारे फ़िल्टर दस्तावेज़ीकरण में देखें कि यह कैसे करें।
--exclude-secrets फ़्लैग आपको गुप्त मानों को बाहर करने के लिए regex नियम निर्दिष्ट करने की अनुमति देता है। हालांकि, यदि आप इसके बजाय शब्दों की एक बड़ी सूची निर्दिष्ट करना चाहते हैं, तो आप --word-list फ़्लैग का उपयोग कर सकते हैं।
इस सुविधा का उपयोग करने के लिए, pyahocorasick पैकेज स्थापित करना सुनिश्चित करें, या बस उपयोग करें:```bash
$ pip install detect-secrets[word_list]
फिर, आप इसका उपयोग इस प्रकार कर सकते हैं:```bash
$ cat wordlist.txt
not-a-real-secret
$ cat sample.ini
password = not-a-real-secret
# Will show results
$ detect-secrets scan sample.ini
# No results found
$ detect-secrets scan --word-list wordlist.txt
गिबरिश डिटेक्टर एक सरल ML मॉडल है, जो यह निर्धारित करने का प्रयास करता है कि कोई गुप्त मान वास्तव में बकवास है या नहीं, इस धारणा के साथ कि वास्तविक गुप्त मान शब्द-जैसे नहीं होते हैं।
इस सुविधा का उपयोग करने के लिए, gibberish-detector पैकेज स्थापित करना सुनिश्चित करें, या उपयोग करें:```bash
$ pip install detect-secrets[gibberish]
मॉडल को प्रशिक्षित करने के तरीके के बारे में अधिक जानकारी के लिए [gibberish-detector](https://github.com/domanchi/gibberish-detector) पैकेज देखें। एक पूर्व-प्रशिक्षित मॉडल (RFCs को संसाधित करके सीड किया गया) आसान उपयोग के लिए शामिल किया जाएगा।
आप अपना स्वयं का मॉडल भी इस प्रकार निर्दिष्ट कर सकते हैं:```bash
$ detect-secrets scan --gibberish-model custom.model
यह डिफ़ॉल्ट प्लगइन नहीं है, क्योंकि यह password जैसे रहस्यों को अनदेखा करेगा।
यह कोडबेस में रहस्यों को प्रवेश करने से रोकने का पक्का समाधान नहीं है। केवल उचित डेवलपर शिक्षा ही वास्तव में ऐसा कर सकती है। यह प्री-कमिट हुक केवल कुछ अनुमानों को लागू करता है ताकि रहस्यों को कमिट करने के स्पष्ट मामलों को रोकने का प्रयास किया जा सके।
जिन चीज़ों को रोका नहीं जाएगा:
KeywordDetector को ट्रिगर नहीं करते (जैसे login = "hunter2")"गिट रिपॉजिटरी का पता नहीं चला।" चेतावनी, भले ही मैं गिट रेपो में हूँ।
जाँचें कि आपका git संस्करण >= 1.8.5 है या नहीं। यदि नहीं, तो कृपया इसे अपग्रेड करें और पुनः प्रयास करें।
अधिक विवरण यहाँ।
बेसलाइन बनाने के बाद detect-secrets audit "मान्य बेसलाइन फ़ाइल नहीं!" प्रदर्शित करता है।
सुनिश्चित करें कि आपकी बेसलाइन फ़ाइल का फ़ाइल एन्कोडिंग UTF-8 है। अधिक विवरण यहाँ।