fix(console): resolve numeric :id by primary key, not a colliding slug#659
Closed
jirkamotejl wants to merge 1 commit into
Closed
fix(console): resolve numeric :id by primary key, not a colliding slug#659jirkamotejl wants to merge 1 commit into
jirkamotejl wants to merge 1 commit into
Conversation
The console loads records via FriendlyId, which matches a numeric :id param against the slug column before the primary key. A record whose slug equals another record's id (e.g. a file uploaded as "349444.jpg" gets slug "349444", colliding with id 349444) hijacked the lookup, so opening/selecting/editing that id returned the wrong record. - Console finder prefers the primary key for numeric params, falling back to FriendlyId only for genuine (non-numeric) slugs. - Folio::File slugs can no longer be purely numeric, so the slug and id namespaces never overlap (covers public download/video lookups too).
mreq
approved these changes
Jun 30, 2026
mreq
left a comment
Member
There was a problem hiding this comment.
👍
@jirkamotejl To uzce souvisi s PoC #658 kdy prepiname celou console ze slugu na ID. Je to ale relativne dalekosahle rozhodnuti, ktere si musime i s @ornsteinfilip posvetit.
Contributor
Author
|
@mreq merguju zatím aspoň tohle, ať tam nemáme regresi |
Contributor
Author
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.
Problem
The console loads records via FriendlyId (
@klass.friendly.find(params[:id])), which matches a numeric:idagainst the slug column before the primary key. A record whose slug equals another record's id hijacks the lookup.This bites files: a file uploaded as
349444.jpggets slug349444. Once thefolio_filesid sequence reaches349444,friendly.find("349444")returns the slug owner instead of the file at id349444— so opening / selecting (file picker) / editing that id shows the wrong file. It grows over time as the id sequence advances into the numeric range historically used as file names, and is invisible in the data (each record is fine; only the lookup is ambiguous).Fix
find_console_resource(Folio::Console::BaseController): for a numeric:id, prefer the primary key (find_by(id:)), falling back to FriendlyId only for genuine non-numeric slugs. Slug-addressed resources (pages, articles — non-numeric slugs) are unaffected; the numeric branch never triggers for them.Folio::File#normalize_friendly_id: file slugs can no longer be purely numeric (neutral fallback), so the slug and id namespaces never overlap going forward. This also protects the public download/video lookups that resolve files via FriendlyId.Tests
file_picker_file_hashwith a numeric id returns the file at that id even when another file's slug equals it (reproduces the bug; red before, green after).Folio::Fileslug is never purely numeric.by_query, the slug unique-index spec, and shared files.