Correctly handle Slug in POST requests
See original GitHub issueThis is how new URIs get created with Slug headers:
One important issue here is that there is no call toCanonicalUriPath
which means that we might create an identifier here which is not supported by our own server.
There is also no check to see if there are multiple slashes in the slug, which might lead to undefined behaviour internally because there could be references to undefined containers.
In case the generated URI already exists the server will instead generate a new random identifier. Not sure if this is correct since this does not seem to be strictly defined anywhere.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Correct way to handle my URL request - Stack Overflow
1 Answer 1 ... $app->get('/:slug', function ($slug) use ($app) { $db = new dbConn(); $Products = $db->ProductQuery(); // DB querying for 'slug' & ......
Read more >WordPress Slugs: What They Are & How to Change Them
Learn what slugs are, how to optimize them, and how to change them in WordPress in just a few easy steps.
Read more >Django Slug Tutorial | LearnDjango.com
Navigate to http://127.0.0.1:8000/ in your web browser to see the Django welcome page which confirms everything is configured properly.
Read more >Remove slug from custom post type post URLs
WordPress needs the post_type slug to route requests properly. This rule prevents naming conflicts between native WP pages (which render without the slug)...
Read more >Custom Post Types query using SLUG as unique identifier ...
Context I've created a Custom Post Type in WordPress named ... that my CPT is registered correctly and that my data can be...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Right that the Protocol doesn’t say what function servers should run the input through. This is really implementation specific. Clients shouldn’t rely on slugtext being handled deterministically by all servers.
Moreover, client wouldn’t or shouldn’t use Slug if they really want to allocate the URI:
For existing resources, this is interesting and important! If say client can determine what the resulting URI will be from slugtext input (well, especially for open source servers, like CSS, and say doesn’t just default to uuid(+slug) or something), then they can find out about the existence of resources in containers where they do not have read permission (eg. Append on C/ and using POST+Slug to see if 201 or 4xx comes back).
Note the table on POST here https://github.com/solid/specification/issues/14#issuecomment-683480525 and I think the following should really be taken as axiom:
with or without Slug! Don’t get the POST+Slug into a situation where the function depends on C/R existing or not.
For example, avoid using slugtext “as is” ie. generate uuid+slug – something unguessable, or perhaps only allow slugtext “as is” in certain cases eg. having Read, Append on C/ will grant the user from knowing whether something exists or not. So, POST C/ with Slug: R where C/R already exists can then maybe respond with 409 or something.
So IMO, if a server allows Slug, it should consider the above.
BTW, if the above is reasoning is agreeable - not necessarily the exact text or the implementation here, I can try to make this more apparent in the Protocol.
I agree that’d be simplest for the server and the outcome is least confusing for the client (given possible outcomes).
In CSS, a POST succeeding is independent of C/R existing, but the generated URI will be different so that way some information is leaked. In the future we could look into making the part that generates the URI based on a slug injectable, so if needed something can be injected that obfuscates this.
I agree with all of the above, and it would be useful to have a bit more official information on how the slug should be handled.
@BelgianNoise, adding this change to your implementation would then also require rewriting the tests that incorrectly use POST like this, so feel free to not fix the slash part yet in case that would be too much.