De controle staat in scripts/lib-inline-script.sh (alleen POSIX-tools), met een test (scripts/test-inline-script-check.sh) en een lokale proef van smoke-site.sh tegen een admin-pagina met en zonder inline script. De melding noemt nu wat er gevonden is. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
16 lines
966 B
Bash
16 lines
966 B
Bash
#!/usr/bin/env bash
|
|
# Finds inline scripts in an HTML page (read from stdin): the ones a Content-Security-Policy with script-src 'self' blocks.
|
|
#
|
|
# An inline script is a <script> WITHOUT a src attribute (wherever the attribute stands in the tag) whose content is not
|
|
# empty. Not counted: <script src="..."> (also with type="module", crossorigin, defer, ... in any order), an empty
|
|
# <script></script>, and data blocks that are not executed (type="application/json", "application/ld+json",
|
|
# "importmap" and the like). Prints the opening tag of every inline script found; no output means none.
|
|
# Plain POSIX tools only (no grep -P), so it behaves the same on every runner.
|
|
inline_scripts() {
|
|
tr '\r\n' ' ' \
|
|
| grep -oiE '<script[^>]*>[[:space:]]*[^[:space:]<]' \
|
|
| grep -viE '<script[^>]*[[:space:]]src[[:space:]]*=' \
|
|
| grep -viE '<script[^>]*type[[:space:]]*=[[:space:]]*["'\'']?(application/(ld\+)?json|importmap|speculationrules)' \
|
|
|| true
|
|
}
|