Skip to content

Sync with updates from the forked library#37

Open
itzbernoulli wants to merge 24 commits intoboxboat:developfrom
reelmetrics:develop
Open

Sync with updates from the forked library#37
itzbernoulli wants to merge 24 commits intoboxboat:developfrom
reelmetrics:develop

Conversation

@itzbernoulli
Copy link

This is to test and then sync the updates to ensure compatibility with how we currently use the library.

blijblijblij and others added 24 commits January 8, 2019 08:43
add semicolon after client_max_body_size 0
…hecking

Feature/include bearer token checking
…oes-not-get-cors-issues

set headers to prevent CORS issues in ElasticSearch
Signed-off-by: Caleb Lloyd <caleblloyd@gmail.com>
Signed-off-by: Matthew DeVenny <matt@boxboat.com>
Signed-off-by: Matthew DeVenny <matt@boxboat.com>
Signed-off-by: Matthew DeVenny <matthew.devenny@gmail.com>
  ## Problem
  Requests with Origin headers were being rejected with 403 Forbidden, even
  with valid Bearer tokens. This broke both same-origin requests (integration
  app → integration Elasticsearch) and cross-origin requests (localhost →
  integration) for all browsers making CORS requests.

  Root cause: NGINX was sending OPTIONS preflight requests through auth_request,
  which rejected them (no credentials in preflight), preventing CORS headers
  from being added.

  ## Solution
  - Move OPTIONS handling BEFORE auth_request in proxy-pass-protected.conf
  - Return 204 with CORS headers immediately for OPTIONS requests
  - Add CORS headers to all actual responses using $http_origin variable
  - Remove incorrect OPTIONS handling from @auth internal location

  ## Changes
  - stage/etc/nginx/templates/proxy-pass-protected.conf: Add OPTIONS handler
    before auth_request, mirror Origin header in Access-Control-Allow-Origin
  - stage/etc/nginx/templates/default.conf: Remove OPTIONS handling from
    @auth location (now handled per-location)
  - server.go: Enhanced logging for debugging authentication flow
  - docker-run.sh: Build local image for easier testing
  - CLAUDE.md: Document CORS handling architecture

  ## Testing
  ✅ OPTIONS preflight returns 204 with proper CORS headers
  ✅ Origin header correctly mirrored in Access-Control-Allow-Origin
  ✅ Access-Control-Allow-Credentials: true set for cookie auth
  ✅ No authentication required for OPTIONS (per CORS spec)

  Fixes issue where integration environment Elasticsearch proxy rejected
  all requests with Origin headers, blocking ReactiveSearch components.
The backend Elasticsearch was rejecting requests that included the Origin
header, even though authentication succeeded. The proxy now:
- Handles CORS preflight (OPTIONS) requests correctly
- Adds appropriate CORS headers to responses
- Strips the Origin header before forwarding to Elasticsearch

This prevents Elasticsearch from seeing CORS requests and rejecting them.
Merges NGINX configuration improvements for Elasticsearch CORS handling:
- Handle OPTIONS preflight requests BEFORE auth_request
- Add proper CORS headers mirroring Origin with credentials support
- Strip Origin header when proxying to backend (fixes Elasticsearch)
- Add CLAUDE.md documentation and test scripts

Conflict resolution: Kept HEAD's server.go which already has bearer token
support and ID/access token flexibility from develop merge. The critical
Elasticsearch CORS fixes are in the NGINX templates which merged cleanly.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Adjusted NGINX to handle OPTIONS preflight requests before auth_request
- Ensured proper CORS headers are added, including mirroring the Origin header
- Stripped the Origin header when proxying to Elasticsearch to prevent request rejections

This update resolves issues with CORS requests being blocked and improves compatibility with various browsers.
Merge upstream nginx updates with downstream repo.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants