-
Notifications
You must be signed in to change notification settings - Fork 8
FRAME_ANCESTORS: embed the admin console, and nothing else #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
distronode-com
wants to merge
1
commit into
Calnode:main
Choose a base branch
from
distronode-com:feat/frame-ancestors
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package server | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "testing" | ||
|
|
||
| "github.com/calnode/calnode/frontend" | ||
| ) | ||
|
|
||
| // serveAdminSPA runs a request through the admin SPA handler wrapped exactly as New | ||
| // wraps it, and returns the response. | ||
| func serveAdminSPA(origins []string, path string) *httptest.ResponseRecorder { | ||
| h := FrameAncestors(origins)(frontend.Handler()) | ||
| rec := httptest.NewRecorder() | ||
| h.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, path, nil)) | ||
| return rec | ||
| } | ||
|
|
||
| // ⚠️ This pins what /admin/ sends TODAY, which is no frame header at all: the SPA is | ||
| // framable by any site unless an operator says otherwise. FRAME_ANCESTORS deliberately | ||
| // does not change that when unset — an opt-in setting must not smuggle in a default deny | ||
| // — so this test exists to make the next person's change to it deliberate rather than | ||
| // incidental. The public booking pages are the ones that carry an unconditional DENY. | ||
| func TestAdminSPA_sendsNoFrameHeadersWhenUnset(t *testing.T) { | ||
| for _, path := range []string{"/", "/bookings", "/favicon.svg"} { | ||
| t.Run(path, func(t *testing.T) { | ||
| rec := serveAdminSPA(nil, path) | ||
| if got := rec.Header().Get("Content-Security-Policy"); got != "" { | ||
| t.Errorf("Content-Security-Policy = %q; want it absent", got) | ||
| } | ||
| if got := rec.Header().Get("X-Frame-Options"); got != "" { | ||
| t.Errorf("X-Frame-Options = %q; want it absent", got) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestAdminSPA_frameAncestorsWhenConfigured(t *testing.T) { | ||
| rec := serveAdminSPA([]string{"https://console.example.test", "'self'"}, "/") | ||
|
|
||
| want := "frame-ancestors https://console.example.test 'self'" | ||
| if got := rec.Header().Get("Content-Security-Policy"); got != want { | ||
| t.Errorf("Content-Security-Policy = %q; want %q", got, want) | ||
| } | ||
| // X-Frame-Options has no allow-list form, and SAMEORIGIN would be honoured instead of | ||
| // the CSP by the browsers that read it, breaking the embedding this enables. | ||
| if got := rec.Header().Get("X-Frame-Options"); got != "" { | ||
| t.Errorf("X-Frame-Options = %q; want it absent alongside frame-ancestors", got) | ||
| } | ||
| } | ||
|
|
||
| // The SPA fallback route (any client-side path) carries it too, not just the shell. | ||
| func TestAdminSPA_frameAncestorsOnSPAFallback(t *testing.T) { | ||
| rec := serveAdminSPA([]string{"'self'"}, "/settings/video") | ||
| if got := rec.Header().Get("Content-Security-Policy"); got != "frame-ancestors 'self'" { | ||
| t.Errorf("Content-Security-Policy = %q; want frame-ancestors 'self'", got) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.