Skip to content

Commit

Permalink
Allow custom permission denied messages
Browse files Browse the repository at this point in the history
  • Loading branch information
rthellend committed Jan 30, 2025
1 parent 02ca984 commit e10a51b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### :wrench: Bug fixes

* Handle quic.ErrTransportClosed correctly.
* Allow customized permission denied messages.

## v0.15.0-rc1

Expand Down
10 changes: 8 additions & 2 deletions proxy/backend-sso.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,21 @@ func (be *Backend) servePermissionDenied(w http.ResponseWriter, req *http.Reques
URL string
DisplayURL string
Token string
Message template.HTML
}{
Email: email,
URL: url,
DisplayURL: url,
Token: token,
Message: template.HTML(be.SSO.HTMLMessage),
}
if len(data.DisplayURL) > 100 {
data.DisplayURL = data.DisplayURL[:97] + "..."
}
w.WriteHeader(http.StatusForbidden)
permissionDeniedTemplate.Execute(w, data)
if err := permissionDeniedTemplate.Execute(w, data); err != nil {
be.logErrorF("ERR permission-denied-template: %v", err)
}
}

func (be *Backend) enforceSSOPolicy(w http.ResponseWriter, req *http.Request) bool {
Expand Down Expand Up @@ -325,7 +329,9 @@ func (be *Backend) enforceSSOPolicy(w http.ResponseWriter, req *http.Request) bo
data.DisplayURL = data.DisplayURL[:97] + "..."
}
w.WriteHeader(http.StatusForbidden)
loginTemplate.Execute(w, data)
if err := loginTemplate.Execute(w, data); err != nil {
be.logErrorF("ERR login-template: %v", err)
}
return false
}
userID, _ := claims["email"].(string)
Expand Down
3 changes: 3 additions & 0 deletions proxy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,9 @@ type BackendSSO struct {
// Exceptions is a list of path prefixes that are exempt from SSO
// enforcement, e.g. /app.webmanifest or /favicon.png
Exceptions []string `yaml:"exceptions,omitempty"`
// HTMLMessage is displayed on the permission denied screen. The value
// is HTML and will be used as it is without escaping.
HTMLMessage string `yaml:"htmlMessage,omitempty"`
// SetUserIDHeader indicates that the x-tlsproxy-user-id header should
// be set with the email address of the user.
//
Expand Down
21 changes: 19 additions & 2 deletions proxy/internal/passkeys/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,22 @@ type nonceData struct {
}

func (m *Manager) SetACL(acl *[]string) {
m.acl = acl
if acl == nil {
return
}
if m.acl == nil {
m.acl = new([]string)
}
v := make(map[string]bool)
for _, a := range *m.acl {
v[a] = true
}
for _, a := range *acl {
if v[a] {
continue
}
*m.acl = append(*m.acl, a)
}
}

func (m *Manager) vacuum() {
Expand Down Expand Up @@ -358,7 +373,9 @@ func (m *Manager) HandleCallback(w http.ResponseWriter, req *http.Request) {
data.Email, _ = redirectClaims["email"].(string)
}
w.Header().Set("X-Frame-Options", "DENY")
authTemplate.Execute(w, data)
if err := authTemplate.Execute(w, data); err != nil {
m.cfg.Logger.Errorf("ERR auth-template: %v", err)
}

case "AssertionOptions":
if req.Method != "POST" {
Expand Down
1 change: 1 addition & 0 deletions proxy/permission-denied-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<div class="big">🛂</div>
<div><em>{{.Email}}</em> is not permitted to access</div>
<div id="target"><a href="{{.URL}}">{{.DisplayURL}}</a></div>
{{- .Message }}
</div>
</body>
</html>

0 comments on commit e10a51b

Please sign in to comment.