mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2025-11-06 09:05:44 +00:00
fix: bot suggestions
This commit is contained in:
Binary file not shown.
@@ -41,7 +41,7 @@
|
|||||||
"totpTitle": "Enter your TOTP code",
|
"totpTitle": "Enter your TOTP code",
|
||||||
"unauthorizedTitle": "Unauthorized",
|
"unauthorizedTitle": "Unauthorized",
|
||||||
"unauthorizedResourceSubtitle": "The user with username <Code>{{username}}</Code> is not authorized to access the resource <Code>{{resource}}</Code>.",
|
"unauthorizedResourceSubtitle": "The user with username <Code>{{username}}</Code> is not authorized to access the resource <Code>{{resource}}</Code>.",
|
||||||
"unaothorizedLoginSubtitle": "The user with username <Code>{{username}}</Code> is not authorized to login.",
|
"unauthorizedLoginSubtitle": "The user with username <Code>{{username}}</Code> is not authorized to login.",
|
||||||
"unauthorizedGroupsSubtitle": "The user with username <Code>{{username}}</Code> is not in the groups required by the resource <Code>{{resource}}</Code>.",
|
"unauthorizedGroupsSubtitle": "The user with username <Code>{{username}}</Code> is not in the groups required by the resource <Code>{{resource}}</Code>.",
|
||||||
"unauthorizedButton": "Try again",
|
"unauthorizedButton": "Try again",
|
||||||
"untrustedRedirectTitle": "Untrusted redirect",
|
"untrustedRedirectTitle": "Untrusted redirect",
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
"totpTitle": "Enter your TOTP code",
|
"totpTitle": "Enter your TOTP code",
|
||||||
"unauthorizedTitle": "Unauthorized",
|
"unauthorizedTitle": "Unauthorized",
|
||||||
"unauthorizedResourceSubtitle": "The user with username <Code>{{username}}</Code> is not authorized to access the resource <Code>{{resource}}</Code>.",
|
"unauthorizedResourceSubtitle": "The user with username <Code>{{username}}</Code> is not authorized to access the resource <Code>{{resource}}</Code>.",
|
||||||
"unaothorizedLoginSubtitle": "The user with username <Code>{{username}}</Code> is not authorized to login.",
|
"unauthorizedLoginSubtitle": "The user with username <Code>{{username}}</Code> is not authorized to login.",
|
||||||
"unauthorizedGroupsSubtitle": "The user with username <Code>{{username}}</Code> is not in the groups required by the resource <Code>{{resource}}</Code>.",
|
"unauthorizedGroupsSubtitle": "The user with username <Code>{{username}}</Code> is not in the groups required by the resource <Code>{{resource}}</Code>.",
|
||||||
"unauthorizedButton": "Try again",
|
"unauthorizedButton": "Try again",
|
||||||
"untrustedRedirectTitle": "Untrusted redirect",
|
"untrustedRedirectTitle": "Untrusted redirect",
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { useAppContext } from "../context/app-context";
|
|||||||
import { Trans, useTranslation } from "react-i18next";
|
import { Trans, useTranslation } from "react-i18next";
|
||||||
|
|
||||||
export const LogoutPage = () => {
|
export const LogoutPage = () => {
|
||||||
const { isLoggedIn, oauth, provider, email } = useUserContext();
|
const { isLoggedIn, oauth, provider, email, username } = useUserContext();
|
||||||
const { genericName } = useAppContext();
|
const { genericName } = useAppContext();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ export const LogoutPage = () => {
|
|||||||
t={t}
|
t={t}
|
||||||
components={{ Code: <Code /> }}
|
components={{ Code: <Code /> }}
|
||||||
values={{
|
values={{
|
||||||
username: email,
|
username: username,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -41,13 +41,13 @@ export const UnauthorizedPage = () => {
|
|||||||
values={{ username, resource }}
|
values={{ username, resource }}
|
||||||
/>
|
/>
|
||||||
</UnauthorizedLayout>
|
</UnauthorizedLayout>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<UnauthorizedLayout>
|
<UnauthorizedLayout>
|
||||||
<Trans
|
<Trans
|
||||||
i18nKey="unaothorizedLoginSubtitle"
|
i18nKey="unauthorizedLoginSubtitle"
|
||||||
t={t}
|
t={t}
|
||||||
components={{ Code: <Code /> }}
|
components={{ Code: <Code /> }}
|
||||||
values={{ username }}
|
values={{ username }}
|
||||||
@@ -65,9 +65,7 @@ const UnauthorizedLayout = ({ children }: { children: React.ReactNode }) => {
|
|||||||
<Text size="xl" fw={700}>
|
<Text size="xl" fw={700}>
|
||||||
{t("Unauthorized")}
|
{t("Unauthorized")}
|
||||||
</Text>
|
</Text>
|
||||||
<Text>
|
<Text>{children}</Text>
|
||||||
{children}
|
|
||||||
</Text>
|
|
||||||
<Button
|
<Button
|
||||||
fullWidth
|
fullWidth
|
||||||
mt="xl"
|
mt="xl"
|
||||||
|
|||||||
@@ -268,7 +268,7 @@ func (auth *Auth) ResourceAllowed(c *gin.Context, context types.UserContext, lab
|
|||||||
// Check if oauth is allowed
|
// Check if oauth is allowed
|
||||||
if context.OAuth {
|
if context.OAuth {
|
||||||
log.Debug().Msg("Checking OAuth whitelist")
|
log.Debug().Msg("Checking OAuth whitelist")
|
||||||
return utils.CheckWhitelist(labels.OAuthWhitelist, context.Username)
|
return utils.CheckWhitelist(labels.OAuthWhitelist, context.Email)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check users
|
// Check users
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ func (h *Handlers) AuthHandler(c *gin.Context) {
|
|||||||
if !authEnabled {
|
if !authEnabled {
|
||||||
for key, value := range labels.Headers {
|
for key, value := range labels.Headers {
|
||||||
log.Debug().Str("key", key).Str("value", value).Msg("Setting header")
|
log.Debug().Str("key", key).Str("value", value).Msg("Setting header")
|
||||||
c.Header(key, value)
|
c.Header(key, utils.SanitizeHeader(value))
|
||||||
}
|
}
|
||||||
c.JSON(200, gin.H{
|
c.JSON(200, gin.H{
|
||||||
"status": 200,
|
"status": 200,
|
||||||
@@ -209,15 +209,15 @@ func (h *Handlers) AuthHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Header("Remote-User", userContext.Username)
|
c.Header("Remote-User", utils.SanitizeHeader(userContext.Username))
|
||||||
c.Header("Remote-Name", userContext.Name)
|
c.Header("Remote-Name", utils.SanitizeHeader(userContext.Name))
|
||||||
c.Header("Remote-Email", userContext.Email)
|
c.Header("Remote-Email", utils.SanitizeHeader(userContext.Email))
|
||||||
c.Header("Remote-Groups", userContext.OAuthGroups)
|
c.Header("Remote-Groups", utils.SanitizeHeader(userContext.OAuthGroups))
|
||||||
|
|
||||||
// Set the rest of the headers
|
// Set the rest of the headers
|
||||||
for key, value := range labels.Headers {
|
for key, value := range labels.Headers {
|
||||||
log.Debug().Str("key", key).Str("value", value).Msg("Setting header")
|
log.Debug().Str("key", key).Str("value", value).Msg("Setting header")
|
||||||
c.Header(key, value)
|
c.Header(key, utils.SanitizeHeader(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
// The user is allowed to access the app
|
// The user is allowed to access the app
|
||||||
|
|||||||
@@ -328,5 +328,19 @@ func CheckWhitelist(whitelist string, str string) bool {
|
|||||||
|
|
||||||
// Capitalize just the first letter of a string
|
// Capitalize just the first letter of a string
|
||||||
func Capitalize(str string) string {
|
func Capitalize(str string) string {
|
||||||
|
if len(str) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
return strings.ToUpper(string([]rune(str)[0])) + string([]rune(str)[1:])
|
return strings.ToUpper(string([]rune(str)[0])) + string([]rune(str)[1:])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sanitize header removes all control characters from a string
|
||||||
|
func SanitizeHeader(header string) string {
|
||||||
|
return strings.Map(func(r rune) rune {
|
||||||
|
// Allow only printable ASCII characters (32-126) and safe whitespace (space, tab)
|
||||||
|
if r == ' ' || r == '\t' || (r >= 32 && r <= 126) {
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}, header)
|
||||||
|
}
|
||||||
|
|||||||
@@ -467,3 +467,65 @@ func TestCheckWhitelist(t *testing.T) {
|
|||||||
t.Fatalf("Expected %v, got %v", expected, result)
|
t.Fatalf("Expected %v, got %v", expected, result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test capitalize
|
||||||
|
func TestCapitalize(t *testing.T) {
|
||||||
|
t.Log("Testing capitalize with a valid string")
|
||||||
|
|
||||||
|
// Create variables
|
||||||
|
str := "test"
|
||||||
|
expected := "Test"
|
||||||
|
|
||||||
|
// Test the capitalize function
|
||||||
|
result := utils.Capitalize(str)
|
||||||
|
|
||||||
|
// Check if the result is equal to the expected
|
||||||
|
if result != expected {
|
||||||
|
t.Fatalf("Expected %v, got %v", expected, result)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Log("Testing capitalize with an empty string")
|
||||||
|
|
||||||
|
// Create variables
|
||||||
|
str = ""
|
||||||
|
expected = ""
|
||||||
|
|
||||||
|
// Test the capitalize function
|
||||||
|
result = utils.Capitalize(str)
|
||||||
|
|
||||||
|
// Check if the result is equal to the expected
|
||||||
|
if result != expected {
|
||||||
|
t.Fatalf("Expected %v, got %v", expected, result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test the header sanitizer
|
||||||
|
func TestSanitizeHeader(t *testing.T) {
|
||||||
|
t.Log("Testing sanitize header with a valid string")
|
||||||
|
|
||||||
|
// Create variables
|
||||||
|
str := "X-Header=value"
|
||||||
|
expected := "X-Header=value"
|
||||||
|
|
||||||
|
// Test the sanitize header function
|
||||||
|
result := utils.SanitizeHeader(str)
|
||||||
|
|
||||||
|
// Check if the result is equal to the expected
|
||||||
|
if result != expected {
|
||||||
|
t.Fatalf("Expected %v, got %v", expected, result)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Log("Testing sanitize header with an invalid string")
|
||||||
|
|
||||||
|
// Create variables
|
||||||
|
str = "X-Header=val\nue"
|
||||||
|
expected = "X-Header=value"
|
||||||
|
|
||||||
|
// Test the sanitize header function
|
||||||
|
result = utils.SanitizeHeader(str)
|
||||||
|
|
||||||
|
// Check if the result is equal to the expected
|
||||||
|
if result != expected {
|
||||||
|
t.Fatalf("Expected %v, got %v", expected, result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user