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
12 changes: 12 additions & 0 deletions .github/workflows/check-hardcoded-urls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Check for hardcoded URLs

on:
pull_request:

jobs:
hardcoded-urls:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: List hardcoded URLs
run: ./scripts/list-hardcoded-urls.sh
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ We welcome contributions from the community! 🚀
2. Create a feature branch
3. Submit a pull request

### Checking for hardcoded URLs

Run the following script to detect any hardcoded `localhost` references before committing code:

```bash
./scripts/list-hardcoded-urls.sh
```

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
20 changes: 20 additions & 0 deletions scripts/list-hardcoded-urls.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/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
matches=$(echo "$matches" | grep -F -v -f "$ALLOWLIST_FILE" || true)
fi

if [[ -n "$matches" ]]; then
echo "$matches"
echo "Hardcoded localhost URLs detected."
exit 1
else
echo "No hardcoded localhost URLs found."
exit 0
fi