My Code Scanner Never Opened My Astro Files
The security tab on this blog's repository has shown the same thing for 68 days: zero. Back in late September, the day I closed twenty findings, reaching that number felt good. Two months later, it has started to feel a
The security tab on this blog's repository has shown the same thing for 68 days: zero. Back in late September, the day I closed twenty findings, reaching that number felt good. Two months later, it has started to feel a little too good.
That earlier piece was about a fix getting less scrutiny than the code it fixed. This one is not about what the tool found but about what it read. Because this week I sat down and asked: what exactly is this zero based on? I pulled the database the scanner builds from my repository and looked inside. One hundred and five of my files are not in it — every file that renders this site's pages and components is missing.
Two months, not one finding
I pulled the repo's entire scan history. First analysis: 28 September, 07:40. Most recent: 4 December, 11:30. In between, 889 analyses — 445 on the JavaScript/TypeScript side with 87 rules, 444 on the workflow side with 17 rules. Both run on every push to main, with a weekly scheduled run on top.
$ gh api --paginate ".../code-scanning/analyses?per_page=100" \
--jq '.[] | "\(.created_at)|\(.category)|\(.results_count)"' \
| awk -F'|' '$3 != 0' | wc -l
19
Nineteen analyses with findings. All of them on 28 September, the day the scan was switched on. The last run with a finding ended at 17:26 that day; every one of the 869 analyses since then came back zero — 435 on the JavaScript side, 434 on the workflow side.
There are two possibilities here. One: I cleaned house in a single day and wrote carefully afterwards. Two: the counter is right about where it looks, but where it looks is not where I think. I am too old a programmer for the first one — this blog carries a dozen posts from those same two months describing my own mistakes.
I pulled the database and opened it
A code scan does not read your source directly. It converts the code into a database first, and the queries run against that database. The good part: the database is downloadable. On my repo the JavaScript side is a 9 MB zip, and inside it sits src.zip — a copy of the source files the extractor actually read and processed. So the answer to "what did you look at" is as concrete as a directory listing, and two commands away.
$ gh api ".../code-scanning/codeql/databases/javascript" \
-H "Accept: application/zip" > js-db.zip
$ unzip -l extracted/javascript/src.zip | awk '{print $4}' \
| sed 's/.*\.//' | sort | uniq -c | sort -rn
112 js
88 ts
68 mjs
22 yml
20 tsx
5 json
2 html
317 files. First surprise: 110 of them are not mine. They are externs files from the extractor's own installation directory — type stubs it carries so it can recognise browser and ECMAScript APIs, 55,438 lines of them. My own code is 207 files and 34,370 lines. The baggage a tool carries to understand your code can outweigh the code.
The second surprise was what the list did not have. Not a single file with an .astro extension.
$ unzip -l extracted/javascript/src.zip | grep -c '\.astro$'
0
There are 105 of them in the repo. 18,100 lines in total.
The extension list has .vue but not .astro
This is not a malfunction. It is a documented boundary. Which extensions the extractor reads is written down: on the JavaScript side .js, .jsx, .mjs, .es, .es6, .htm, .html, .xhtm, .xhtml, .vue, .hbs, .ejs, .njk, .json, .yaml, .yml, .raml, .xml; on the TypeScript side .ts, .tsx, .mts, .cts.
Look at that list carefully. .vue is there, and so are Handlebars, EJS and Nunjucks templates. .astro is not. Neither is .svelte.
So this is no special snub aimed at Astro. The list stopped somewhere: the template formats on it describe the web of the mid-2010s, and what came later never joined. Popularity does not explain it either — Svelte is more widely used than Nunjucks, yet Nunjucks is the one on the list. From where I stand the outcome is unchanged: part of my repo sits behind an extension filter.
The asymmetry showed up in one more place. The same documentation counts, among its modelled data sources, a class for "inputs to a React, Vue, or Angular component" and says it is only used by JavaScript/TypeScript analysis. A Vue component's props are a named data source in the tool's eyes. My page's props are not even a filename.
The tool is not lazy either. All 35 scripts/*.ts files, all 62 scripts/*.mjs files, all 52 TypeScript files under src/ are in that database. What it does not read is a file extension.
My workflows have no such gap
For comparison I pulled the second database too. The workflow side is 196 KB; it holds 17 files, and those 17 are every single file under .github/workflows/. Nothing missing.
Then I laid the two listings on top of each other and things got slightly comical. Of the 22 .yml files in the JavaScript database, 17 are those same .github/workflows/ files — because .yml sits both on the JavaScript extractor's extension list and in the workflow extractor's own territory.
$ grep -c 'workflows/.*\.yml$' srclist.txt # JS database
17
$ unzip -l ex_actions/actions/src.zip | grep -c 'workflows/'
17
Those 2,990 lines of workflow enter two separate databases on every run, queried once with 87 rules and once with 17. The same files are read twice while 105 of mine are not read at all. Nobody designed it that way, of course; two extractors' extension lists overlap, that is all. But I could not find a better illustration of why looking for a single "total" in a coverage table is the wrong move.
What is actually in those 105 files
I could have said "they're template files, there's no code in them". I counted, and I cannot say that.
Ninety-seven of the 105 files have a non-empty frontmatter block; those server-side blocks come to 3,797 lines. Seventeen files read the request directly — twelve through Astro.params, five through Astro.url.searchParams. Fifty-five contain a <script> block that runs in the browser. And twelve call set:html, which prints a value into HTML as-is.
Astro's own documentation is perfectly clear about set:html: the value is not automatically escaped by Astro, you need to be sure you trust it or that you have escaped it manually, and forgetting that opens you up to XSS. This is a place that asks for care — not as a rumour, but in the framework's own words.
The one place strangers can type
Rather than stop at counting, I traced by hand the single path inside these 105 files where text from outside actually travels: the comments component. A reader's comment text is turned into markdown in the browser, and the result is written to the page with innerHTML.
function esc(s) { var d = document.createElement('div'); d.textContent = s; return d.innerHTML; }
function md(t) {
return esc(t).replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
/* ... */ .replace(/\n/g, '<br>');
}
Good news: md opens with esc, so the text goes through a textContent round trip and is escaped before any markdown transform touches it. The tags that survive are only the ones I generate. This path holds up today, and the only reason I can state that is that I sat down and read it.
The real point is who did the reading. The repo's one path for untrusted input sits in a file the scan never opens. Finding it correct was a relief; the method is still not one.
Five are escaped, five are not
There are ten places where JSON.stringify output is printed inside a <script> tag — six in pages, four in components. In five of them I had escaped the < character by hand:
<script is:inline type="application/ld+json"
set:html={JSON.stringify(schema).replace(/</g, '\\u003c')} />
In five of them I had not:
<script is:inline type="application/ld+json"
set:html={JSON.stringify(faqSchema)}></script>
Same repo, same purpose, dates close together. I cannot defend the difference as a decision; it was a lapse in attention. And the only reason I can call it that is that I sat down and counted for this post.
It does not amount to a hole today: the data feeding those five places comes from my own content, and no outside text gets to slip a </script> into the middle of it. But the side meant to tell "cannot be exploited today" apart from "written correctly" was the scan. One more note: the example in Astro's own documentation also prints JSON.stringify output into a <script> without escaping. I did not invent the habit single-handedly.
There is a separate line in the FAQ component: it turns newlines in answers into <br> tags and prints the result with set:html, applying no escaping at all. What was on my mind when I wrote it was not "does this need escaping" but "don't lose the line breaks" — and the code does precisely what was on my mind. The fix is easy: escape first, then replace; or drop the <br> and use white-space: pre-line.
What changed in the window where the counter went quiet
Taking the commit right after the last finding as a base, here is how the code moved up to today: 431 commits.
$ git diff --numstat b0d9c10c..origin/main # code extensions only
.astro +3130 -5729 (50 files)
.mjs +915 -322 ( 9 files)
.ts +40 -16 ( 3 files)
That table deserves an honest reading. More than three quarters of the added code lines went into files the scan never opens — but 5,729 lines were also deleted from those same files, so the template surface shrank on net. And extensions like .json, .css and .sh are absent from the table; fold those in and .astro's share drops to 41%.
What does not change: the TypeScript surface the scan can see moved by 40 lines in two months, while the template surface it cannot see saw nine thousand lines of traffic. The counter said "zero" 869 times in that window and told the truth every time — about the part that barely moved.
The tool does nothing wrong in this story. It wrote down what it reads, it does not pretend to read what it skips, it does not stop me from downloading the database, and it hands me a copy of every file it put in there. The incomplete question was mine.
Back in October I deliberately broke six rules and watched all ninety-three tests stay green; the lesson there was that a test count is an inventory. What gets measured here is not a count but a boundary: the tests were giving a wrong answer, while the scan gives a correct answer about a narrow area. In one case the tool's verdict was faulty; in the other the verdict is sound and I never read its scope.
Second blind spot: which input counts as suspect
I pulled the repo's scan settings from the API:
$ gh api ".../code-scanning/default-setup"
{"state":"configured","languages":["actions","javascript",...],
"query_suite":"default","threat_model":"remote", ...}
threat_model: remote. That setting answers "which data will I treat as suspect". The default model treats only what arrives over the network as suspect; the other model, in the documentation's own example list, also covers command-line arguments, environment variables, file systems and databases.
Most of the 28 September findings were under scripts/. Every script there is fed by arguments, environment variables and file reads; the pipeline that produces articles, translates them and posts to social runs exactly that way. The directory where the findings came from works with the very inputs the default model does not treat as suspect.
So what happens if I flip that switch? The documentation contradicts itself, clearly enough to read. The code scanning pages say in two separate places that "during the public preview, threat models are supported only by analysis for Java/Kotlin and C#", and add that the row in the interface only appears for those languages. CodeQL's own page on customizing JavaScript library models says that "during the beta, threat models are supported only by Java, C#, Python and JavaScript/TypeScript analysis". Same company, two documents, one feature, two different language lists. And my repo is a JavaScript repo, and the API hands me back not an empty field but the value remote.
The documentation cannot tell me whether turning it on would do anything. That needs an experiment and a measurement, and I am publishing this post without having run it.
A half-hour check for your own repo
All of this is reading work; not one step touches the repository.
Read the scan's configuration. gh api repos/<owner>/<repo>/code-scanning/default-setup tells you which languages, which query suite and which threat model it runs with. On advanced setup the answer is in your workflow file.
Count the analysis history. How many analyses have come back zero since the last one with a finding? If that number is large there are two explanations, and only the next step can tell them apart.
Download the database and list what is in src.zip. Count by extension and compare against the file counts in your repo. The gap is the blind spot the scan never mentioned to you.
Count what is in the files that got left out, then trace the riskiest one by hand. I ran grep -rln for the counts and read the one path untrusted input travels; together it took half an hour.
If you are on a newer framework — especially one whose name appeared in the last decade — run this check the day you switch scanning on. Once the tool starts showing green, you stop asking.
What I am doing about it
Four options, and none substitutes for another.
Widening the query suite is the easiest: security-extended, in the documentation's phrasing, adds "lower severity and precision queries" on top of the default suite. It does not make an unread file readable; it means asking more questions of the same 207 files.
Moving logic out of the page and into a .ts module is the only option that genuinely grows coverage. I already do this in part: all 15 endpoints under src/pages/api/ are .ts and all of them are in the database.
Scanning the compiled output. The database I downloaded says buildMode: none in its own metadata — the source tree was read as-is, nothing compiled. Yet this site builds with @astrojs/node, and the server output is dist/server/entry.mjs, an extension the extractor does read. An advanced setup with a build step could put the logic inside those templates in front of the scan. I have not tried it; that is the most concrete open item in this post.
Collecting the escaping in one place. I will wire the ten JSON.stringify sites through a shared helper. Let me be honest about this one: it does not make the code visible to the tool — the set:html call, the part that matters, stays in an unread file. The only thing it buys is that a five-escape, five-no-escape split cannot happen again. Not sufficient, but cheap.
I am not giving a date, because I learned by counting how many of the promises I make on this blog are still open. What I can write down: the price of learning a tool's coverage was, in this repo, downloading one zip and running unzip -l. I did not do it for two months because nothing ever prompted the question — keeping the question from arising is the whole job of a green badge.
Official Sources
- CodeQL — Supported languages and frameworks — the extension list the extractor reads
-
CodeQL — Customizing library models for JavaScript — threat model classes and the default
remote -
GitHub Docs — Customizing your advanced setup for code scanning —
threat-models: localand query suites - GitHub Docs — Editing your configuration of default setup — the threat model row in default setup
-
Astro — Template directives reference —
set:htmland its escaping warning
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.