This project is a highly secure, transparent, and tamper-proof voting system built on the Ethereum blockchain. By integrating advanced facial recognition technology with decentralized smart contracts, the system ensures that elections are fair, verifiable, and completely immune to voter fraud or manipulation.
Network: Ethereum Sepolia Testnet
Contract Address: 0xYOUR_CONTRACT_ADDRESS_HERE
Etherscan: https://sepolia.etherscan.io/address/0xYOUR_CONTRACT_ADDRESS_HERE
The centralized, modern interface for managing the election process securely.
The voting process is divided into clear, secure stages to ensure the integrity of the election from start to finish.
Before an election begins, eligible voters are registered into the system by the administration.
- The voter's facial biometric data is captured via webcam and securely encoded.
- Each voter is assigned a unique Voter ID linked to their biometric profile.
When a voter wants to cast their vote, they must pass a strict authentication process:
- The voter enters their unique Voter ID on the login page.
- The system activates the webcam to perform a live facial scan.
- The live scan is compared against the securely stored biometric data.
- If the face matches, the system verifies the voter's identity and grants them a secure, temporary session to access the voting booth. This prevents anyone from logging in with a stolen password.
Once inside the secure voting dashboard:
- The voter is presented with the list of participating candidates.
- The voter makes their selection and casts their vote.
- The vote is transmitted directly to a Smart Contract deployed on the Ethereum blockchain.
- The Smart Contract independently verifies that the voter has not already voted.
- Once verified, the vote is permanently recorded on the blockchain ledger.
Administrators have access to a separate, secure dashboard where they can:
- Define the election parameters (Start Date and End Date).
- Add or manage the list of candidates.
- Monitor the ongoing election securely.
- Facial Recognition Authentication: You cannot vote using someone else's credentials. The system uses facial recognition to match the voter. (Note: Active liveness detection/anti-spoofing is currently out of scope for this prototype).
- Immutability: Because votes are stored on the Ethereum blockchain, they cannot be deleted, modified, or tampered with by anyone—not even the administrators.
- No Single Point of Failure: Unlike traditional centralized databases that can be hacked to alter vote counts, the decentralized nature of the blockchain ensures the voting data is distributed and secure.
- Double-Voting Prevention: The smart contract logic strictly enforces the rule that one person gets exactly one vote. Any attempt to vote twice is automatically rejected by the blockchain network.
The project utilizes GitHub's automated CodeQL analysis to continuously scan the codebase for security vulnerabilities, code quality issues, and compliance.
- Status:
(Passing / Clean)
- Coverage: Scans both JavaScript/TypeScript (Frontend & Express App) and Python (FastAPI Authentication Server) codebases.
- Trigger: Automated analysis is performed on every push to the
mainbranch, pull requests, and scheduled weekly (every Sunday at 01:30 UTC).
In recent security remediation cycles, all identified vulnerabilities have been systematically resolved:
- Authentication Security & Secret Management
- Remediation: Split configuration secrets into unique client-side (
NODE_SECRET_KEY) and server-side (FASTAPI_SECRET_KEY) JWT signing secrets. - Production Hardening: Integrated
envalidto validate required environment variables at startup, disabling dangerous fallback defaults in production.
- Remediation: Split configuration secrets into unique client-side (
- Brute-Force & Denial of Service (DoS) Mitigation
- Rate Limiting: Integrated
slowapi(backed by Redis with an in-memory fallback for local dev) on the FastAPI face authentication endpoints./verify-faceis rate-limited to 5 requests per minute per IP, and/enroll-faceis limited to 10 requests per minute per IP. - Payload Size Guards: Implemented strict request payload limits (maximum of 2MB per image sequence) to block memory-exhaustion DoS attacks.
- Rate Limiting: Integrated
- Input Sanitization & Injection Prevention
- Form Field Safety: Implemented strict
maxLength={64}limits and disabled auto-completion on Login views. - Regex Restraints: Added paste listeners (
handlePaste) to reject non-alphanumeric inputs or values exceeding length limits. - Vote Integrity: Enforced candidate verification checks on vote submissions in the frontend, preventing attempts to inject invalid candidate IDs.
- Unused Code Cleanup: Completely removed the experimental MongoDB backend (
server/directory) to reduce the attack surface and eliminate potential NoSQL injection vectors.
- Form Field Safety: Implemented strict
- Replay & Side-Channel Protections
- Anti-Replay Nonces: Added cryptographic random UUID nonces and timestamps to verification requests to block capture-and-replay exploitation.
- Information Disclosure Mitigation: Removed the face-matching proximity
distancescore from the public/verify-faceresponse payload to prevent side-channel reverse-engineering of user faces.
- Secure Headers & Strict CORS
- Response Hardening: Added middleware to both Express and FastAPI servers to set strict
Content-Security-Policy(CSP),Permissions-Policy(camera enabled only for self, microphone/geolocation disabled),X-Frame-Options: DENY,X-Content-Type-Options: nosniff, andReferrer-Policyheaders. - Origin Restriction: Configured CORS origins on the FastAPI server to strictly allow only the specified frontend origin.
- Response Hardening: Added middleware to both Express and FastAPI servers to set strict
- None: There are currently no outstanding security alerts or vulnerabilities detected by CodeQL.
├── server/
│ ├── face-recognition/ # FastAPI face authentication service
│ ├── blockchain/ # Solidity smart contracts, migrations, and Truffle configs
│ └── deploy/ # Docker orchestration & deployment configs (nginx, vercel)
├── docs/ # Project documentation and security notes
├── src/ # Frontend source files (HTML/CSS/JS/TS)
├── index.ts # Express server entry point (Frontend)
└── README.md # Documentation
Follow these steps to download and run the project on your local machine.
- Node.js (v18+)
- pnpm (
npm install -g pnpm) - Python (v3.10 recommended)
- Ganache (Local Ethereum blockchain)
- MetaMask browser extension
- Truffle (
npm install -g truffle) - Webcam (for facial recognition)
You can either fork the repository on GitHub or download it directly to your machine:
git clone https://github.com/Mohammed0572/VotingSystem.git
cd VotingSystemInstall the Node.js packages for the frontend using pnpm:
pnpm installInstall the Python packages for the Face Authentication API:
cd server/face-recognition
pip install -r requirements.txt
cd ../..(Note: The face_recognition Python library requires dlib, which may need CMake and a C++ compiler installed on your system.)
Copy the example environment files and set them up:
cp .env.example .env
cp server/face-recognition/.env.example server/face-recognition/.envGenerate two unique secure secret keys by running this command twice:
node -e "console.log(require('crypto').randomBytes(64).toString('hex'))"Place one key as NODE_SECRET_KEY in the root .env file, and the other as SECRET_KEY in server/face-recognition/.env.
- Open Ganache and create a new workspace (e.g., named "development").
- Link it to the
blockchain/truffle-config.jsfile in the project root. - Configure your MetaMask extension to connect to
http://localhost:7545(Chain ID 1337) and import an account using one of Ganache's private keys.
Open a terminal in the root directory. You can deploy either to your local Ganache network or to the public Sepolia testnet.
For Local Development (Ganache):
cd server/blockchain
npx truffle compile
npx truffle migrateFor Public Testnet (Sepolia):
Ensure you have set the SEPOLIA_RPC_URL (e.g., from Alchemy or Infura) and MNEMONIC in your .env file, and that your account has some Sepolia testnet ETH.
cd server/blockchain
npx truffle compile
npx truffle migrate --network sepoliaThe frontend uses Vite and React. You can either run the development server or build for production.
For Development (Recommended):
npm run devFor Production:
npm run build
npm run serveYou need to run two servers simultaneously in separate terminals:
Terminal 1: Start the Face Auth API
cd server/face-recognition
python -m uvicorn main:app --host 127.0.0.1 --port 8000 --reloadTerminal 2: Start the Frontend Server
If you are using the development server, npm run dev is already running. If you built for production, ensure npm run serve is running.
Open your web browser and go to:
- http://localhost:8080 (if using
npm run dev) - http://localhost:8080 (if using
npm run serve)
This project includes automated testing suites for the Smart Contracts, Backend API, and Frontend components.
The solidity smart contracts are tested using Truffle and Mocha/Chai. Ensure Ganache is running before executing the tests.
cd server/blockchain
npx truffle testThe FastAPI backend is tested using pytest. The tests mock the face recognition modules to run quickly without needing real webcam input.
cd server/face-recognition
pytestThe React frontend components are tested using Vitest and React Testing Library.
npm run testThis system was developed as a Major Project at K.S. School of Engineering and Management by:
This project is licensed under the MIT License. See the LICENSE file for details.

