-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Pkce v2.18.25 #4151
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
Junaide
wants to merge
19
commits into
semaphoreui:develop
Choose a base branch
from
VCACanada:pkce-v2.18.25
base: develop
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
Pkce v2.18.25 #4151
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
60997ab
feat(ansible): skip galaxy install
fiftin 8a4dcf0
fix(ui): remove invalid alert
fiftin b8f1e05
ci: fix stable branch
fiftin eb841c8
,.d.,mxx,.mxlvv /.gfb;h
fiftin a7a7a33
fix(git): validate url
fiftin aedf311
fix(tasks): add resolveGitBranch
fiftin 4af0a58
fix(tasks): allow override branch only for flag AllowOverrideBranchIn…
fiftin 419c655
fix(api): validate access key data
fiftin 1c4bb65
fix(roles): check user permissions for creating custom roles
fiftin 5d87656
fix(templates): validate playbook path
fiftin 2d6e2e3
feat: secure flag for session when https enabled
fiftin f51502e
sec(auth): origin/referer check
fiftin a9b4bb6
feat(api): logs
fiftin aa67063
feat(api): logs
fiftin debf7a0
feat(ui): return extra vars for secrets
fiftin 74d8dd5
feat(ui): placeholder for enterprise storages
fiftin 7c3789c
fix(runners): close connections
fiftin 525be80
feat(oidc): add PKCE to the OIDC authorization code flow
Junaide 0754e71
build(docker): add Dockerfile.pkce for the VCAC patched image
Junaide 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| package api | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "net/url" | ||
| "testing" | ||
|
|
||
| "github.com/semaphoreui/semaphore/util" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestIsStateChangingMethod(t *testing.T) { | ||
| tests := []struct { | ||
| method string | ||
| expected bool | ||
| }{ | ||
| {http.MethodGet, false}, | ||
| {http.MethodHead, false}, | ||
| {http.MethodOptions, false}, | ||
| {http.MethodPost, true}, | ||
| {http.MethodPut, true}, | ||
| {http.MethodPatch, true}, | ||
| {http.MethodDelete, true}, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.method, func(t *testing.T) { | ||
| assert.Equal(t, tt.expected, isStateChangingMethod(tt.method)) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestRequestOriginHost(t *testing.T) { | ||
| t.Run("from Origin header", func(t *testing.T) { | ||
| r := httptest.NewRequest(http.MethodPost, "/api/users/1/password", nil) | ||
| r.Header.Set("Origin", "https://semaphore.example.com") | ||
|
|
||
| host, ok := requestOriginHost(r) | ||
| assert.True(t, ok) | ||
| assert.Equal(t, "semaphore.example.com", host) | ||
| }) | ||
|
|
||
| t.Run("falls back to Referer", func(t *testing.T) { | ||
| r := httptest.NewRequest(http.MethodPost, "/api/users/1/password", nil) | ||
| r.Header.Set("Referer", "https://semaphore.example.com/project/1") | ||
|
|
||
| host, ok := requestOriginHost(r) | ||
| assert.True(t, ok) | ||
| assert.Equal(t, "semaphore.example.com", host) | ||
| }) | ||
|
|
||
| t.Run("Origin takes precedence over Referer", func(t *testing.T) { | ||
| r := httptest.NewRequest(http.MethodPost, "/api/users/1/password", nil) | ||
| r.Header.Set("Origin", "https://attacker.com") | ||
| r.Header.Set("Referer", "https://semaphore.example.com/") | ||
|
|
||
| host, ok := requestOriginHost(r) | ||
| assert.True(t, ok) | ||
| assert.Equal(t, "attacker.com", host) | ||
| }) | ||
|
|
||
| t.Run("no headers", func(t *testing.T) { | ||
| r := httptest.NewRequest(http.MethodPost, "/api/users/1/password", nil) | ||
|
|
||
| _, ok := requestOriginHost(r) | ||
| assert.False(t, ok) | ||
| }) | ||
| } | ||
|
|
||
| // newRecordingHandler returns an http.Handler that records whether it was | ||
| // called, used to assert that the middleware did or did not pass the request | ||
| // through. | ||
| func newRecordingHandler(called *bool) http.Handler { | ||
| return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| *called = true | ||
| w.WriteHeader(http.StatusNoContent) | ||
| }) | ||
| } | ||
|
|
||
| func TestCsrfProtectionMiddleware(t *testing.T) { | ||
| orig := util.WebHostURL | ||
| defer func() { util.WebHostURL = orig }() | ||
|
|
||
| webHost, err := url.Parse("https://semaphore.example.com") | ||
| require.NoError(t, err) | ||
| util.WebHostURL = webHost | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| method string | ||
| host string | ||
| origin string | ||
| referer string | ||
| authHeader string | ||
| wantStatus int | ||
| wantForwPass bool | ||
| }{ | ||
| { | ||
| name: "safe method is always allowed", | ||
| method: http.MethodGet, | ||
| host: "semaphore.example.com", | ||
| origin: "https://attacker.com", | ||
| wantStatus: http.StatusNoContent, | ||
| wantForwPass: true, | ||
| }, | ||
| { | ||
| name: "same origin POST is allowed", | ||
| method: http.MethodPost, | ||
| host: "semaphore.example.com", | ||
| origin: "https://semaphore.example.com", | ||
| wantStatus: http.StatusNoContent, | ||
| wantForwPass: true, | ||
| }, | ||
| { | ||
| name: "cross origin POST is blocked", | ||
| method: http.MethodPost, | ||
| host: "semaphore.example.com", | ||
| origin: "https://attacker.com", | ||
| wantStatus: http.StatusForbidden, | ||
| wantForwPass: false, | ||
| }, | ||
| { | ||
| name: "cross origin DELETE is blocked", | ||
| method: http.MethodDelete, | ||
| host: "semaphore.example.com", | ||
| origin: "https://attacker.com:1337", | ||
| wantStatus: http.StatusForbidden, | ||
| wantForwPass: false, | ||
| }, | ||
| { | ||
| name: "cross origin via Referer is blocked", | ||
| method: http.MethodPost, | ||
| host: "semaphore.example.com", | ||
| referer: "https://attacker.com/evil", | ||
| wantStatus: http.StatusForbidden, | ||
| wantForwPass: false, | ||
| }, | ||
| { | ||
| name: "missing origin and referer is allowed", | ||
| method: http.MethodPost, | ||
| host: "semaphore.example.com", | ||
| wantStatus: http.StatusNoContent, | ||
| wantForwPass: true, | ||
| }, | ||
| { | ||
| name: "bearer token bypasses origin check", | ||
| method: http.MethodPost, | ||
| host: "semaphore.example.com", | ||
| origin: "https://attacker.com", | ||
| authHeader: "Bearer sometoken", | ||
| wantStatus: http.StatusNoContent, | ||
| wantForwPass: true, | ||
| }, | ||
| { | ||
| name: "origin matching request host is allowed", | ||
| method: http.MethodPost, | ||
| host: "internal-proxy:3000", | ||
| origin: "http://internal-proxy:3000", | ||
| wantStatus: http.StatusNoContent, | ||
| wantForwPass: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| r := httptest.NewRequest(tt.method, "/api/users/1/password", nil) | ||
| r.Host = tt.host | ||
| if tt.origin != "" { | ||
| r.Header.Set("Origin", tt.origin) | ||
| } | ||
| if tt.referer != "" { | ||
| r.Header.Set("Referer", tt.referer) | ||
| } | ||
| if tt.authHeader != "" { | ||
| r.Header.Set("Authorization", tt.authHeader) | ||
| } | ||
|
|
||
| var forwarded bool | ||
| w := httptest.NewRecorder() | ||
|
|
||
| csrfProtectionMiddleware(newRecordingHandler(&forwarded)).ServeHTTP(w, r) | ||
|
|
||
| assert.Equal(t, tt.wantStatus, w.Code) | ||
| assert.Equal(t, tt.wantForwPass, forwarded) | ||
| }) | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Document the template override control.
The API schemas document
skip_galaxy_install, but omitallow_override_skip_galaxy_install. Clients cannot discover how to permit task-level changes to this setting. Document the template-side field in both schemas.api-docs.yml#L858-L859: add the template override property to the schema used for template parameters.web/public/swagger/api-docs.yml#L846-L847: add the same property to the public Swagger schema.📍 Affects 2 files
api-docs.yml#L858-L859(this comment)web/public/swagger/api-docs.yml#L846-L847🤖 Prompt for AI Agents