havenwood changed the topic of #ruby to: Rules: https://ruby-community.com | Ruby 3.2.2, 3.1.4, 3.0.6, 3.3.0-preview1: https://www.ruby-lang.org | Paste 4+ lines to: https://gist.github.com | Books: https://t.ly/9ua4 | Logs: https://libera.irclog.whitequark.org/ruby/
brw has quit [Quit: The Lounge - https://thelounge.chat]
brw has joined #ruby
<johnjaye> leftylink: your impersonation of an ordinary person was flawless
doyle has joined #ruby
<doyle> Olá! humanos
ixti has quit [Remote host closed the connection]
desnudopenguino1 has joined #ruby
desnudopenguino has quit [Ping timeout: 260 seconds]
desnudopenguino1 is now known as desnudopenguino
doyle has quit [Read error: Connection reset by peer]
markong has quit [Ping timeout: 268 seconds]
ap4y has quit [Ping timeout: 246 seconds]
kenichi has quit [Server closed connection]
kenichi has joined #ruby
kenichi has quit [Changing host]
kenichi has joined #ruby
brokkoli_origin has quit [Quit: (Leaving)]
brokkoli_origin has joined #ruby
<mooff> = :hola
<ruby-eval> => :hola
caedmon has joined #ruby
caedmon has quit [Ping timeout: 260 seconds]
FetidToot has joined #ruby
moldorcoder7 has quit [Read error: Connection reset by peer]
nektro has quit [Server closed connection]
nektro has joined #ruby
justache has quit [Server closed connection]
justache has joined #ruby
panella32 has joined #ruby
<panella32> Hi
<panella32> I have something to ask. Let me know please if you have any idea
<panella32> Considering this erb tag: <%= image_tag @movie.cover_path %>
<panella32> What is the recommended way to add a static directory path in front of @movie.cover_path preferably without using string interpolation?
<leftylink> it sounds like the way to go would be to modify cover_path to return the value, including the path that should be added in front, no?
panella32 has quit [Ping timeout: 240 seconds]
caedmon has joined #ruby
panella32 has joined #ruby
<panella32> leftylink Sorry I got disconnected. You right but logic aside I'd like to know what's the proper way to add string inside a erb tag? I've heard string interpolation could be dangerous..
<leftylink> then I think the best course of action is to seek clarification from the sources that said it could be dangerous - we would have trouble defending against a danger we do not understand
<leftylink> we do not want to be either too cautious (and avoid a good solution because of groundless potential dangers that turn out to never surface) or too careless (and run into a problem that we should have avoided)
<leftylink> for example, if we know that we need to avoid cross-site scripting, then that implies we would want to do the things in https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html
<leftylink> but if instead all we know is "it's dangerous" without understanding why, we can get nowhere.
<panella32> "if a developer writes a query manually using string concatenation or interpolation, without properly sanitizing or validating user input, it can leave the application vulnerable to SQL injection attacks."
<panella32> Couldn't find a better referrence.
<panella32> So I thought I'd better avoid string interpolation specially when it comes to dealing with user input data.
<leftylink> so now you know that the danger is coming from anywhere where a potential attacker could control the contents of the string. now we consider the question previously asked which is how to prepend a static path in front. this static path presumably cannot be controlled by an attacker (unless they have the ability to change the code that the server is running), so adding a fixed prefix to the string does not
<leftylink> introduce any danger beyond any danger that was already present (for example, if an attacker can specify cover_path).
<panella32> Sorry if it was ambiguous. The static part is okay and I did not count it as a user input data, but the instance variable coming from db somehow could be set by users (at least the image name as a part of image path, I'm not sure because it's not implemented yet)
<leftylink> indeed, so that will be a problem, regardless of whether the static part is added or not
<leftylink> so the static part seems irrelevant to this question, then
<panella32> Why not. Considering my 'string interpolation' version of than line it indeed is relevant: <%= image_tag "some/static/path/#{@movie.cover_path}" %>
_ht has joined #ruby
<leftylink> well, what I mean by irrelevant is that <%= image_tag "some/static/path/#{@movie.cover_path}" %> is exactly equally as dangerous as <%= image_tag @movie.cover_path %>
<leftylink> so either they're both dangerous, in which case you should take the appropriate actions in response, such as the actions listed in https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html, or neither are dangerous, in which case you do nothing
<leftylink> thre is no world in which one is dangerous and the other isn't. it's either both or neither
mexen has joined #ruby
<panella32> The whole time I consider the <%= image_tag @movie.cover_path %> totally safe because I thought it would be sanitized by rails (ver7) by default even if there was any malicious data in db
<panella32> Thanks for clarifying.
<leftylink> @movie.cover_path is a string being passed to the function image_tag. "some/static/path/#{@movie.cover_path}" is also a string being passed to the function image_tag
<panella32> Thanks I am actively checking a related section of a course that I've already took just to compare with this scenario... Should not take too long!
<leftylink> so we see the string interpolation is the wrong place to look for the danger. instead, it's any place where an attacker-controlled string can appear in HTML, not just interpolation. so for example anywhere where image_tag is used
<leftylink> it's possible image_tag does something to help here, but I wouldn't know since this isn't the rails channel and therefore I wouldn't know about rails
<panella32> I think you right overal. Even though I may be able to provide the source later but for the record I do remember an instructor once said we must avoid "string interpolation" when it comes to writing activerecord queries. MaybeI had that in mind and its the reason I am too careful and try to avoid SI at any cost! Thanks anyway.
<panella32> And as you said such thing (in this case: activerecord) is a #rubyonrails thing
caedmon has quit [Ping timeout: 240 seconds]
<panella32> leftylink from a credible linkedin course: https://i.imgur.com/J4ojwGQ.png
<panella32> "if you use a string, avoid dropping values into that string using string interpolation. This is unsafe and it may create a vulnerability to SQL injection. Instead, the safe way to do it is to use an array with a string that has a question mark in it as a placeholder and then the second element of the array is the value to insert at that placeholder. Rails will sanitize the value before it inserts it."
<leftylink> yes from this we see that the place where user-controlled strings are used leads us to the type of vulnerability we need to look out for. if it's in a SQL query, we look out for SQL injection. and if it's in HTML we look out for cross-site scripting
<panella32> Thanks! It was an eye-opening discussion for me :) As a beginner learned a lot through it
hightower2 has quit [Ping timeout: 246 seconds]
panella32 has quit [Ping timeout: 240 seconds]
_ht has quit [Remote host closed the connection]
roadie has joined #ruby
jprokop has joined #ruby
pavelz has quit [Server closed connection]
pavelz has joined #ruby
teclator has joined #ruby
friendlypunk has quit [Remote host closed the connection]
friendlypunk has joined #ruby
infinityfye has joined #ruby
Sankalp has quit [Ping timeout: 248 seconds]
Sankalp has joined #ruby
jvalleroy has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
jvalleroy has joined #ruby
tomtmym has joined #ruby
tomtmym has joined #ruby
pyeri has joined #ruby
pyeri has quit [Client Quit]
hightower2 has joined #ruby
hightower3 has joined #ruby
hightower2 has quit [Ping timeout: 240 seconds]
dalan0382 has joined #ruby
dalan0382 has quit [Client Quit]
TomyWork has joined #ruby
dalan0382 has joined #ruby
moldorcoder7 has joined #ruby
BazzaBazaa has joined #ruby
hightower3 has quit [Ping timeout: 240 seconds]
BazzaBazaa has quit [Remote host closed the connection]
markong has joined #ruby
yassernasc has joined #ruby
infinityfye has quit [Quit: Leaving]
BazzaBazaa has joined #ruby
<leah2> hm, why doesnt Queue implement Enumerable?
BazzaBazaa has quit [Remote host closed the connection]
BazzaBazaa has joined #ruby
BazzaBazaa has quit [Remote host closed the connection]
BazzaBazaa has joined #ruby
BazzaBazaa has quit [Remote host closed the connection]
intelligent_boat has quit [Ping timeout: 265 seconds]
intelligent_boat has joined #ruby
BazzaBazaa has joined #ruby
<ox1eef_> Probably because it can block.
MalusVulgaris has joined #ruby
hightower2 has joined #ruby
<leah2> so?
<leah2> reading from IO can block too, yet IO#each exists
<ox1eef_> Fair point!
<leah2> well. i'll write a little warpper
<Bish> how do i get from Vec<(a,b)> to HashMap<a, Vec<b>>
BazzaBazaa has quit [Remote host closed the connection]
BazzaBazaa has joined #ruby
<ox1eef_> Hash[[vec]]
yassernasc has quit [Remote host closed the connection]
yassernasc has joined #ruby
gravel86 has joined #ruby
<Bish> lul, wrong channel
<leah2> still false tho :p
marath0 has joined #ruby
<ox1eef_> >> tup = [1,2]; Hash[*tup.each_slice(2).to_a].tap { |h| h.each { |k,v| h[k] = [*v] } }
<ruby[bot]> ox1eef_: # => wrong element type Integer at 0 (expected array) (ArgumentError) (https://carc.in/#/r/f7vq)
<ox1eef_> >> tup = [1,2]; Hash[tup.each_slice(2).to_a].tap { |h| h.each { |k,v| h[k] = [*v] } }
<ruby[bot]> ox1eef_: # => {1=>[2]} (https://carc.in/#/r/f7vr)
gravel86 has quit [Ping timeout: 240 seconds]
marath0 has quit [Ping timeout: 240 seconds]
BazzaBazaa has quit [Remote host closed the connection]
_ht has joined #ruby
yassernasc has quit [Remote host closed the connection]
yassernasc has joined #ruby
lena64t has quit [Quit: WeeChat 4.0.0-dev]
wakaflaka has joined #ruby
caedmon has joined #ruby
caedmon has quit [Ping timeout: 240 seconds]
eddof13 has joined #ruby
yassernasc has quit [Remote host closed the connection]
MalusVulgaris has quit [Remote host closed the connection]
foobarbaz has joined #ruby
foobarbaz has quit [Quit: Client closed]
foobarbaz has joined #ruby
roshanavand_ has joined #ruby
testGuest93 has joined #ruby
testGuest93 has quit [Client Quit]
testGuest93 has joined #ruby
testGuest93 has left #ruby [#ruby]
ikke has quit [Quit: WeeChat 3.8]
<Bish> yeah well, .to_h does it aswell
caedmon has joined #ruby
markong has quit [Ping timeout: 260 seconds]
roshanavand_ has quit [Ping timeout: 248 seconds]
<leftylink> because in most cases I do this I have to handle duplicate keys, I would have to write it differently (I use group_by then transform_keys)
<leftylink> nope
<leftylink> group_by then transform_values
<ox1eef_> Agreed, to_h would be better but there's still some work to do after that.
<ox1eef_> >> tup = [1,2]; tup.each_slice(2).to_h.tap { |h| h.each { |k,v| h[k] = [*v] } }
<ruby[bot]> ox1eef_: # => {1=>[2]} (https://carc.in/#/r/f7vx)
<leftylink> it's a Vec<(a, b)> therefore no each_slice should be used
<ox1eef_> I don't think there's any rules to it. It is Rust after all.
<leftylink> that's true. I was wanting to be faithful but there's no rules that say it has to be such
<leftylink> so that's okay
<ox1eef_> Roger
<leftylink> I wonder if someone's name here is Roger, what they think of that
<ox1eef_> I never thought of that, but I'd guess it is not the first time it happened :)
<leftylink> it wouldn't be as easily mistaken as the time when someone's name is Okay though
<leftylink> wasn't just their username; it was their given name
<ox1eef_> It is the lingo of the radio.
<leftylink> there was also a T. Hanks at some point, so they get the username thanks
<ox1eef_> Airplane pilots have their dialect, cab drivers, etc.
<leftylink> I hope transform_values isn't less performant
<leftylink> haven't had a case where a transform_values was in the critical path so I never measured it
yassernasc has joined #ruby
<ox1eef_> For this case it would be fine.
caedmon has quit [Ping timeout: 258 seconds]
eddof13 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
foobarbaz has quit [Quit: Client closed]
eddof13 has joined #ruby
solici9 has joined #ruby
TomyWork has quit [Remote host closed the connection]
solici9 has quit [Quit: Best CPUs can count to infinity twice without being bugged out by zero division errors or whatnot.]
yassernasc has quit [Remote host closed the connection]
yassernasc has joined #ruby
teclator has quit [Quit: http://quassel-irc.org - Chat comfortably. Anywhere.]
gasbag has joined #ruby
gasbag has quit [Client Quit]
_ht has quit [Remote host closed the connection]
mexen has quit []
finsternis has joined #ruby
finsternis has quit [Client Quit]
finsternis has joined #ruby
hightower2 has quit [Remote host closed the connection]
duderonomy has quit [Quit: Textual IRC Client: www.textualapp.com]
yassernasc has quit [Remote host closed the connection]
nmollerup has quit [Remote host closed the connection]
<wakaflaka> hey
roadie has quit [Ping timeout: 240 seconds]
szkl has joined #ruby
<leftylink> I used to like that song
<leftylink> I guess I never stopped liking it so I shouldn't have used the past tense, it's just that I haven't thought about the song in a while so I didn't think to use present tense
roadie has joined #ruby
yetoo has quit [Quit: Leaving]
gasbag has joined #ruby
roadie has quit [Ping timeout: 240 seconds]
gr33n7007h has quit [Ping timeout: 260 seconds]
gr33n7007h has joined #ruby
ruby[bot] has quit [Remote host closed the connection]
ruby[bot] has joined #ruby
gasbag has quit [Quit: Leaving]
FetidToot has quit [Quit: The Lounge - https://thelounge.chat]
FetidToot has joined #ruby
<wakaflaka> leftylink: pffft
<wakaflaka> its just ur taste in music that sucks, not my song :)
<wakaflaka> v2 of it is substantially better though (in the studio making it now)
tomtmym has quit [Quit: Gone.]
<wakaflaka> actually using ruby to make it
roadie has joined #ruby
roadie has quit [Ping timeout: 240 seconds]
<wakaflaka> leftylink: wanna hear?
<wakaflaka> uses ruby midilib, a lotta fun
gr33n7007h has quit [Ping timeout: 258 seconds]
gr33n7007h has joined #ruby
cek_ has joined #ruby
cek_ is now known as cek
cek has left #ruby [#ruby]
markong has joined #ruby
ap4y has joined #ruby
kokoro has quit [Ping timeout: 240 seconds]
kokoro has joined #ruby
Bish has quit [Ping timeout: 240 seconds]
lena64t has joined #ruby
Bish has joined #ruby
lena64t has quit [Remote host closed the connection]
eddof13 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
roadie has joined #ruby
roadie has quit [Ping timeout: 240 seconds]