Quick revision
The short answer
We stop relying on each developer by making the safe path the default path: shared starters ship auto-escaping templates, Jackson for JSON, a CSV export helper that neutralises formula prefixes such as =, +, - and @, and structured logging, so most code is safe without anyone thinking about it. We approve one encoder library, such as the OWASP Java Encoder, and ban hand-written escaping with static analysis, add SAST, DAST and hostile-input tests to every pipeline, train teams with our own incidents, and track findings per service so we fix systemic causes in the shared libraries first.
What to remember
In this answer, we saw that encoding bugs keep returning because each developer must remember context-specific rules. We made correct escaping the default through a shared starter with auto-escaping templates, Jackson, structured logging, a CSV helper that neutralises formula prefixes and a CSP header, approved one encoder and banned hand-written escaping with static analysis, added SAST, DAST and hostile-input tests to pipelines, trained teams with our own incidents and a review question about who interprets each value, and tracked findings so that systemic causes are fixed once in shared libraries.
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.
We stop relying on each developer by making the safe path the default path: shared starters ship auto-escaping templates, Jackson for JSON, a CSV export helper that neutralises formula prefixes such as =, +, - and @, and structured logging, so most code is safe without anyone thinking about it. We approve one encoder library, such as the OWASP Java Encoder, and ban hand-written escaping with static analysis, add SAST, DAST and hostile-input tests to every pipeline, train teams with our own incidents, and track findings per service so we fix systemic causes in the shared libraries first.
Why this question is asked
When the same class of vulnerability keeps returning across many services, the problem is no longer a missing skill in one team. It is a system that makes the unsafe option the easiest one. At 80 services and hundreds of developers, every rule that depends on memory will be forgotten somewhere every week. Interviewers ask this leadership question to see whether we can change the system rather than issue reminders. In this answer, we will see why individual discipline does not scale, then build the approach in layers: secure defaults, one approved encoder, automated tests, training and review, and measurement that tells us where to fix next.
1Why Individual Discipline Does Not Scale
Output encoding is hard to get right by hand because it depends on context. A value in HTML element content, in an HTML attribute, in a CSV cell and in a log line each needs different treatment, and a developer adding a quick admin page or a report export is thinking about the feature, not about how Excel interprets a cell that starts with an equals sign. If each of 80 services makes its own choices, the probability that all of them are right, all of the time, is close to zero. That is what our incident history already shows: XSS in admin pages, formula injection in exports and forged log lines are three different contexts that each team handled, or did not handle, on its own.
So the goal is to make correct encoding happen without a decision. A developer who uses our standard tools in the standard way should get safe output, and doing something unsafe should require an explicit, visible step that tools can flag.
2Secure Defaults in Shared Starters
Most of our services are Spring Boot applications, so the most effective place for defaults is a company starter, a dependency that configures things for every service that includes it. It brings Thymeleaf, which escapes output by default, and a lint rule against th:utext, the unescaped form. It configures one Jackson ObjectMapper, so nobody builds JSON by hand. It turns on structured JSON logging, which escapes control characters and makes log forging impossible. And it provides a CSV export helper, because CSV is the context teams most often forget.
- Company Spring Boot startertemplates, Jackson, logging, CSV helper, CSP
- One approved encoder libraryOWASP Java Encoder for edge cases
- Build rulesban hand-written escaping and unescaped output
- Pipeline testsSAST, DAST, hostile-input cases
- Peopletraining from our incidents, review checklist
5 layers, from the top down. Step through them one at a time.
The top layers make the safe path automatic; the lower ones catch what still gets through.
The starter also sets a strict Content-Security-Policy header for HTML pages, which limits the damage if an XSS bug still slips through. Notice that every one of these defaults removes a decision from the developer rather than adding a rule to remember.
3One Approved Encoder, No Hand-Written Escaping
Some code will always need to encode by hand, for example when building an HTML email outside a template. For those cases we approve one library, typically the OWASP Java Encoder, because it has a method per context, such as forHtml, forHtmlAttribute, forJavaScript and forUriComponent, and it is well tested. Hand-written escape helpers are banned, because each is a guess about an interpreter's rules. We enforce this with static analysis: a Semgrep or forbidden-apis rule flags new methods with names like escapeHtml in our code, calls to unescaped template output, and string concatenation flowing into known sinks. A finding fails the build, and an exception needs a reviewed suppression with a reason.
4Security Tests in Every Pipeline
Defaults and bans prevent most problems; tests find the rest. Static application security testing, such as CodeQL, Semgrep or Sonar rules, traces data from request parameters to sinks such as HTML output, SQL and logs, and runs on every pull request. Dynamic testing, with a scanner such as OWASP ZAP, runs against deployed admin pages in a test environment, because admin pages are exactly where teams skip reviews and where we have had incidents. Finally, a shared test library gives teams a list of hostile inputs, script tags, attribute breakers, formula prefixes, CR and LF, quotes and backslashes, so writing a test that feeds them through an endpoint and checks the output takes one line.
5Training and Review From Our Own Incidents
Generic security training is easy to forget. Our own incidents are not: a short session that shows the actual admin page, the actual payload and the actual fix is far more convincing than a slide about XSS. After each incident, a blameless review asks why the safe path was not the easy path, and the answer usually becomes a change to the starter. In code review, one checklist question does most of the work: where does this value end up, and what will interpret it there? If the answer is HTML, CSV, a log, SQL or a shell, the reviewer checks that the standard tool is used.
6Measure, and Fix Root Causes Centrally
We track findings from scans, reviews and incidents per service and per category. That data tells us where to invest. If twelve services have CSV injection findings, the answer is not twelve tickets; it is fixing or adding the helper in the starter and upgrading those services. We also track adoption, the share of services on the current starter version, and use automated dependency update pull requests, for example from Renovate or Dependabot, so a security fix in the starter reaches all 80 services within days, with a deadline for teams that do not merge.
- Finding reportedscan, review, pen test or incident
- Does the same cause exist in other services?YesFix it in the starter or shared libraryNoFix it in the service
- Add a rule or test that catches itso it cannot return
- Roll out with automated upgrade PRstrack adoption until done
4 steps in order. Play them, or step through them one at a time.
7Follow-up questions
What is CSV formula injection and how do you prevent it?
Spreadsheet programs such as Excel, LibreOffice and Google Sheets treat a cell that starts with =, +, - or @, and in some programs a tab or carriage return, as a formula. If an export contains user-controlled text, an attacker can enter a value like =HYPERLINK(...) that sends data from the sheet to their server when clicked, or in older setups even runs commands. The person opening the export, often an administrator, is the victim. The prevention is to neutralise those leading characters, usually by prefixing the cell with a single quote so the program shows it as text, and to quote every field and double inner quotes. The trade-off is that legitimate values starting with a minus, such as negative numbers, need care, so the helper applies the prefix to text columns and writes numeric columns from typed numbers.
How do you get 80 teams to adopt the starter?
By making it the easiest path rather than a mandate alone. New services are generated from a template that already includes it, the starter removes configuration teams would otherwise write, and upgrades arrive as automated pull requests that teams only need to merge. For security fixes we add a clear deadline and a dashboard of which services are behind, and platform engineers help the few services with unusual setups. Teams adopt shared libraries that save them work; they resist ones that only add rules.
Is a Content-Security-Policy enough to stop XSS?
It is a strong second line, not a replacement. A strict CSP that forbids inline scripts and limits script sources stops most injected scripts from running, even when escaping fails. But it does not stop HTML injection that changes page content, it can be weakened by exceptions teams add for convenience, and it does nothing for CSV, logs or SQL. So we use it as defence in depth on top of correct encoding.
8Conclusion
In this answer, we saw that encoding bugs keep returning because each developer must remember context-specific rules. We made correct escaping the default through a shared starter with auto-escaping templates, Jackson, structured logging, a CSV helper that neutralises formula prefixes and a CSP header, approved one encoder and banned hand-written escaping with static analysis, added SAST, DAST and hostile-input tests to pipelines, trained teams with our own incidents and a review question about who interprets each value, and tracked findings so that systemic causes are fixed once in shared libraries.
Open with
If the same encoding bugs keep coming from 80 services, the system makes the unsafe path the easy one, so reminders won't fix it. I'd make correct escaping the default.
Then, if they want more
First, a shared Spring Boot starter: Thymeleaf with auto-escaping and a lint rule against th:utext, one Jackson ObjectMapper so nobody builds JSON by hand, structured JSON logging so control characters are escaped and log forging is impossible, a CSV export helper that quotes every field and neutralises cells starting with equals, plus, minus or at, and a strict Content-Security-Policy as a second line.
Second, one approved encoder, the OWASP Java Encoder, for the cases templates don't cover, and a static analysis rule that bans hand-written escape helpers and unescaped output.
Third, security tests in every pipeline: SAST rules that trace request data to sinks, DAST scans like OWASP ZAP against admin pages, which is where we've had incidents, and a shared library of hostile inputs so testing an endpoint takes one line.
Fourth, people: short training built from our own incidents, and one review question, where does this value end up and what interprets it there.
Finally, I'd track findings per service and category, and when several services share a cause, fix it once in the starter and roll it out with automated upgrade pull requests and a deadline, watching adoption on a dashboard until every service is current.
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
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
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 "Across 80 services, security incidents keep coming from wrong or missing output...": https://scrivio-interview-library.netlify.app/java/strings/4ec85e1d9a/