Skip to content

Latest commit

 

History

History
114 lines (91 loc) · 6.21 KB

security.md

File metadata and controls

114 lines (91 loc) · 6.21 KB

Security

Threat model, controls and their tests. Reporting vulnerabilities: SECURITY.md. Findings in the original code that led to this design: audit.md.

Assets and attackers

Asset Why it matters
Hidden test data Leaking it lets anyone pass every problem
Verdicts and standings Forged results corrupt rankings
Accounts and sessions Impersonation, admin takeover
The judge host Runs untrusted code from anyone with an account
Personal data E-mail addresses, names, country

Attackers considered: anonymous visitors, registered users trying to cheat or escalate, malicious code submitted to the judge, and a network attacker between browser and server (mitigated by HTTPS in production).

Controls

Authentication and sessions

Control Implementation Test
Passwords hashed with Argon2id Argon2PasswordEncoder (Spring Security defaults) —
Password policy 8-128 chars, a letter and a digit AuthFlowIT.weakPasswordAndBadUsernameAreFieldErrors
No account enumeration on login Same message for unknown e-mail and wrong password; a dummy hash is checked for unknown e-mails so timing is similar AuthFlowIT.wrongPasswordAndUnknownEmailGiveTheSameAnswer
No enumeration on password reset Always 202, mail only if the account exists AuthFlowIT.passwordResetChangesPasswordAndRevokesSessions
Login brute force 10 attempts per minute per IP, 429 with Retry-After AuthFlowIT.loginIsRateLimited
Session cookie Opaque ID, HttpOnly, SameSite=Lax, Secure behind HTTPS, 7-day timeout, stored server-side AuthFlowIT.sessionCookieIsHttpOnly
Session fixation Session ID changed at login —
Revocation Logout, logout everywhere, password change (other sessions), password reset (all sessions), account deletion AuthFlowIT.logoutEndsTheSession, changingPasswordKeepsThisSessionAndEndsOthers
E-mail verification and reset tokens 256-bit random, only SHA-256 stored, single use (atomic update), 24 h / 1 h expiry AuthFlowIT.registerLogsInAndSendsVerificationMail, resetTokenExpiresAfterOneHour
CSRF Double-submit cookie (XSRF-TOKEN + X-XSRF-TOKEN) on every state-changing request AuthFlowIT.stateChangingRequestsNeedCsrfToken

Authorization

Rule Test
/api/v1/admin/** requires role ADMIN (401 anonymous, 403 users) AuthorizationIT.adminApiNeedsTheAdminRole
Unpublished contests and their problems are 404 for non-admins AuthorizationIT.unpublishedContestsAreInvisibleToUsers
Problems are 404 until the contest starts AuthorizationIT.problemsAreHiddenUntilTheContestStarts
Submissions (with source code) visible to their owner and admins only; others get 404 AuthorizationIT.submissionsAreVisibleOnlyToOwnerAndAdmin
Public profiles never contain e-mail or password data AuthorizationIT.publicProfileDoesNotExposeEmailOrPassword
Comments: verified e-mail to post; delete by author or admin AuthorizationIT.commentsNeedVerifiedEmailAndOnlyAuthorOrAdminDeletes
Users change only their own account (/me); no endpoint takes another user's ID for writes by design

Judging integrity

  • The server judges; clients send only source code (JudgingIT.correctSolutionIsAccepted).
  • Hidden test inputs and expected outputs are never returned; program output is stored only for sample tests (JudgingIT.hiddenTestDataIsNeverReturned).
  • Only in-contest submissions count for standings (StandingsIT.icpcScoringWithPenaltyAndSharedRanks).
  • Submissions are idempotent per clientRequestId (JudgingIT.clientRequestIdMakesSubmitIdempotent).

Untrusted code

See judge.md: isolate sandboxes, unprivileged user, no network, CPU/memory/process limits per run, container-level limits for the judge in production. The Piston container is privileged; it is never exposed and shares a network only with the API.

Input handling

  • Bean Validation on every request body; field errors returned as errors[] without echoing internals.
  • Size limits: source and run input 64 KiB (also checked in bytes), tests 1 MiB, request headers 16 KiB, multipart disabled.
  • SQL only through bound parameters; ILIKE search escapes % and _.
  • Markdown is rendered in the browser without raw HTML.

HTTP hardening

  • CSP default-src 'self'; script-src 'self' (Monaco is bundled, no CDN), frame-ancestors 'none', X-Content-Type-Options, Referrer-Policy, Permissions-Policy, Cross-Origin-Opener-Policy (nginx); HSTS at Caddy.
  • Errors are RFC 9457 problem details without stack traces or exception messages (server.error.include-*: never); unexpected errors return a generic message and a requestId that links to the server log.
  • Actuator is not routed publicly; only health, info and prometheus are exposed, health details hidden.
  • The API trusts X-Forwarded-For only from private-network proxies.

Secrets

  • No secrets in the repository: configuration comes from the environment (.env, ignored by Git; template .env.example).
  • CI runs gitleaks on the full history.
  • Historical secrets. The original code committed a JWT signing secret and JDoodle API credentials (see audit.md). They are removed from the current tree, but remain in Git history. Treat them as compromised: the JWT secret is no longer used by anything; the JDoodle client secret must be rotated in the JDoodle dashboard by the account owner.

Logging and privacy

  • Structured JSON logs (ECS) with requestId; passwords, tokens, session IDs and mail bodies are never logged.
  • Deleting the account removes the user's submissions, registrations and comments.

Residual risks and follow-ups

Risk Mitigation today Possible next step
Piston escape (kernel or isolate bug) Isolate sandbox, no job network, private network, container limits Run Piston on a separate VM; gVisor
Rate limits are per instance Single API instance Shared Bucket4j store when scaling out
No 2FA for admins Strong passwords, rate limits, revocation TOTP for the ADMIN role
Dependency vulnerabilities Dependabot, npm audit in CI Container image scanning in CI