make blog/instance description a SafeString #223
No reviewers
Labels
No labels
A: API
A: Backend
A: Federation
A: Front-End
A: I18N
A: Meta
A: Security
Build
C: Bug
C: Discussion
C: Enhancement
C: Feature
Compatibility
Dependency
Design
Documentation
Good first issue
Help welcome
Mobile
Rendering
S: Blocked
S: Duplicate
S: Incomplete
S: Instance specific
S: Invalid
S: Needs Voting/Discussion
S: Ready for review
Suggestion
S: Voted on Loomio
S: Wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: Plume/Plume#223
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "fix/safe-string"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
long_description & short_description's documentation say they can be
Markdown, but they are String, not SafeString.
This led to escaped strings being printed in the editor
https://github.com/Plume-org/Plume/issues/220
n.b.: This is a work-in-progress and does not solve the problem yet
For the
FromFormValue
problem, you should be able to delegate the parsing to theString::from_form_value
method. I haven't compiled this but it should go something like:you can change
&<String>::new
here to just""
, sinceSafeString::new()
takes a&str
. It will save an allocation, at least, especially since currently the allocation just gets dropped and another is made in theammonia::clean
function.Same comment here re:
String::new
and here as well
@pwoolcoc thank you for your review!
i've pushed one commit which addresses your concerns wrt allocation, and one which adds your
imp FromFormValue for SafeString
… now… to make use of it ;)(by which i mean, "now to find out how to make use of it")
@igalic Thanks for working on this. Rocket will use your
FromFormValue
directly if you replace theString
fields of the form struct (InstanceSettingsForm
insrc/routes/instance.rs
) bySafeString
.SafeString
s are cleaned at creation, you must either callSafeString::new(&str)
orammonia::clean(&str)
(which is used internally by new) when creating such struct, not built it directly from an unstrusted String.big confused about @pwoolcoc's code here ;)
@ -104,0 +106,4 @@
use rocket::http::RawStr;
impl<'v> FromFormValue<'v> for SafeString {
type Error = &'v RawStr;
can someone help me understand what
'v
means?this should be fixed in
d62c72d
@ -104,0 +106,4 @@
use rocket::http::RawStr;
impl<'v> FromFormValue<'v> for SafeString {
type Error = &'v RawStr;
'v
is a lifetime, because you got a reference to aRawStr
, not aRawStr
directly. This helps Rust figure out how long a struct containing pointers (references) can live, and when some parts of it might got dropped and it's therefore no longer safe to access a struct. You can read more about it in rust's book, which probably explain better than me 😉@ -104,0 +106,4 @@
use rocket::http::RawStr;
impl<'v> FromFormValue<'v> for SafeString {
type Error = &'v RawStr;
okay, thanks! i was just not clear on the notation
okay! so with the last commit (
06718a5c8a
) i've now done everything everyone on here has so helpfully suggestedwhich means that it now… still doesn't work 😅
I think you did all that was needed on rust side. Now you just have to edit templates to add
| safe
whenever one of the vars you changed to SafeString is used as done here for user's summaryd355379e01/templates/users/header.html.tera (L41)
This should be in
templates/instance/admin.html.tera
I think.but that's not done with content:
d355379e01/templates/posts/new.html.tera (L31)
@fdb-hiroshima i tried
| safe
anyway, and it did nothing!The exact line you need is
<textarea id="short_description" name="short_description">{{ form.short_description | default(value=instance.short_description | safe) }}</textarea>
, with the| safe
insidedefault
's brackets. The difference with post's content isinstance.short_description
is read bydefault
, not passed directly (same goes withlong_description
). I'm sorry I was not clear enough in my previous comment