Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ Run the following script to detect any hardcoded `localhost` references before c
```

The script lists offending lines and exits with a nonzero status if any are found.
Existing references known to be safe are tracked in `scripts/hardcoded-url-allowlist.txt`.

## License
MIT License – Feel free to modify and share. 📜
Expand Down
5 changes: 5 additions & 0 deletions scripts/hardcoded-url-allowlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FEDERATION_GUIDE.md
backend/federation/federationSyncJob.js
frontend/user_login.js
frontend/federationStatusCLI.js
README.md
6 changes: 6 additions & 0 deletions scripts/list-hardcoded-urls.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#!/usr/bin/env bash
set -euo pipefail

ALLOWLIST_FILE="$(dirname "$0")/hardcoded-url-allowlist.txt"

matches=$(grep -R --line-number --exclude-dir=node_modules --exclude-dir=.git -E "http://localhost|localhost:5000" || true)
matches=$(echo "$matches" | grep -v 'scripts/list-hardcoded-urls.sh' || true)

if [[ -f "$ALLOWLIST_FILE" ]]; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Filter only file paths when applying allowlist

The allowlist is applied with grep -F -v -f "$ALLOWLIST_FILE" against the entire file:line:content string produced by the previous grep. This causes false negatives when the line’s contents mention any string from the allowlist even if the file itself is not allowlisted (for instance, a comment that says “see README.md” and also contains a new http://localhost URL). In such cases the checker silently drops the match and will not fail the build, defeating the purpose of the safeguard. Filtering should be applied solely to the path portion before the first colon.

Useful? React with 👍 / 👎.

matches=$(echo "$matches" | grep -F -v -f "$ALLOWLIST_FILE" || true)
fi

if [[ -n "$matches" ]]; then
echo "$matches"
echo "Hardcoded localhost URLs detected."
Expand Down