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

Election creation dates, IP hashes, migration scripts #456

Merged
merged 9 commits into from
Jan 30, 2024

Conversation

mikefranze
Copy link
Collaborator

Description

Built on top of #455

Updates election DB to include creation date, public election flag, and claim key. Existing elections in DB at time of migration will be given creation time based on current time.

Changes IP addresses in voter roll and ballots to IP hashes instead, though I don't think we're currently saving that for ballots.

Adds scripts to migrate the database up and down to help with development.

Adds a NewElection type for the forms in the frontend that just removes the election id and creation date since they're assigned in the server.

Related Issues

#451

@mikefranze mikefranze requested a review from ArendPeter January 28, 2024 07:43
Copy link
Member

@ArendPeter ArendPeter left a comment

Choose a reason for hiding this comment

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

I left some comments, it it looks great! Those migrator functions look useful

}

export function hashString(inputString: string) {
return createHash('sha1').update(inputString).digest('hex')
Copy link
Member

Choose a reason for hiding this comment

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

sha256 might be a better option

sounds like sha1 is still pretty secure overall, but if we're committing to one I figure we may as well go with the stronger option

https://www.keycdn.com/support/sha1-vs-sha256#:~:text=SHA1%20is%20no%20longer%20considered,should%20also%20switch%20to%20SHA256.

https://crypto.stackexchange.com/questions/48289/how-secure-is-sha1-what-are-the-chances-of-a-real-exploit

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, I meant to use 256 but forgot to update it.

@@ -46,12 +47,12 @@ export async function getOrCreateElectionRoll(req: IRequest, election: Election,
election_id: String(election.election_id),
email: req.user?.email ? req.user.email : undefined,
voter_id: new_voter_id,
ip_address: req.ip,
ip_hash: hashString(req.ip),
Copy link
Member

Choose a reason for hiding this comment

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

nit

Could we use the ip_hash variable here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated to reuse the variable, but changed the logic some to preserve the behavior. I'm not sure if this is what we want, but currently when we submit a new voter roll there we always include the IP address even if it isn't required for authentication. The ip_hash variable was being set to null if it isn't required so that the PG query knows to ignore it. I updated the ip_hash to be its own variable and the one sent to the the PG querry to require_ip_hash

@mikefranze mikefranze requested a review from ArendPeter January 30, 2024 02:28
@mikefranze mikefranze merged commit 9c2e452 into Equal-Vote:main Jan 30, 2024
3 checks passed
Copy link
Member

@ArendPeter ArendPeter left a comment

Choose a reason for hiding this comment

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

Looks good!

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