Skip to content

Conversation

@mostlygeek
Copy link
Contributor

@mostlygeek mostlygeek commented Oct 21, 2025

This PR incorporates the changes and recommendations from the external security review. Where applicable commits will reference the ID in the security report.

Signed-off-by: Benson Wong <benson@tailscale.com>
In serveAuthorize there was a chance an authorization code is saved but
never used if a url.Parse() fails. This commit moves the parsing logic
above the saving logic.

Signed-off-by: Benson Wong <benson@tailscale.com>
Signed-off-by: Benson Wong <benson@tailscale.com>
Signed-off-by: Benson Wong <benson@tailscale.com>
The UI form endpoints and the /client/ endpoints accept POST requests
for modifying OAuth client data. This commit adds checking of the
Sec-Fetch-Site and Origin request headers.

Signed-off-by: Benson Wong <benson@tailscale.com>
add isDangerousScheme() to disallow various schemes that may be
dangerous in an OAuth redirect_uri

Signed-off-by: Benson Wong <benson@tailscale.com>
Signed-off-by: Benson Wong <benson@tailscale.com>
Eliminiate a low risk scenario where a refresh token could be used to
issue multiple access tokens in a race condition. The trade-off is that
a users would need to re-authenticate when a token refresh fails.

Signed-off-by: Benson Wong <benson@tailscale.com>
Signed-off-by: Benson Wong <benson@tailscale.com>
@mostlygeek mostlygeek force-pushed the mostlygeek/sec-review branch from 8a8ea35 to 28c2f76 Compare October 21, 2025 23:56
Signed-off-by: Benson Wong <benson@tailscale.com>
@mostlygeek mostlygeek force-pushed the mostlygeek/sec-review branch from 28c2f76 to 7c49993 Compare October 22, 2025 00:25
}
}

func TestDynamicClientRegistrationCORSHeaders(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add CORS pre-flight tests to enforce the contract we have for now. We can tighten them up in the future. DCR doesn't really work without more permissive settings, particularly with the mcp-inspector.

}
}

func TestClientApiCSRF(t *testing.T) {
Copy link
Contributor Author

@mostlygeek mostlygeek Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add tests to ensure the /clients/ api handles CSRF mitigation as expected.


// isFunnelRequest checks if the request is coming through Tailscale Funnel
// Migrated from legacy/tsidp.go:2392-2410
func isFunnelRequest(r *http.Request) bool {
Copy link
Contributor Author

@mostlygeek mostlygeek Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function moved to server.go

}
}
}
func TestMetadataCORSHeaders(t *testing.T) {
Copy link
Contributor Author

@mostlygeek mostlygeek Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add test to ensure metadata endpoints have the appropriate CORS preflight behaviour.

}

// isFunnelRequest checks if the request is coming through Tailscale Funnel
func isFunnelRequest(r *http.Request) bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved here from oauth-metadata.go. No changes to the code.


RUN addgroup -g 1001 -S app && \
adduser -u 1001 -S app

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run binary as a less privileged user than root

Signed-off-by: Benson Wong <benson@tailscale.com>
Signed-off-by: Benson Wong <benson@tailscale.com>
@mostlygeek mostlygeek force-pushed the mostlygeek/sec-review branch from 9382158 to f2206b2 Compare October 22, 2025 03:40
@awly awly requested a review from patrickod October 23, 2025 19:56
Copy link
Member

@awly awly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some other stuff that would be good to patch, here or in a separate PR:

  • LT-APP25-11: I don't think all endpoints do request method filtering (like handleUI); perhaps using http.ServeMux capabilities is the simplest thing here? https://pkg.go.dev/net/http#hdr-Patterns-ServeMux
  • LT-APP25-16: other misc security headers like HSTS and CSP

@mostlygeek mostlygeek force-pushed the mostlygeek/sec-review branch from cab732d to a92591c Compare October 25, 2025 04:26
mostlygeek and others added 3 commits October 24, 2025 21:46
Co-authored-by: Andrew Lytvynov <awly@tailscale.com>
Signed-off-by: Benson Wong <benson@tailscale.com>
Co-authored-by: Andrew Lytvynov <awly@tailscale.com>
Signed-off-by: Benson Wong <benson@tailscale.com>
- add "s" to misspelled CORS header Access-Control-Allow-Method
- use filippo.io/csrf for CSRF protection

Signed-off-by: Benson Wong <benson@tailscale.com>
@mostlygeek mostlygeek force-pushed the mostlygeek/sec-review branch from a92591c to 986bd68 Compare October 25, 2025 04:51
Signed-off-by: Benson Wong <benson@tailscale.com>
@mostlygeek
Copy link
Contributor Author

@awly thanks for the suggestions. Ready for another review.

@mostlygeek mostlygeek requested a review from awly October 28, 2025 21:23
server/server.go Outdated
Comment on lines 246 to 247
protect := csrf.New()
protect.AddTrustedOrigin(s.serverURL)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: move this to the bottom, right before the return where it's actually needed

Signed-off-by: Benson Wong <benson@tailscale.com>
@mostlygeek mostlygeek merged commit 08d296d into main Oct 28, 2025
2 checks passed
@mostlygeek mostlygeek deleted the mostlygeek/sec-review branch October 28, 2025 21:40
mostlygeek added a commit that referenced this pull request Oct 30, 2025
tsidp completed an external security review in #89. It is safe to remove
the WIP check.

Fixes: #99

Signed-off-by: Benson Wong <benson@tailscale.com>
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.

2 participants