Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

gaberudy
Copy link

Fixes #7142

Supersedes previous pull request #7143

Copy link

@Parkreiner Parkreiner left a 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

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

Comment on lines +129 to +142
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
}

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?

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.

Support HTTP BasicAuth as alternative authentication
3 participants