Tim Retout: Prevent DOM-XSS with Trusted Types - a smarter DevSecOps approach
It can be incredibly easy for a frontend developer to accidentally
write a client-side cross-site-scripting (DOM-XSS) security issue, and
yet these are hard for security teams to detect. Vulnerability
scanners are slow, and suffer from false positives. Can smarter
collaboration between development, operations and security teams
provide a way to eliminate these problems altogether?
Google claims that Trusted
Types has all but eliminated
DOM-XSS exploits on those of their sites which have implemented
it. Let s find out how this can work!
DOM-XSS vulnerabilities are easy to write, but hard for security teams to catch
It is very easy to accidentally introduce a client-side XSS problem.
As an example of what not to do, suppose you are setting an element s
text to the current URL, on the client side:
DOM-XSS vulnerabilities are easy to write, but hard for security teams to catch
It is very easy to accidentally introduce a client-side XSS problem.
As an example of what not to do, suppose you are setting an element s
text to the current URL, on the client side:
// Don't do this
para.innerHTML = location.href;
Unfortunately, an attacker can now manipulate the URL (and e.g. send
this link in a phishing email), and any HTML tags they add will be
interpreted by the user s browser. This could potentially be used by
the attacker to send private data to a different server.
Detecting DOM-XSS using vulnerability scanning tools is challenging -
typically this requires crawling each page of the website and
attempting to detect problems such as the one above, but there is a
significant risk of false positives, especially as the complexity of
the logic increases.
There are already ways to avoid these exploits developers
should validate untrusted input before making use of it. There are
libraries such as DOMPurify
which can help with sanitization.1
However, if you are part of a security team with responsibility for
preventing these issues, it can be complex to understand whether you
are at risk. Different developer teams may be using different
techniques and tools. It may be impossible for you to work closely
with every developer so how can you know that the frontend
team have used these libraries correctly?
Trusted Types closes the DevSecOps feedback loop for DOM-XSS, by allowing Ops and Security to verify good Developer practices
Trusted Types enforces sanitization in the browser2, by requiring
the web developer to assign a particular kind of JavaScript object
rather than a native string to .innerHTML and other dangerous
properties. Provided these special types are created in an
appropriate way, then they can be trusted not to expose XSS
problems.
This approach will work with whichever tools the frontend developers have
chosen to use, and detection of issues can be rolled out by
infrastructure engineers without requiring frontend code changes.
Content Security Policy allows enforcement of security policies in the browser itself
Because enforcing this safer approach in the browser for all websites
would break backwards-compatibility, each website must opt-in through
Content Security Policy headers.
Content Security Policy (CSP) is a mechanism that allows web pages
to restrict what actions a browser should execute on their page, and a
way for the site to receive reports if the policy is violated.
Figure 1: Content-Security-Policy browser communication
This is revolutionary, because it allows servers to receive feedback
in real time on errors that may be appearing in the browser s console.
Trusted Types can be rolled out incrementally, with continuous feedback
Web.dev s article on Trusted Types
explains how to safely roll out the feature using the features of CSP itself:
- Deploy a CSP collector if you haven t already
- Switch on CSP reports without enforcement (via
Content-Security-Policy-Report-Only headers)
- Iteratively review and fix the violations
- Switch to enforcing mode when there are a low enough rate of reports
Static analysis in a continuous integration pipeline is also sensible
you want to prevent regressions shipping in new releases
before they trigger a flood of CSP reports. This will also give you a
chance of finding any low-traffic vulnerable pages.
Smart security teams will use techniques like Trusted Types to eliminate entire classes of bugs at a time
Rather than playing whack-a-mole with unreliable vulnerability
scanning or bug bounties, techniques such as Trusted Types are truly
in the spirit of Secure by Design build high quality in from
the start of the engineering process, and do this in a way which
closes the DevSecOps feedback loop between your Developer, Operations
and Security teams.
-
Sanitization libraries are especially needed when the examples
become more complex, e.g. if the application must manipulate the
input. DOMPurify version 1.0.9 also added Trusted Types support, so
can still be used to help developers adopt this feature.
-
Trusted Types has existed in Chrome and Edge since 2020, and
should soon be coming to
Firefox
as well. However, it s not necessary to wait for Firefox or Safari to
add support, because the large market share of Chrome and Edge will
let you identify and fix your site s DOM-XSS issues, even if you do
not set enforcing mode, and users of all browsers will benefit. Even
so, it is great that Mozilla is now on board.
// Don't do this
para.innerHTML = location.href;
.innerHTML and other dangerous
properties. Provided these special types are created in an
appropriate way, then they can be trusted not to expose XSS
problems.
This approach will work with whichever tools the frontend developers have
chosen to use, and detection of issues can be rolled out by
infrastructure engineers without requiring frontend code changes.
Content Security Policy allows enforcement of security policies in the browser itself
Because enforcing this safer approach in the browser for all websites
would break backwards-compatibility, each website must opt-in through
Content Security Policy headers.
Content Security Policy (CSP) is a mechanism that allows web pages
to restrict what actions a browser should execute on their page, and a
way for the site to receive reports if the policy is violated.
Figure 1: Content-Security-Policy browser communication
This is revolutionary, because it allows servers to receive feedback
in real time on errors that may be appearing in the browser s console.
Trusted Types can be rolled out incrementally, with continuous feedback
Web.dev s article on Trusted Types
explains how to safely roll out the feature using the features of CSP itself:
- Deploy a CSP collector if you haven t already
- Switch on CSP reports without enforcement (via
Content-Security-Policy-Report-Only headers)
- Iteratively review and fix the violations
- Switch to enforcing mode when there are a low enough rate of reports
Static analysis in a continuous integration pipeline is also sensible
you want to prevent regressions shipping in new releases
before they trigger a flood of CSP reports. This will also give you a
chance of finding any low-traffic vulnerable pages.
Smart security teams will use techniques like Trusted Types to eliminate entire classes of bugs at a time
Rather than playing whack-a-mole with unreliable vulnerability
scanning or bug bounties, techniques such as Trusted Types are truly
in the spirit of Secure by Design build high quality in from
the start of the engineering process, and do this in a way which
closes the DevSecOps feedback loop between your Developer, Operations
and Security teams.
-
Sanitization libraries are especially needed when the examples
become more complex, e.g. if the application must manipulate the
input. DOMPurify version 1.0.9 also added Trusted Types support, so
can still be used to help developers adopt this feature.
-
Trusted Types has existed in Chrome and Edge since 2020, and
should soon be coming to
Firefox
as well. However, it s not necessary to wait for Firefox or Safari to
add support, because the large market share of Chrome and Edge will
let you identify and fix your site s DOM-XSS issues, even if you do
not set enforcing mode, and users of all browsers will benefit. Even
so, it is great that Mozilla is now on board.
- Deploy a CSP collector if you haven t already
- Switch on CSP reports without enforcement (via
Content-Security-Policy-Report-Onlyheaders) - Iteratively review and fix the violations
- Switch to enforcing mode when there are a low enough rate of reports
Smart security teams will use techniques like Trusted Types to eliminate entire classes of bugs at a time
Rather than playing whack-a-mole with unreliable vulnerability
scanning or bug bounties, techniques such as Trusted Types are truly
in the spirit of Secure by Design build high quality in from
the start of the engineering process, and do this in a way which
closes the DevSecOps feedback loop between your Developer, Operations
and Security teams.
-
Sanitization libraries are especially needed when the examples
become more complex, e.g. if the application must manipulate the
input. DOMPurify version 1.0.9 also added Trusted Types support, so
can still be used to help developers adopt this feature.
-
Trusted Types has existed in Chrome and Edge since 2020, and
should soon be coming to
Firefox
as well. However, it s not necessary to wait for Firefox or Safari to
add support, because the large market share of Chrome and Edge will
let you identify and fix your site s DOM-XSS issues, even if you do
not set enforcing mode, and users of all browsers will benefit. Even
so, it is great that Mozilla is now on board.
- Sanitization libraries are especially needed when the examples become more complex, e.g. if the application must manipulate the input. DOMPurify version 1.0.9 also added Trusted Types support, so can still be used to help developers adopt this feature.
- Trusted Types has existed in Chrome and Edge since 2020, and should soon be coming to Firefox as well. However, it s not necessary to wait for Firefox or Safari to add support, because the large market share of Chrome and Edge will let you identify and fix your site s DOM-XSS issues, even if you do not set enforcing mode, and users of all browsers will benefit. Even so, it is great that Mozilla is now on board.
By the influencers on the famous proprietary video platform
Anyway, my brain suddenly decided that I needed a red wool dress, fitted
enough to give some bust support. I had already made a
I knew that I didn t have enough fabric to add a flounce to the hem, as
in the cotton dress, but then I remembered that some time ago I fell for
a piece of fringed trim in black, white and red. I did a quick check
that the red wasn t clashing (it wasn t) and I knew I had a plan for the
hem decoration.
Then I spent a week finishing other projects, and the more I thought
about this dress, the more I was tempted to have spiral lacing at the
front rather than buttons, as a nod to the kirtle inspiration.
It may end up be a bit of a hassle, but if it is too much I can always
add a hidden zipper on a side seam, and only have to undo a bit of the
lacing around the neckhole to wear the dress.
Finally, I could start working on the dress: I cut all of the main
pieces, and since the seam lines were quite curved I marked them with
tailor s tacks, which I don t exactly enjoy doing or removing, but are
the only method that was guaranteed to survive while manipulating this
fabric (and not leave traces afterwards).
While cutting the front pieces I accidentally cut the high neck line
instead of the one I had used on the cotton dress: I decided to go for
it also on the back pieces and decide later whether I wanted to lower
it.
Since this is a modern dress, with no historical accuracy at all, and I
have access to a serger, I decided to use some dark blue cotton voile
I ve had in my stash for quite some time, cut into bias strip, to bind
the raw edges before sewing. This works significantly better than bought
bias tape, which is a bit too stiff for this.
For the front opening, I ve decided to reinforce the areas where the
lacing holes will be with cotton: I ve used some other navy blue cotton,
also from the stash, and added two lines of cording to stiffen the front
edge.
So I ve cut the front in two pieces rather than on the fold, sewn the
reinforcements to the sewing allowances in such a way that the corded
edge was aligned with the center front and then sewn the bottom of the
front seam from just before the end of the reinforcements to the hem.
The allowances are then folded back, and then they are kept in place
by the worked lacing holes. The cotton was pinked, while for the wool I
used the selvedge of the fabric and there was no need for any finishing.
Behind the opening I ve added a modesty placket: I ve cut a strip of red
wool, a strip of cotton, folded the edge of the strip of cotton to the
center, added cording to the long sides, pressed the allowances of the
wool towards the wrong side, and then handstitched the cotton to the
wool, wrong sides facing. This was finally handstitched to one side of
the sewing allowance of the center front.
I ve also decided to add real pockets, rather than just slits, and for
some reason I decided to add them by hand after I had sewn the dress, so
I ve left opening in the side back seams, where the slits were in the
cotton dress. I ve also already worn the dress, but haven t added the
pockets yet, as I m still debating about their shape. This will be fixed
in the near future.
Another thing that will have to be fixed is the trim situation: I like
the fringe at the bottom, and I had enough to also make a belt, but this
makes the top of the dress a bit empty. I can t use the same fringe
tape, as it is too wide, but it would be nice to have something smaller
that matches the patterned part. And I think I can make something
suitable with tablet weaving, but I m not sure on which materials to
use, so it will have to be on hold for a while, until I decide on the
supplies and have the time for making it.
Another improvement I d like to add are detached sleeves, both matching
(I should still have just enough fabric) and contrasting, but first I
want to learn more about real kirtle construction, and maybe start
making sleeves that would be suitable also for a real kirtle.
Meanwhile, I ve worn it on Christmas (over my 1700s menswear shirt with
big sleeves) and may wear it again tomorrow (if I bother to dress up to
spend New Year s Eve at home :D )
Debian Public Statement about the EU Cyber Resilience Act and the Product Liability Directive
The European Union is currently preparing a regulation "on horizontal
cybersecurity requirements for products with digital elements" known as the
Cyber Resilience Act (CRA). It is currently in the final "trilogue" phase of
the legislative process. The act includes a set of essential cybersecurity and
vulnerability handling requirements for manufacturers. It will require products
to be accompanied by information and instructions to the user. Manufacturers
will need to perform risk assessments and produce technical documentation and,
for critical components, have third-party audits conducted. Discovered security
issues will have to be reported to European authorities within 25 hours (1).
The CRA will be followed up by the Product Liability Directive (PLD) which will
introduce compulsory liability for software.
While a lot of these regulations seem reasonable, the Debian project believes
that there are grave problems for Free Software projects attached to them.
Therefore, the Debian project issues the following statement:
The Emacs part is superceded by
This post describes how I m using
Over roughly the last year and a half I have been participating as a reviewer in
ACM s
This is a post I wrote in June 2022, but did not publish back then.
After first publishing it in December 2023, a perfectionist insecure
part of me unpublished it again. After receiving positive feedback, i
slightly amended and republish it now.
In this post, I talk about unpaid work in F/LOSS, taking on the example
of hackathons, and why, in my opinion, the expectation of volunteer work
is hurting diversity.
Disclaimer: I don t have all the answers, only some ideas and questions.































