-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Support HTTP BasicAuth for authentication with auth-user argument, password or hashedPassword #7173
base: main
Are you sure you want to change the base?
Conversation
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.
Thank you for the contribution! Ended up leaving two small comments, but I'm worried I don't have enough architectural understanding of the project to give more finer-grained feedback
@bcpeinhardt @code-asher Pinging you just so you're aware of this PR
@@ -570,6 +577,14 @@ export async function setDefaults(cliArgs: UserProvidedArgs, configArgs?: Config | |||
args.password = process.env.PASSWORD | |||
} | |||
|
|||
const usingEnvAuthUser = !!process.env.AUTH_USER |
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.
If this variable isn't going to be used for another 50+ lines, I think it'd be better to inline it inside the return type
try { | ||
const base64Credentials = authHeader.split(" ")[1] | ||
const credentials = Buffer.from(base64Credentials, "base64").toString("utf-8") | ||
const [username, password] = credentials.split(":") | ||
if (username !== authUser) return false | ||
if (hashedPassword) { | ||
return await isHashMatch(password, hashedPassword) | ||
} else { | ||
return safeCompare(password, authPassword || "") | ||
} | ||
} catch (error) { | ||
logger.error("Error validating basic auth:" + error) | ||
return false | ||
} |
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.
Could the logic for base64Credentials
be updated to check that the split array has an element at index 1, and isn't potentially undefined
? Once that's done, could the declaration be moved out of the block since that part of the code wouldn't be able to throw an error?
Fixes #7142
Supersedes previous pull request #7143