Invoke-DbaDbPiiScan - Fix broken PII patterns, add Nordic known names, and proposals for metadata-only scan and native classification
Los mantenedores suelen responder en 2 días
@nltgpeterskoglund ya está trabajando en esto.
Desde el 20/11/2026.
- #10862 de @nltgpeterskoglund — abierto
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- powershell
- Área
- databases
Línea de trabajo
Start with bin/datamasking/pii-patterns.json and bin/datamasking/pii-knownnames.json, then read the PII scan tests in tests/Invoke-DbaDbPiiScan.Tests.ps1. The issue describes ready branches for pattern fixes and Nordic aliases, with synthetic cases and expected matches to guide the changes. Run the named tests; done means the listed patterns match valid samples, Nordic column names are recognized, and the stated false positives are not.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Summarize Functionality
I would like to contribute to the PII scan and data classification commands, so that they can be used for GDPR work, also against production, without reading row data.
- Bug fix: several shipped data patterns in
bin/datamasking/pii-patterns.jsonnever match valid values. I have a branch ready. - Enhancement: Swedish, Norwegian, Danish and Finnish column names in
bin/datamasking/pii-knownnames.json, including a known-name rule for national IDs. I have a branch ready. - Proposals I would like your direction on before I write code, as CONTRIBUTING asks:
- a metadata-only mode and protection status for
Invoke-DbaDbPiiScan; - a native store (
sys.sensitivity_classifications) for*-DbaDbDataClassification; - a new
Get-DbaDbUnmaskPermission.
- a metadata-only mode and protection status for
Is there a command that is similiar or close to what you are looking for?
Yes
Technical Details
1. Bugs in pii-patterns.json (branch ready)
I checked the shipped patterns with synthetic values, using -match the same way Invoke-DbaDbPiiScan does:
| Pattern | Problem | Synthetic value | Matches today |
|---|---|---|---|
| Creditcard (All) | Uses \\| (a literal pipe) instead of | (alternation), so only AMEX can match |
4111111111111111, 5555555555554444 |
No |
| Website (All) | Same \\| problem in the scheme alternation |
https://example.com/page |
No |
| National ID (US) | The trailing \b is a JSON backspace character. \2 refers to the inner ([0-6]\d) group, not the separator. |
123-45-6789 |
No |
| Zipcode (DE) | The trailing \b is a JSON backspace character |
10115 |
No |
| National ID (FR) | The opening [ is missing (1,2][), and []? is an empty class |
1 85 05 78 006 084 36 |
No |
| National ID (PL) | Typo [0-9} |
44051401359 |
Yes, by accident |
| National ID (FI) | No support for the century signs added in 2023 (Y X W V U, B C D E F) |
010594Y9032 |
No |
| National ID (SE) | Only YYMMDD-NNNN. It misses the 12-digit form and accepts any month or day. |
191212121212 / 20231301-1234 |
No / Yes |
| IBAN Number "with spaces" (All) | The pattern is identical to the "without spaces" entry | SE45 5000 0000 0583 9825 7466 |
No |
| National ID (Bulgaria) | The CountryCode is Bg. ISO 3166 is BG. -CountryCode filtering is case-insensitive, so the fix is not breaking. |
n/a | n/a |
The SE pattern deliberately does not match 10 digits without a separator, because that collides with Swedish mobile numbers (07xxxxxxxx). The fixed US pattern requires a separator for the same reason: without one, it matches every 9-digit number.
2. Nordic known names (branch ready)
- Current gap: the known names cover English, German, French, Spanish and Dutch, but no Nordic languages. There is no known-name rule for national IDs at all.
- What I add:
- Nordic aliases to the existing entries: First name, Last name, Date, Gender, E-mail, Nationality, Address, City, Phone and Zipcode;
- a new entry, "National ID": personnummer, samordningsnummer, fødselsnummer, CPR, henkilötunnus.
- Encoding: every non-ASCII alias also has an ASCII form, the same way as
Staatsangehörigkeit|Staatsangehorigkeit, because Windows PowerShell reads the file as ANSI. - Tests: a new UnitTests context in
tests/Invoke-DbaDbPiiScan.Tests.ps1covers:- no duplicate patterns, no control characters, ISO country codes;
- Nordic names found, and the false positives
Reposted,Konto,Ikon,CprStatusandHetupdatenot found; - every data pattern in the table above.
- Local result: 52 passed, 0 failed in Windows PowerShell 5.1 and PowerShell 7.
Invoke-DbatoolsFormatterleaves the file unchanged.
3. Known issue, not in the branch: \\| in known-name patterns
- The problem: many of the second-line known-name patterns use
\\|as well, e.g.(?>dob\\|dtofb\\|...)and((tele?)?phone)\\|(co?nta?ct..., so they never match. - Why I left them alone: turning them into real alternation would start new matches, some of them false positives (e.g.
b_?(date?|day)matchesJobDate). - Related false positives that already exist, because the first-line patterns are not anchored:
pass→ Password matchesPassengerCountandPassportTypeId;ip→ IPAddress matchesTripId,DescriptionandShipDate;land→ Country matchesIslandCode.
- Question: would you accept a separate PR that fixes these one at a time, with tests?
4. Proposal: metadata-only scan and protection status in Invoke-DbaDbPiiScan
Today the scan reads TOP (SampleCount) rows from every column. For GDPR work, reading production data is often not acceptable at all. I would like to add:
-SkipDataScan: only data type, column name and classification are used, and no rows are read.- Classification as a source:
FoundWith = 'Classification', read fromsys.sensitivity_classifications(SQL Server 2019+ and Azure SQL), or from the SSMS extended properties used byGet-DbaDbDataClassificationon older versions. - New output properties:
IsMasked(sys.masked_columns);IsEncrypted(Always Encrypted);RowCount;SensitivityLabelandInformationType.- With these, the output shows which findings are already protected.
- Fixes along the way:
- The sample query uses
-SqlInstance $instance, which opens a new connection per column. It could reuse the$serverconnection. - Identifiers are wrapped in
[...]without escaping]. - When
-Databaseis not given, the scan could cover all accessible user databases, with-ExcludeDatabase.
- The sample query uses
- No breaking changes: existing parameters and properties stay as they are.
5. Proposal: native store in Get-, Set- and Remove-DbaDbDataClassification (follow-up to #6316)
- The gap: the commands from #6316 use extended properties. Defender for SQL, Purview and SQL Audit (
data_sensitivity_information) readsys.sensitivity_classifications. - New parameter:
-Store Native|ExtendedProperty|Auto.Automeans native on SQL Server 2019+ and Azure SQL, otherwise extended properties. - Native store:
- write with
ADD SENSITIVITY CLASSIFICATION ... WITH (LABEL, LABEL_ID, INFORMATION_TYPE, INFORMATION_TYPE_ID, RANK); - remove with
DROP SENSITIVITY CLASSIFICATION; - read from
sys.sensitivity_classifications.
- write with
- Also:
-Rank, for the native store only;-InputObject, so findings fromInvoke-DbaDbPiiScancan be piped in.
- Open question: should
Autobecome the default, or should the extended-property behavior stay the default for compatibility?
6. Proposal: new command Get-DbaDbUnmaskPermission
- What it does: lists the principals that can read data unmasked when Dynamic Data Masking is in use, through any of:
UNMASKat database, schema, object or column level (granular UNMASK, SQL Server 2022 and Azure SQL);CONTROLon the database;db_owner, including through nested role membership;sysadminorCONTROL SERVER.
- Output:
ComputerName,InstanceName,SqlInstance,Database,Principal,PrincipalType,Source,Scope,Via. - Why a new command:
Get-DbaPermissionshows explicit grants, but it does not resolve nested roles into effective UNMASK. I could not find an existing command that covers this. If you prefer, I can open it as a separate "New Command" issue.
Your direction
- Are you OK with items 1 and 2 as one PR (rule files and tests), or would you prefer two?
- Do items 4, 5 and 6 fit the module, and do you agree with the parameter and command names?
- Lenguaje dominante
- PowerShell
- Estrellas
- 2.9k
- Forks
- 869
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 38
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de dataplat/dbatools
-
bugs life triage required
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Los mantenedores suelen responder en 2 días
-
bugs life triage required
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 2 días
-
bugs life triage required
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
dataplat/dbatools#10860 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
bugs life Chrissy needed
Dificultad 3/5 Medio día Aptitud para principiantes 38/100
Los mantenedores suelen responder en 2 días
-
Dificultad 3/5 1-2 días Aptitud para principiantes 42/100
Los mantenedores suelen responder en 2 días
Todos los issues de dataplat/dbatools
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
kagent-dev/kagent#3789 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Los mantenedores suelen responder en 1 día
-
metaskirando
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día
-
bug vector-store
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día