Repository navigation
Conversation
Adds a browser-based way to add short links to a GitLab-hosted
instance without a local checkout. Submitting a URL at /add picks a
collision-free random slug (reusing the same alphabet/length logic
as v8s-lnk, extracted into scripts/workers/lib/slug.mjs so both
share it) — or uses a self-chosen one, validated with the same
segment rules as v8s-lnk's own custom slugs, checked against
reserved routes and existing links — and triggers a GitLab pipeline
that runs the real v8s-lnk CLI, reusing all existing validation
(check:links), commit, and push logic rather than duplicating it.
The page is gated behind a dedicated Cloudflare Access Application,
since it grants write access to the repository; it uses the same
audience as the general one by default, or a separate
CF_ACCESS_SUBMIT_AUD when configured, so a general-site identity
doesn't automatically also get write access.
The submit page intentionally does NOT get the CSP `sandbox`
directive that custom HTML assets otherwise receive: its own
fetch("/add/submit") needs to run same-origin so the browser sends
the Access session cookie with it. An opaque (sandboxed) origin
would make that same-host fetch cross-origin, and Access's CORS
preflight always rejects (preflight requests never carry cookies),
breaking submission entirely — see isAddPageAssetPath in worker.mjs.
The feature is opt-in via links.remote_submission in site config
(off by default) and GitLab-specific for now — it triggers a GitLab
CI pipeline via the Pipeline Trigger API. A GitHub Actions
equivalent is a reasonable follow-up but out of scope here.
Labels are only translated for en/fr so far (see the comment in
v8s-submit.js); es/it/de fall back to English, unlike the full
en/fr/es/it/de set v8s-lookup.js already has. Translation
contributions welcome.
Built and tested on a live instance (f-l.ca) before porting here.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
felleg
marked this pull request as draft
October 11, 2026 22:23
Collaborator
Author
|
Marking as draft in case anyone wants to take ownership of this PR. I created this not with the intent of merging as is, but more as a proof of concept. |
The job's rules: only skip the job itself on an ordinary push, not pipeline creation — so the commit it pushes (adding the new link) was spawning a second, job-less pipeline every time, pure noise with nothing to run. Add a workflow: rule so a pipeline is only created at all when triggered via the API (SUBMIT_URL/SUBMIT_SLUG set), matching this file's one and only job. Found and fixed after a real instance (f-l.ca) showed this in its pipeline history. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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
Adds a browser-based way to add short links to a GitLab-hosted instance without a local checkout. Submitting a URL at
/add:v8s-lnk, extracted intoscripts/workers/lib/slug.mjsso both share it) — or accepts a self-chosen one, validated with the same segment rules asv8s-lnk's own custom slugs, checked against reserved routes and existing links;v8s-lnkCLI, so all existing validation (check:links), commit, and push logic is reused rather than duplicated.It's opt-in (
links.remote_submission.enabledin site config, off by default) and GitLab-specific for now (triggers a GitLab CI pipeline via the Pipeline Trigger API). A GitHub Actions equivalent seems like a reasonable follow-up but felt like a separate, bigger scope — happy to discuss if there's interest.Access model
The page is meant to sit behind a dedicated Cloudflare Access Application, since it grants write access to the repository. It uses the general Access audience by default, or a separate
CF_ACCESS_SUBMIT_AUDwhen configured, so a general-site identity doesn't automatically also get write access to/add.A CSP/CORS detail worth a careful look
Custom HTML pages (anything an instance places under
custom/public/) get a CSPsandboxdirective withoutallow-same-origin, which gives them an opaque browser origin. If an instance themes/addinto a custom page, its ownfetch("/add/submit")would then be treated as cross-origin by the browser, triggering a CORS preflight — and Cloudflare Access always rejects that preflight (OPTIONSrequests never carry cookies, by spec), breaking submission entirely before the real POST ever has a chance.This PR exempts specifically the
/addpage's asset path from that sandbox (isAddPageAssetPathinworker.mjs) so its fetch keeps running same-origin, carrying the Access session cookie normally. Every other custom page keeps the sandbox. I confirmed this exact failure mode and fix on a live instance (browser console showedCORS Missing Allow Originon the preflight;wrangler tailnever showed the POST reaching the Worker at all until the fix).I'm flagging this prominently because I'm not 100% certain this is the most idiomatic fix for this codebase — an alternative would be extending the existing
Origin: nullCORS handling (isPublicCorsEndpoint/withPublicCorsHeaders, already used for/lookupand/expand) to also coveradd/submit's preflight, but the actual POST would still need Access's session cookie to travel cross-site, which depends on that cookie'sSameSiteattribute (not something this PR controls). The sandbox-exemption approach sidesteps that uncertainty entirely, which is why I went with it, but I'd welcome a second opinion.i18n
Labels are only translated for en/fr so far (noted in a comment in
v8s-submit.js); es/it/de fall back to English, unlikev8s-lookup.js's full en/fr/es/it/de set. Happy to add the remaining translations if that's a blocker, but didn't want to guess at translation quality without review.Testing
npm run test:worker— all passing, including new coverage for: Access gating (dedicated vs. general audience), the CSP-sandbox exemption, random slug generation/collision handling, custom slug validation/reservation/collision, and GitLab pipeline trigger wiring.npm run test:slug,npm run lint,npm run format:check— all passing.npm run test:detachfails in my sandbox for an unrelated, pre-existing local git-config reason (git tag v9.9.9/ "fatal: no tag message?"), reproducible on a clean checkout ofmainwith no changes from this PR — not something this PR introduced.Docs
I didn't add anything to the external docs site (vanityurls.link) since I don't have access to it — happy to write a page for it if that's useful, just let me know the format/location. For now there's a short pointer in
README.mdand a fairly detailed setup comment block indefaults/gitlab/.gitlab-ci.yml.