Skip to content

Commit

Permalink
Adding Security RegExes: ?<Security_AccessToken> and ?<Security_JWT>
Browse files Browse the repository at this point in the history
  • Loading branch information
StartAutomating committed Apr 9, 2021
1 parent 5e16230 commit 2ba9de3
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
39 changes: 39 additions & 0 deletions RegEx/Security/AccessToken.regex.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<#
.Synopsis
Matches Access Tokens
.Description
Matches Access Tokens.
Access Tokens are single-line base64 strings that have more than -MinimumLength characters (default 40)
#>
param(
# The Minimum Length of an Access Token. By default, 40 characters
[int]
$MinimumLength = 40,


# The Maximum Length of an Access Token. By default, 1kb characters
[int]
$MaximumLength = 1kb,

# If set, will look for a hexadecimal access token.
# By default, will match Base64 access tokens
[switch]
$Hex,

# If set, will allow the token to be a JSON Web Token.
# These are similar to Base64 tokens, but may contain periods (and will tend to be longer)
[Alias('JSONWebToken')]
[switch]
$JWT
)

if ($Hex) {
"(?<AccessToken>[0-9a-f]{$MinimumLength,$MaximumLength})"
}
elseif ($JWT) {
"(?<AccessToken>[0-9a-z/=\+\.]{$MinimumLength,$MaximumLength})"
}
else {
"(?<AccessToken>[0-9a-z/=\+]{$MinimumLength,$MaximumLength})"
}
11 changes: 11 additions & 0 deletions RegEx/Security/JWT.regex.source.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
$myName = ($MyInvocation.MyCommand.ScriptBlock.File | Split-Path -Leaf) -replace '\.source', '' -replace '\.ps1', '.txt'
$myRoot = $MyInvocation.MyCommand.ScriptBlock.File | Split-Path
Write-RegEx -Description @'
Matches a JSON Web Token (JWT)
'@ |
Write-RegEx -Pattern '[0-9a-z=/\+]+' -Name Header -Comment "A base 64 string containing the header" |
Write-RegEx -LiteralCharacter '.' -Comment "Followed by a period" |
Write-RegEx -Pattern '[0-9a-z=/\+]+' -Name Payload -Comment "A base 64 string containing the payload" |
Write-RegEx -LiteralCharacter '.' -Comment "Followed by a period" |
Write-RegEx -Pattern '[0-9a-z=/\+]+' -Name Signature -Comment "A base 64 string containing the signature" |
Set-Content -Path (Join-Path $myRoot $myName) -PassThru
7 changes: 7 additions & 0 deletions RegEx/Security/JWT.regex.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Matches a JSON Web Token (JWT)
(?<Header>[0-9a-z=/\+]+) # A base 64 string containing the header
\. # Followed by a period
(?<Payload>[0-9a-z=/\+]+) # A base 64 string containing the payload
\. # Followed by a period
(?<Signature>[0-9a-z=/\+]+) # A base 64 string containing the signature

1 change: 1 addition & 0 deletions RegEx/Security/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This directory contains Regular Expressions related to Security.

0 comments on commit 2ba9de3

Please sign in to comment.