You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sssecrets is a reusable implementation of GitHub's structured secret token format. You can learn more about GitHub's design process and the properties of their API token format on the [GitHub blog](https://github.blog/2021-04-05-behind-githubs-new-authentication-token-formats/).
6
5
7
-
## Why Structured Secrets?
6
+
Welcome to sssecrets: **S**imple **S**tructured **Secrets**. Sssecrets is a library for generating secrets (like API tokens, etc) in line with best practices.
8
7
9
-
If you're a developer and your application issues some kind of access tokens (API keys, PATs, etc), it's important to format these in a way that both identifies the string as a secret token and provides insight into its permissions. Even better if you provide example (dummy) tokens and regexes for them in your documentation!
8
+
Sssecrets is a reusable implementation of GitHub's [API token format](https://github.blog/2021-04-05-behind-githubs-new-authentication-token-formats/) (which is also used by [NPM](https://github.blog/2021-09-23-announcing-npms-new-access-token-format/)), and it's designed to make it simple for developers to issue secure secret tokens that are easy to detect when leaked.
9
+
10
+
You can learn more about GitHub's design process and the properties of this API token format on the [GitHub blog](https://github.blog/2021-04-05-behind-githubs-new-authentication-token-formats/).
11
+
12
+
## Why Structured Secrets?
13
+
14
+
If you're a developer and your application issues some kind of access tokens (API keys, PATs, etc), it's important to format these in a way that both identifies the string as a secret token and provides insight into its permissions. For bonus points, you should also provide example (dummy) tokens and regexes for them in your documentation.
10
15
11
16
Simple Structured Secrets help solve this problem: They're a compact format with properties that are optimized for detection with static analysis tools. That makes it possible to automatically detect when secrets are leaked in a codebase using features like [GitHub Secret Scanning](https://docs.github.com/en/code-security/secret-scanning/about-secret-scanning) or GitLab Secret Detection.
12
17
@@ -22,14 +27,20 @@ While random, strings in this format are used in many places for non-sensitive p
22
27
23
28
Structured secrets have three parts:
24
29
25
-
- A prefix (defined by you),
26
-
- 30 characters of randomness,
27
-
- A 6 character checksum.
30
+
- A prefix (2-10 characters, defined by you)
31
+
- 30 characters of randomness
32
+
- A 6 character checksum
33
+
34
+
That's it!
28
35
29
-
That's it!
36
+
Here's the format:
30
37
31
38
`[prefix]_[randomness][checksum]`
32
39
40
+
An example Sssecret, with an `org` of `t` and a `type` of `k`, looks like this:
41
+
42
+
`tk_GNrRoBa1p9nuwm7XrWkrhYUNQ7edOw4GUp8I`
43
+
33
44
### Prefix
34
45
35
46
Token prefixes are a simple and effective method to make tokens identifiable. [Slack](https://api.slack.com/authentication/token-types), [Stripe](https://stripe.com/docs/api/authentication), [GitHub](https://github.blog/2021-04-05-behind-githubs-new-authentication-token-formats/#identifiable-prefixes), and others have adopted this approach to great effect.
@@ -52,6 +63,8 @@ The token checksum can be used as a first-pass validity check. Using these check
52
63
53
64
_Note that this library can only check whether a given token is in the correct form and has a valid checksum. To fully determine whether a given token is active, you'll still need to implement your own logic for checking the validity of tokens you've issued._
54
65
66
+
_Another note: Because Sssecrets uses the same format as GitHub tokens, you can also perform offline validation of GitHub-issued secrets with `SimpleStructuredSecrets#validate`._
0 commit comments