fix(cors): allow Office add-in origins (addin.postguard.eu + localhost:3000) and DELETE method#179
Merged
Merged
Conversation
Browser callers from the Office add-in were blocked by CORS when reaching /fileupload/* and /filedownload/*: the preflight returned no Access-Control-Allow-Origin because the production allowed_origins regex only matched the postguard.eu/nl website. - conf/config.toml: extend allowed_origins to also match https://addin.postguard.eu (Outlook prod) and https://localhost:3000 (Office add-in dev), keeping the existing postguard.(eu|nl) origins. - build_rocket CORS: add DELETE to allowed_methods so the preflight advertises GET, POST, PUT, DELETE. Content-Type and Authorization are already in the allowed-headers list. - Add integration tests over the real build_rocket CORS fairing asserting the preflight succeeds (echoes Allow-Origin, advertises all four methods and the required headers) for both add-in origins, and is rejected for an unlisted origin. Refs encryption4all/postguard#154 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The comment claimed a config typo would fail the suite, but the CORS tests use this hand-maintained copy and never read conf/config.toml. Reword to state it is a copy that must be kept in sync. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
rubenhensen
approved these changes
Jun 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the CORS failure reported in encryption4all/postguard#154: browser callers (pg-js inside the Office add-in) were blocked when reaching
/fileupload/*and/filedownload/*, because the preflight returned noAccess-Control-Allow-Origin. The productionallowed_originsregex only matched thepostguard.eu/postguard.nlwebsite, so the add-in's origins never matched.Changes
conf/config.toml— extend theallowed_originsregex to also match the add-in origins from the issue, keeping the existing website origins:https://addin.postguard.eu— Outlook add-in (prod)https://localhost:3000— Office add-in dev serverhttps://postguard.eu/https://postguard.nl— unchangedbuild_rocketCORS (src/main.rs) — addMethod::Deletetoallowed_methods, so the preflight advertisesGET, POST, PUT, DELETEas requested.Access-Control-Allow-Headersalready includesContent-TypeandAuthorization(plusContent-Range,CryptifyToken,Range,X-Recovery-Token,X-POSTGUARD-CLIENT-VERSION), so no header change was needed.Tests
Two new integration tests boot the real
build_rocketCORS fairing with the exact production regex (kept in aPROD_ALLOWED_ORIGINSconst, a hand-maintained copy of the shipped regex):cors_preflight_allows_addin_and_localhost_origins— sendsOPTIONS /fileupload/initfrom both add-in origins and asserts a 2xx preflight that echoesAccess-Control-Allow-Origin, advertises all four methods, and listsContent-Type+Authorization.cors_preflight_rejects_unlisted_origin— asserts an unlisted origin gets noAccess-Control-Allow-Originheader.This is the in-process equivalent of the
curl -i -X OPTIONSrepro from the issue. Booting the standalone binary to curl it live isn't feasible here (it requires a reachable PKG server at startup), but the test drives the identical fairing + config path the curl would hit.cargo fmt --all -- --check,cargo clippy --all-targets -- -D warnings, andcargo test --all-targets(127 passed) all pass locally.Closes encryption4all/postguard#154
🤖 Generated with Claude Code