@@ -133,6 +133,103 @@ jobs:
133133 APIFY_SIGNING_TOKEN : ${{ secrets.APIFY_SIGNING_TOKEN }}
134134 SEGMENT_TOKEN : ${{ secrets.SEGMENT_TOKEN }}
135135
136+ - name : Install Nginx
137+ run : |
138+ sudo apt-get update
139+ sudo apt-get install -y nginx
140+
141+ - name : Start Docusaurus server
142+ run : |
143+ cd website
144+ nohup yarn docusaurus serve --port 3000 --no-open &
145+ sleep 5
146+ curl -f http://localhost:3000 > /dev/null
147+
148+ - name : Start Nginx with project config
149+ run : |
150+ PWD_PATH="$(pwd)"
151+ cat > default.conf <<EOF
152+ worker_processes auto;
153+ error_log ${PWD_PATH}/logs/error.log;
154+ pid ${PWD_PATH}/logs/nginx.pid;
155+ events {}
156+ http {
157+ access_log ${PWD_PATH}/logs/access.log;
158+ include ${PWD_PATH}/website/nginx.conf;
159+ }
160+ EOF
161+ sed -i 's|https://apify.github.io/crawlee|http://localhost:3000|g' default.conf
162+ mkdir -p "${PWD_PATH}/logs"
163+ nginx -c "${PWD_PATH}/default.conf"
164+ sleep 1
165+
166+ - name : Run header assertions
167+ run : |
168+ set -euo pipefail
169+ function assert_header() {
170+ url=$1
171+ header=$2
172+ expected=$3
173+ shift 3
174+ extra_args=("$@")
175+ actual=$(curl -s -D - -o /dev/null "${extra_args[@]}" "$url" | grep -i "^$header" | tr -d '\r' || true)
176+ echo "→ $url → $actual"
177+ echo "$actual" | grep -q "$expected" || (echo "❌ Expected '$expected' in '$header' for $url" && exit 1)
178+ }
179+
180+ function assert_status() {
181+ url=$1
182+ expected=$2
183+ shift 2
184+ extra_args=("$@")
185+ actual=$(curl -s -o /dev/null -w "%{http_code}" "${extra_args[@]}" "$url")
186+ echo "→ $url → HTTP $actual"
187+ [ "$actual" = "$expected" ] || (echo "❌ Expected HTTP $expected but got $actual for $url" && exit 1)
188+ }
189+
190+ function assert_no_redirect() {
191+ url=$1
192+ shift
193+ extra_args=("$@")
194+ response=$(curl -s -D - -o /dev/null -w "\n%{http_code}" "${extra_args[@]}" "$url" 2>/dev/null)
195+ status=$(echo "$response" | tail -1)
196+ location=$(echo "$response" | grep -i "^location:" | tr -d '\r' || true)
197+ echo "→ $url → HTTP $status ${location:+(${location})}"
198+ if [ "$status" = "301" ] || [ "$status" = "302" ]; then
199+ echo "❌ Got redirect for $url: $location" && exit 1
200+ fi
201+ }
202+
203+ echo "🧪 Checking open redirect protection..."
204+ assert_no_redirect "http://localhost:8080///%5Cevil.com/"
205+ assert_no_redirect "http://localhost:8080/%5Cevil.com/"
206+ assert_no_redirect "http://localhost:8080///%5cevil.com/"
207+ assert_no_redirect "http://localhost:8080" --request-target '/\evil.com/'
208+ assert_no_redirect "http://localhost:8080" --request-target '///\evil.com/'
209+ assert_status "http://localhost:8080/js/docs/quick-start/" "302"
210+
211+ echo "🧪 Checking Nginx responses... (crawlee JS)"
212+ assert_header "http://localhost:8080/" "Content-Type" "text/html"
213+ assert_header "http://localhost:8080/" "Content-Type" "text/markdown" -H "Accept: text/markdown"
214+ assert_header "http://localhost:8080/js/docs/quick-start" "Content-Type" "text/html"
215+ assert_header "http://localhost:8080/js/docs/quick-start.md" "Content-Type" "text/markdown"
216+ assert_header "http://localhost:8080/js/docs/quick-start" "Content-Type" "text/markdown" -H "Accept: text/markdown"
217+ assert_header "http://localhost:8080/llms.txt" "Content-Type" "text/markdown"
218+ assert_header "http://localhost:8080/llms-full.txt" "Content-Type" "text/markdown"
219+
220+ echo "🧪 Checking Nginx responses... (crawlee Python)"
221+ assert_header "http://localhost:8080/python/docs/quick-start" "Content-Type" "text/html"
222+ assert_header "http://localhost:8080/python/docs/quick-start.md" "Content-Type" "text/markdown"
223+ assert_header "http://localhost:8080/python/docs/quick-start" "Content-Type" "text/markdown" -H "Accept: text/markdown"
224+ assert_header "http://localhost:8080/python/llms.txt" "Content-Type" "text/markdown"
225+ assert_header "http://localhost:8080/python/llms-full.txt" "Content-Type" "text/markdown"
226+
227+ echo "✅ All Nginx header checks passed."
228+
229+ - name : Stop Nginx
230+ if : always()
231+ run : nginx -c "$(pwd)/default.conf" -s stop
232+
136233 lint :
137234 name : Lint
138235 runs-on : ubuntu-22.04
0 commit comments