Skip to content

Commit 0274912

Browse files
committed
- Added US passport number detector
1 parent fc50b07 commit 0274912

4 files changed

Lines changed: 463 additions & 4 deletions

File tree

docs/supported_inventory_types.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,11 @@ See the docs on [how to add a new Extractor](/docs/new_extractor.md).
216216
| HTTP CSRF Token | `secrets/csrftoken` |
217217

218218
### Sensitive information
219-
| Type | Extractor Plugin |
220-
| ------------------------------------------- | ------------------------------------ |
221-
| International Bank Account Number | `sensitiveinformation/iban` |
222-
| US Social Security Number | `sensitiveinformation/ssn` |
219+
| Type | Extractor Plugin |
220+
| ------------------------------------------- | ---------------------------------------- |
221+
| International Bank Account Number | `sensitiveinformation/iban` |
222+
| US Passport Numbers | `sensitiveinformation/uspassportnumber` |
223+
| US Social Security Number | `sensitiveinformation/ssn` |
223224

224225
### Container inventory
225226

extractor/filesystem/list/list.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ import (
186186
"github.com/google/osv-scalibr/veles/secrets/vapid"
187187
"github.com/google/osv-scalibr/veles/sensitiveinformation/iban"
188188
"github.com/google/osv-scalibr/veles/sensitiveinformation/ssn"
189+
"github.com/google/osv-scalibr/veles/sensitiveinformation/uspassportnumber"
189190

190191
cpb "github.com/google/osv-scalibr/binary/proto/config_go_proto"
191192
)
@@ -459,6 +460,7 @@ var (
459460
SensitiveInformationDetectors = initMapFromVelesPlugins([]velesPlugin{
460461
{iban.NewDetector(), "sensitiveinformation/iban", 0},
461462
{ssn.NewDetector(), "sensitiveinformation/ssn", 0},
463+
{uspassportnumber.NewDetector(), "sensitiveinformation/uspassportnumber", 0},
462464
})
463465

464466
// Secrets contains both secret extractors and detectors.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright 2026 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Package uspassportnumber implements logic for detecting US passport numbers
16+
package uspassportnumber
17+
18+
import (
19+
"bytes"
20+
"regexp"
21+
22+
"github.com/google/osv-scalibr/veles"
23+
"github.com/google/osv-scalibr/veles/sensitiveinformation"
24+
"github.com/google/osv-scalibr/veles/sensitiveinformation/common/simpleregex"
25+
)
26+
27+
const (
28+
maxPassportNumberLen = 9
29+
maxKeywordLen = 20
30+
contextWindowSize = 32
31+
)
32+
33+
var (
34+
keywordsRe = simpleregex.KeywordsRe([]string{
35+
`pass`,
36+
`passport`,
37+
`travel`,
38+
`doc`,
39+
`document`,
40+
})
41+
passportNumberRe = regexp.MustCompile(`\b[A-Za-z][0-9]{8}\b`)
42+
)
43+
44+
// NewDetector returns a Detector, that finds US Passport Numbers
45+
func NewDetector() veles.Detector {
46+
return simpleregex.Detector{
47+
MaxLen: max(maxKeywordLen, maxPassportNumberLen),
48+
Re: passportNumberRe,
49+
KeywordsRe: keywordsRe,
50+
ContextWindowBefore: contextWindowSize,
51+
ContextWindowAfter: contextWindowSize,
52+
FromMatch: func(blob []byte, keywordMatch bool) (sensitiveinformation.SensitiveInformation, bool) {
53+
likelihood := sensitiveinformation.LikelihoodUnlikely
54+
if keywordMatch {
55+
likelihood = sensitiveinformation.LikelihoodLikely
56+
}
57+
58+
return sensitiveinformation.SensitiveInformation{
59+
InfoType: sensitiveinformation.InfoType{
60+
Name: "US_PASSPORT_NUMBER",
61+
Sensitivity: sensitiveinformation.SensitivityLevelHigh,
62+
},
63+
Likelihood: likelihood,
64+
Raw: bytes.Clone(blob),
65+
}, true
66+
},
67+
}
68+
}

0 commit comments

Comments
 (0)