3dd9ab60e897ccec19820c10fec4182c34feb313
8
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
b7c9818dd6 |
Pictures: refuse a header that claims too many pixels, before decoding
The first fuzz run on cnx01 found it: a drawn signature of 798 bytes whose PNG header says 300 x 738,197,594 pixels made krilla ask for 885 GB. A failed allocation aborts the process, so one such signature on any client link (or such an upload in a pack) would have ended the app for everyone; reproduced on a normal build, with a valid IHDR checksum. krilla decodes a picture as soon as it makes it, so papers::pixels reads the size from the header first, with the decoder krilla uses (png, zune-jpeg, image-webp; already in Cargo.lock, now direct dependencies), and papers::picture refuses more than MAX_PIXELS (50 megapixels, about 200 MB decoded) before krilla sees the file. The pack and the Documents tab print a note for such a file, the signed copy refuses it, and the client page refuses the signature (422, "did not arrive whole") before anything is stored. tests/fuzz_cases/signed_copy/png-claims-885-gigabytes is the finding, replayed on every push; unit tests for the header sizes and the limit, and the agreements test sends the forged signature. |
||
|
|
7b5ec35e7c |
Property tests for what people paste and type; a one-letter given name
src/props.rs (proptest, 256 cases each, about 3 s of cargo test) holds the rules every input must keep: any text reads as a passport zone without a panic and two lines of zone characters always parse; a composed zone reads back field by field; OCR finds the zone among other lines in either order, in lower case and with spaces, and puts back digits read as letters in the dates; a Thai number with its check digit is valid and another check digit is not; same_name is symmetric and ignores order and case; a kept position and its Google Maps and OpenStreetMap links read back, a swapped pair is outside Thailand; a form date is in range and reads back; normalize is idempotent and blocks are never empty; a diff rebuilds both versions; any change to a journal entry changes its hash, also text moved between two fields; the PDF's line wrap keeps every letter and no line starts with a mark. Their first run found a bug: the photo reader dropped a one-letter given name, since a lone K, C, E or L in filler counts as a misread <. The letter right after the << between the names is now kept (unit test a_one_letter_given_name_is_kept; the shrunk cases are in proptest-regressions/props.txt). 50,000 cases each pass. proptest without fork and timeout (rust-version 1.88; the fleet builds with 1.95). AGENTS.md says when to add one, PLAN has the fuzzing steps. |
||
|
|
2e465a463c |
Phase 8 begins: mail, the Notifications page and a test mail
The app sends mail by SMTP submission (src/mail.rs, lettre over rustls with the system's CA bundle, ring as reqwest): VISA_SMTP_HOST, _PORT (465), _SECURITY (tls, starttls, or none for a server on this machine), _USER and the password from VISA_SMTP_PASSWORD_FILE or the credential smtp-password; VISA_MAIL_FROM defaults to "Lanna Desk <user>", VISA_MAIL_REPLY_TO is optional. Without VISA_SMTP_HOST mail is off. The settings are checked at start; the password stays out of Debug. The Notifications page (Office) shows the sender, server and connection, sends a test mail to the address given (offered again next time) and shows the mail server's answer; every message sent or failed is logged (notifications, migration 0011). Text messages say "not yet". Tests: a fake SMTP server checks the envelope, Subject and Reply-To, a refused recipient logged as failed, a bad address and mail switched off. 121 unit, 65 integration. |
||
|
|
43ed75d81b |
Phase 7: the client link
Staff make a link for a person (or "+ New client": a record with only the name they know, and its link); the client fills in their own record from their phone without a login, and presses Send. - Links (src/links.rs, migrations/0006): the table keeps the SHA-256 of the token only, as sessions do; the link is shown once, to copy, to email (mailto with the person's address) or as a QR code (qrcode crate, inline SVG). It is open 14 days, until Send, or until staff close it; a new link closes the earlier one. States open, opened, sent, closed, expired. - The client's pages at /c/<token> (src/web/client.rs, client_*.html in a frame of their own, phone first): About you, Passport (the photo reader; a zone fills in the personal details still empty), Address in Thailand, Contact, Documents, Send. Each part is saved on its own, straight into the record. Forms carry the link's own token plus the same-site check. A passport with the same number is changed; an address unlike the current one is added beside it, so the current one and its TM.30 receipt stay; a second save changes what the link added. Uploads (passport page, photo, visa, arrival stamp, TDAC, work permit, other) go through the same checks and encrypted store as staff uploads, tied to the person's newest record of their kind. - Audit: the client's views and changes carry the actor `link <id>`; actions send and close and entity link are new. The person's page shows the newest links, when they were opened and sent, and each record the client changed, with the fields, to check. - Demo data: Erika sent her link an hour ago (phone and email changed), Jane opened hers. - documents::read_upload returns why it refused, so the client's pages answer in their own words. Checks: fmt, clippy; 101 unit and 54 integration tests (tests/client.rs: the link shown once and kept as a hash, a new client, the whole client flow with the login on, forged, closed, expired and made-up links); layout check light/dark desk/phone on the client pages, the person page and the new client form: no problems; the camera reader on the client's passport page with a fake camera filled the form and Send closed the link. |
||
|
|
fc8c1b6a44 |
Phase 6: the Non-B extension pack, checked and printed as one PDF
The pack for an extension of stay based on work, item by item in the
officer's order, each with its state at the date of the application:
generated, has blanks, uploaded, missing, out of date, no date, or not
needed for this person.
- src/pack/mod.rs: the rules as a pure function of the records and the
documents, a unit test per rule. Copies belong to their record (the
current passport, the last arrival and its TDAC, the re-entry permit it
came back on, every extension since the passport was issued, the last
90-day report, the current address, the work permit); the company
certificate and BOJ.5 count six months from their certification, the
balance sheet 17 months from its year's end, PND.1, SPS 1-10 and PP.30
the last three months, PND.91 the latest year; two photos of the office.
Sources in docs/PLAN.md (thailand.go.th 006_008, Immigration Division 1).
- A Pack tab: the six parts, each item's files and form, and what fixes it
(the upload with the kind and record chosen, through the new ?kind= on
the Documents tab and on a company's page; a document's date; a record).
The application's fields are the Forms tab's, and both tabs carry them.
- /people/{id}/pack.pdf (src/pack/pdf.rs): a cover sheet with the contents
page by page and what to sign and bring, the five forms, then every copy:
uploaded PDFs as they are (a PDF 2.0 upload makes the pack 2.0), images
fitted on A4 and turned as their EXIF orientation says, a page in place of
a file that cannot be read; bookmarks per item. krilla gains its
raster-images feature. The audit logs the forms' codes and a view or
download of each document that went in.
- A company's page shows its part of every employee's pack.
- The extension deadline links to the pack; at 390 px the six tabs fit, as
"Visa and stay" reads "Stay" on phones.
- Demo data shows every state.
- The Forms tab showed "Back about" and "Purpose" empty: the template read
app.back and app.purpose, which serialize as "return" and "for".
docs/PLAN.md: phase 6 done, open question 2 settled (the office is the
application's), phase 7 planned from Alex's answers: the client link, the
MRZ from a phone photo, later the signed agreement; reminders move to 8.
Checks: cargo fmt, clippy -D warnings, 97 unit and 47 integration tests;
layout_check 0 problems (pack, company, forms, dashboard, person; light,
dark, desk, phone); the tabs measured at 390 and 360 px; the pack PDF
rendered and looked at, an EXIF-turned JPEG upright.
|
||
|
|
a2cedcdd7e |
Phase 5: the Immigration Bureau's forms, filled in from the records
A Forms tab on each person fills in TM.7, STM.2, STM.9, STM.11 and STM.1 for an extension of stay, TM.47 for a 90-day report and TM.8 for a re-entry permit. The Bureau's blank pages (forms/, with their sources and checksums) go unchanged into a new PDF, and the values are written on the dotted lines in Sarabun; boxes are ticked and the title circled where a form asks. scripts/gen_layout.py measures the blanks into src/papers/layout.rs. The tab says what would stay blank and links to where it is added. What only the application says (the date, the office, the reason, the days, a trip) is carried in the links and never stored. The extension's five forms also come in one PDF. Opening or downloading a form is audited as entity "form" with the forms' codes, never their values. Migration 0005 adds what STM.1 and STM.11 ask of the company (capital, revenue, equity, staff, a coordinator), a work permit's salary and contract dates, and where an arrival came from. The Nix package now takes forms/. |
||
|
|
2061e3a024 |
Phase 4: documents, encrypted on the server
Scans and photos of a person's papers, and a company's documents for the extension packs, uploaded on a dashed strip that takes dropped files: up to 10 files of 20 MB each, 64 MB in all; PDF, JPEG, PNG and WebP, told by their first bytes. - src/files.rs: one file per document as <id>.vdoc, AES-256-GCM under a key per file (HKDF-SHA256 from the file key and a random salt in the header); the document's id is authenticated with it. The key comes from VISA_FILES_KEY_FILE or the credential files-key; with the login on, the app does not start without it and VISA_FILES_DIR. - migrations/0003: documents (a person's or a company's, the record it belongs to, kind, date on it, note, file name, type, size, SHA-256); audit_log gets company_id and the action download. - A Documents tab per person, the documents on the company's page, and each record's documents next to its Edit link with "+ Document". - An upload's form token is its first field and is checked before any file is read; the guard lets multipart through only to the two upload addresses. - Files open under their own CSP and are never cached; a download is named after the person or company, the kind and the date. Every upload, view, download, change and deletion is in the audit log. - visa files-check; demo documents in seed-demo; scripts/dev.sh keeps the local documents and their key in .dev/; /favicon.ico for image and PDF pages. Tests: 57 unit and 33 integration (8 new for documents). Edge check of the strip (choose, drop, too large), an upload, the PDF and image viewers under the file policy: no problems, no console errors. |
||
|
|
2e009700a9 |
Phase 1: app, Kanidm login, people, passports, addresses, audit log
visa.buildfor.life keeps the immigration records of the foreigners B4L looks after. This first phase is the base the deadlines and extension packs build on (docs/PLAN.md, phases 2 to 7). - One Rust binary (axum 0.8, minijinja, sqlx on PostgreSQL) with its templates, static files and migrations compiled in. - Login through Kanidm (OpenID Connect with PKCE and a nonce, ES256), client visa-web, group visa; sessions in PostgreSQL keyed by the SHA-256 of the cookie. VISA_INSECURE_NO_LOGIN=1 for loopback development only. - Same-site check and form token on every POST; a CSP without inline script or style; security headers. - People: list with filter, page, create, edit, archive, restore. - Passports from the machine-readable zone with check digits (ICAO 9303 TD3); expiry warnings at 12 and 6 months. - Addresses in Thailand in the order Thai forms use, with the house master and the TM.30 receipt. - Append-only audit log of every view and change, with the names of the changed fields but never their values (PDPA); the Activity page. - Invented demo people (visa seed-demo, refused when login is on). - 40 tests: unit tests, pages with demo data, the forms, the audit log and the whole login against a fake OpenID provider. - CI: gitleaks over the history, fmt, clippy and the tests against PostgreSQL 18; the pre-commit secret scan. |