Quick revision
The short answer
In the database, support roles read through views or column privileges that show only masked values, and only privileged flows can read full values. In the application, DTOs for support roles mask by default and an explicit, audited reveal action shows a full value when there is a reason. In the logs, request bodies are never logged by default, masking patterns and tests catch anything that slips, and existing log stores are scrubbed. Card numbers are tokenised with the payment provider so the service never stores raw card numbers, and fields are classified as PII so tools can apply these rules automatically.
What to remember
In this answer, we added controls at each layer where personal data was spreading. The database gives support a masked view and column privileges, the application masks support DTOs by default and offers an audited reveal action, and the logs drop request bodies, use masking patterns as a safety net, are tested with known values and are scrubbed retroactively. Card numbers are tokenised by the payment provider so the service never stores them, and classifying fields as PII lets the view generator, serializers, log masking and CI checks apply the rules automatically.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
In the database, support roles read through views or column privileges that show only masked values, and only privileged flows can read full values. In the application, DTOs for support roles mask by default and an explicit, audited reveal action shows a full value when there is a reason. In the logs, request bodies are never logged by default, masking patterns and tests catch anything that slips, and existing log stores are scrubbed. Card numbers are tokenised with the payment provider so the service never stores raw card numbers, and fields are classified as PII so tools can apply these rules automatically.
Why this question is asked
A support tool that shows everything and logs that contain card numbers are two faces of the same problem: personal data spreading to places with many readers and few controls. A support team may have hundreds of agents, and logs are read by every engineer, copied into ticket attachments and kept for months. Interviewers ask this scenario to see whether we can put controls at each layer without making support impossible. In this answer, we will recap what counts as sensitive here, then add controls in the database, the application and the logs, deal with card numbers and PCI scope, and finish with classification so the rules apply themselves.
1A Quick Recap of the Data and the Risks
Personal data, or PII, is any information that identifies a person: names, emails, phone numbers, addresses. Card numbers, also called PANs for primary account numbers, are a special case governed by the PCI DSS standard, which requires that full card numbers are stored only when necessary, protected strongly, and never written to logs. The principle behind every control below is data minimisation: each reader sees the least data needed for the task. A support agent resetting a delivery address needs the address, not the full email and card number.
- Support tool UImasked by default, reveal button with reason
- Application DTOsrole-based masking, audited reveal endpoint
- Loggingno bodies, masking patterns, tests
- Databasemasked views and column privileges for support
- Payment providerholds card numbers, we store tokens only
5 layers, from the top down. Step through them one at a time.
Each layer limits what the next one can leak.
2Controls in the Database
The support tool should not connect with a role that can read every column. We give support a role that reads through a view with masked columns, and column privileges make sure it cannot read the base table's sensitive columns directly.
The view runs with its owner's privileges, so support_ro can read the masked result without any access to the underlying table. Where a view is too coarse, PostgreSQL also supports column-level grants such as GRANT SELECT (id, first_name, city) ON app.customers TO support_ro, which make any query touching other columns fail. Full values remain readable only by the service's own role, used by specific privileged flows.
3Controls in the Application
The support tool usually talks to a backend service, so that is where most of the masking belongs. The service returns a support DTO in which sensitive fields are masked unless the caller has performed a reveal.
Masking by default means an agent who just browses records never sees full values. The reveal action is deliberate: it needs a role, a reason such as a ticket number, it returns a single field, and it writes an audit event, so unusual patterns, such as one agent revealing 300 emails in an hour, can be alerted on. The @Pii annotation here is our own marker that a Jackson serializer reads to apply the mask, which keeps the rule next to the field.
4Controls in the Logs
Logging request bodies is the most common way card numbers and emails end up in logs. The first control is simply not to do it: request and response payload logging is off by default, and only metadata such as method, path, status, duration and request id is logged. Spring's request logging filters and libraries such as Logbook have switches for payloads; we make sure they are off, or that bodies pass through a masking filter.
Patterns are only a safety net, because they miss formats like card numbers with spaces and can over-mask harmless numbers, so tests with known test card numbers and emails are what really keeps logs clean. Finally, the logs already written must be scrubbed: we search the log store for card-like and email-like values, delete or re-index the affected entries, and check downstream copies such as archives, because those old logs are still in PCI and privacy scope.
5Card Numbers Belong to the Payment Provider
The strongest control for card numbers is not to have them. With tokenisation, the card number goes from the customer's browser or app directly to the payment provider, through its hosted fields or SDK, and our service receives only a token that represents the card. The service stores and logs the token and perhaps the last four digits and expiry for display, never the full number, and the card security code is never stored at all. This takes most of our systems out of PCI scope, which reduces audit cost as well as risk, and the support tool can show the last four digits safely.
6Classify Fields So Tools Apply the Rules
Doing all this by hand for each field does not scale, and the next new column will be missed. So we classify fields as part of the schema: a column comment or catalog tag such as pii:email in the database, and the @Pii annotation on DTO fields in code. Tools then read the classification: the support view generator masks tagged columns, the Jackson serializer masks tagged fields, the log masking and the test-data masking pipeline use the same list, and a CI check fails when a new column holding personal data has no classification.
7Follow-up questions
Would dynamic data masking in the database be enough on its own?
No. It protects queries from the support role, but the service that reads full values can still log them or return them in an API. We need masking in the application and logs as well, because that is where most leaks happen.
How do you handle agents who genuinely need full values often?
Look at the task first; often a masked value plus a verify action, such as checking whether the email the caller gives matches, removes the need. For tasks that truly need full values, a specific role with reveal rights, reasons and monitoring is the answer, not unmasked access for everyone.
What do you do once card numbers are found in logs?
Treat it as an incident: stop the logging at the source, scrub the log store and its backups and archives, check who had access, and assess with the compliance team whether it must be reported under PCI rules.
8Conclusion
In this answer, we added controls at each layer where personal data was spreading. The database gives support a masked view and column privileges, the application masks support DTOs by default and offers an audited reveal action, and the logs drop request bodies, use masking patterns as a safety net, are tested with known values and are scrubbed retroactively. Card numbers are tokenised by the payment provider so the service never stores them, and classifying fields as PII lets the view generator, serializers, log masking and CI checks apply the rules automatically.
Open with
I would add controls in each layer. In the database, the support tool should not read the base tables; it gets a role with SELECT on a view that masks email and phone, and no privileges on the sensitive columns, or column-level grants that exclude them, so only privileged service flows can read full values.
Then, if they want more
In the application, the support API returns DTOs where sensitive fields are masked by default, driven by an annotation on the field, and there is an explicit reveal endpoint that needs a specific role and a reason, returns one field, and writes an audit event so we can alert on unusual reveal patterns.
For logs, I would turn off request body logging, log only metadata like path, status and request id, add masking patterns in the log layout as a safety net, and write tests that make a payment with a known test card and assert the logs do not contain it.
Existing log stores and archives need scrubbing, and I would treat that as an incident with compliance. Card numbers should not be in our systems at all: tokenise them with the payment provider so we only store tokens and last four digits, which also shrinks PCI scope.
Finally, classify fields as PII in the schema and code, so masking and checks apply automatically to new fields.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- PostgreSQL documentation, MySQL reference manual
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A support tool shows full customer records, and logs from a Java service include request...": https://scrivio-interview-library.netlify.app/databases/database-security/6973caef81/