Skip to content

Add detection rule for Anthropic API keys

What does this MR do?

Adds rule for Anthropic API keys. Rule was provided by Anthropic.

Click to expand test results of running *regex-scoring manually
~/code/regex-scoring(master) $ cat anthrop.toml 
[[rules]]
id = "anthropic_key"
description = "Anthropic keys"
regex = '''\b(sk-ant-[a-z]{3}\d{2}-[A-Za-z0-9\-_]{86}-[A-Za-z0-9\-_]{8})(?:[[:punct:]]|[[:space:]]|[[:blank:]]|$)'''
keywords = [
    "sk-ant-",
]
~/code/regex-scoring(master) $ go run main.go -tomlFile=anthrop.toml
File to parse for rules: anthrop.toml
SCORE: 2 / 3 File: negative_scenarios Regex: \b(sk-ant-[a-z]{3}\d{2}-[A-Za-z0-9\-_]{86}-[A-Za-z0-9\-_]{8})(?:[[:punct:]]|[[:space:]]|[[:blank:]]|$) Token: sk-ant-inh09-fFmeKQn8EThQL9WEnHHoorxVGKg4266YlipB8kj4pfccHJjC9_UHtYF43fM7eGLcLaw8Bepz_R9OVDTn3rNzI5-WsDpHaOT}
SCORE: 51 / 52 File: positive_scenarios Regex: \b(sk-ant-[a-z]{3}\d{2}-[A-Za-z0-9\-_]{86}-[A-Za-z0-9\-_]{8})(?:[[:punct:]]|[[:space:]]|[[:blank:]]|$) Token: sk-ant-inh09-fFmeKQn8EThQL9WEnHHoorxVGKg4266YlipB8kj4pfccHJjC9_UHtYF43fM7eGLcLaw8Bepz_R9OVDTn3rNzI5-WsDpHaOT}
~/code/regex-scoring(master) $ 
~/code/regex-scoring(master) $ go run main.go -tomlFile=anthrop.toml
File to parse for rules: anthrop.toml
SCORE: 3 / 3 File: negative_scenarios Regex: \b(sk-ant-[a-z]{3}\d{2}-[A-Za-z0-9\-_]{86}-[A-Za-z0-9\-_]{8})(?:[[:punct:]]|[[:space:]]|[[:blank:]]|$) Token: sk-ant-hxv86-2tnsgAf5mLCdAgRqa2iBpuTproWdBQ9vWoWBpXbWINjjTayXxniiz-aaSsRZWH2XvTmkoyqsREDOm4yemacoGO-LyJop3Mi
SCORE: 51 / 52 File: positive_scenarios Regex: \b(sk-ant-[a-z]{3}\d{2}-[A-Za-z0-9\-_]{86}-[A-Za-z0-9\-_]{8})(?:[[:punct:]]|[[:space:]]|[[:blank:]]|$) Token: sk-ant-hxv86-2tnsgAf5mLCdAgRqa2iBpuTproWdBQ9vWoWBpXbWINjjTayXxniiz-aaSsRZWH2XvTmkoyqsREDOm4yemacoGO-LyJop3Mi

~/code/regex-scoring(master) $ go run main.go -tomlFile=anthrop.toml
File to parse for rules: anthrop.toml
SCORE: 3 / 3 File: negative_scenarios Regex: \b(sk-ant-[a-z]{3}\d{2}-[A-Za-z0-9\-_]{86}-[A-Za-z0-9\-_]{8})(?:[[:punct:]]|[[:space:]]|[[:blank:]]|$) Token: sk-ant-mhm42-gWkilqiNY_86QkCrMoe8tvhbINtcbkFKk_HKM8UuCDdrZLQloxYUS_HWdPNbdAhXh_vA3GWMhTVjXovim0difM-i07HMpF-
SCORE: 51 / 52 File: positive_scenarios Regex: \b(sk-ant-[a-z]{3}\d{2}-[A-Za-z0-9\-_]{86}-[A-Za-z0-9\-_]{8})(?:[[:punct:]]|[[:space:]]|[[:blank:]]|$) Token: sk-ant-mhm42-gWkilqiNY_86QkCrMoe8tvhbINtcbkFKk_HKM8UuCDdrZLQloxYUS_HWdPNbdAhXh_vA3GWMhTVjXovim0difM-i07HMpF-

~/code/regex-scoring(master) $ go run main.go -tomlFile=anthrop.toml
File to parse for rules: anthrop.toml
SCORE: 3 / 3 File: negative_scenarios Regex: \b(sk-ant-[a-z]{3}\d{2}-[A-Za-z0-9\-_]{86}-[A-Za-z0-9\-_]{8})(?:[[:punct:]]|[[:space:]]|[[:blank:]]|$) Token: sk-ant-pxs93-5FDuZtmUlXURSs_TjuxXfgYCBTgjyF3wVEiCXGTVJIfVhyNUC3IONx-S_0veziE4Bh71a_t51E47rVMw_pHbZu-lm8VOoXK
SCORE: 51 / 52 File: positive_scenarios Regex: \b(sk-ant-[a-z]{3}\d{2}-[A-Za-z0-9\-_]{86}-[A-Za-z0-9\-_]{8})(?:[[:punct:]]|[[:space:]]|[[:blank:]]|$) Token: sk-ant-pxs93-5FDuZtmUlXURSs_TjuxXfgYCBTgjyF3wVEiCXGTVJIfVhyNUC3IONx-S_0veziE4Bh71a_t51E47rVMw_pHbZu-lm8VOoXK

~/code/regex-scoring(master) $ go run main.go -tomlFile=anthrop.toml -debug
File to parse for rules: anthrop.toml
DIDN'T MATCH: aaaask-ant-kdi78-0mwyCwJdeeACpsFVpG4145-DhxDzv6Ca2_PvRIzbp1zsARScyI_Ty6Mu53cV7OOb9tDCZi0tMfR8D9ALBVUd8V-cgQ9htod*
DIDN'T MATCH: aaaask-ant-kdi78-0mwyCwJdeeACpsFVpG4145-DhxDzv6Ca2_PvRIzbp1zsARScyI_Ty6Mu53cV7OOb9tDCZi0tMfR8D9ALBVUd8V-cgQ9htod*aaaa
SCORE: 2 / 3 File: negative_scenarios Regex: \b(sk-ant-[a-z]{3}\d{2}-[A-Za-z0-9\-_]{86}-[A-Za-z0-9\-_]{8})(?:[[:punct:]]|[[:space:]]|[[:blank:]]|$) Token: sk-ant-kdi78-0mwyCwJdeeACpsFVpG4145-DhxDzv6Ca2_PvRIzbp1zsARScyI_Ty6Mu53cV7OOb9tDCZi0tMfR8D9ALBVUd8V-cgQ9htod*
DIDN'T MATCH: _sk-ant-kdi78-0mwyCwJdeeACpsFVpG4145-DhxDzv6Ca2_PvRIzbp1zsARScyI_Ty6Mu53cV7OOb9tDCZi0tMfR8D9ALBVUd8V-cgQ9htod*
SCORE: 51 / 52 File: positive_scenarios Regex: \b(sk-ant-[a-z]{3}\d{2}-[A-Za-z0-9\-_]{86}-[A-Za-z0-9\-_]{8})(?:[[:punct:]]|[[:space:]]|[[:blank:]]|$) Token: sk-ant-kdi78-0mwyCwJdeeACpsFVpG4145-DhxDzv6Ca2_PvRIzbp1zsARScyI_Ty6Mu53cV7OOb9tDCZi0tMfR8D9ALBVUd8V-cgQ9htod*

~/code/regex-scoring(master) $ go run main.go -tomlFile=anthrop.toml -debug
File to parse for rules: anthrop.toml
DIDN'T MATCH: aaaask-ant-gso30-ZTLOjnczGi200Ysvw78umKIQdQsQNDQP8ijchrbTUKZxiNoERhKOyRrGUsPUGpLhhjWP3q3TJ6KemTnbiUTPrW-9WS295gN
DIDN'T MATCH: aaaask-ant-gso30-ZTLOjnczGi200Ysvw78umKIQdQsQNDQP8ijchrbTUKZxiNoERhKOyRrGUsPUGpLhhjWP3q3TJ6KemTnbiUTPrW-9WS295gNaaaa
DIDN'T MATCH: sk-ant-gso30-ZTLOjnczGi200Ysvw78umKIQdQsQNDQP8ijchrbTUKZxiNoERhKOyRrGUsPUGpLhhjWP3q3TJ6KemTnbiUTPrW-9WS295gNaaaa
SCORE: 3 / 3 File: negative_scenarios Regex: \b(sk-ant-[a-z]{3}\d{2}-[A-Za-z0-9\-_]{86}-[A-Za-z0-9\-_]{8})(?:[[:punct:]]|[[:space:]]|[[:blank:]]|$) Token: sk-ant-gso30-ZTLOjnczGi200Ysvw78umKIQdQsQNDQP8ijchrbTUKZxiNoERhKOyRrGUsPUGpLhhjWP3q3TJ6KemTnbiUTPrW-9WS295gN
DIDN'T MATCH: _sk-ant-gso30-ZTLOjnczGi200Ysvw78umKIQdQsQNDQP8ijchrbTUKZxiNoERhKOyRrGUsPUGpLhhjWP3q3TJ6KemTnbiUTPrW-9WS295gN
SCORE: 51 / 52 File: positive_scenarios Regex: \b(sk-ant-[a-z]{3}\d{2}-[A-Za-z0-9\-_]{86}-[A-Za-z0-9\-_]{8})(?:[[:punct:]]|[[:space:]]|[[:blank:]]|$) Token: sk-ant-gso30-ZTLOjnczGi200Ysvw78umKIQdQsQNDQP8ijchrbTUKZxiNoERhKOyRrGUsPUGpLhhjWP3q3TJ6KemTnbiUTPrW-9WS295gN

What are the relevant issue numbers?

Add Anthropic API Key Pattern to Security Detec... (gitlab-org/gitlab#481547 - closed) • rossfuhrman • 17.4

Does this MR meet the acceptance criteria?

Edited by rossfuhrman

Merge request reports

Loading