News for hackers. Stuff that matters.
Re:A minimalistic site to vent and see others doing the same... by raggi on Wednesday January 27, 2021 @02:09AM (#25925196)
You're warned:

    const messageText = inputTextBox.value.replace(/<\/?[^>]+(>|$)/g, "");

    var $newdiv = $('<div class="' + messageDivClass + '"><p>' + messageText + '<p/><div/>').css({
        'opacity': '0.95'
    });
Re:A minimalistic site to vent and see others doing the same... by szhu on Wednesday January 27, 2021 @02:24AM (#25925298)
The safe, proper way to do this is both shorter and more readable!

Both with jQuery:

    const $newdiv = $('<div>')
      .addClass(messageDivClass)
      .text(inputTextBox.value)
      .css({'opacity': '0.95'});

and without:

    const newdiv = document.createElement('div');
    newdiv.classList.add(messageDivClass);
    newdiv.innerText = inputTextBox.value;
    newdiv.style.opacity = '0.95';
Re:A minimalistic site to vent and see others doing the same... by VentScape on Wednesday January 27, 2021 @02:34AM (#25925355)
Hey, creator of the site here, thank you so much for the tip!

Unfortunately I'm quite new to full stack. ~1.5 months ago I didn't know a lick of HTML (let alone CSS, JS, any backend framework, AWS, etc), and I'm making lots of mistakes along the way. Currently trying to figure out how to improve my DB performance as Spring's default pagination seems to be quite slow and my site is getting hugged to death at the moment. If anyone has any tips for that especially I'm all ears.

At any rate, your suggestion seems easy enough to put in, so I'll put it in ASAP! Thanks again

Re:A minimalistic site to vent and see others doing the same... by jlis on Wednesday January 27, 2021 @07:02AM (#25927181)
You could also benefit from using websockets instead of sending the message to a DB and fetching it from there. This way, you'd have instant communication between the users and there's no need to store anything.
Re:A minimalistic site to vent and see others doing the same... by C4stor on Wednesday January 27, 2021 @04:59AM (#25926272)
Reduce the refresh rate drastically, augment the number of messages fetched at once (let's say 200), and display them slowly. Should reduce 20 times the load on DB while making no sensible difference for end users anyway.
Re:A minimalistic site to vent and see others doing the same... by VentScape on Wednesday January 27, 2021 @06:51AM (#25927106)
Ok interesting idea. My one fret here would be that it would decrease interactivity on the site. Sometimes people send messages in response to each other, right? But nonetheless I'll experiment with increasing the refresh rate and maybe strike a nicer balance
Re:A minimalistic site to vent and see others doing the same... by corobo on Wednesday January 27, 2021 @08:57AM (#25928304)
I agree with you. Realtime is the key intrigue after the site itself, people will go off it when they realise it's not live.
Re:A minimalistic site to vent and see others doing the same... by nmeta on Wednesday January 27, 2021 @10:39AM (#25929513)
second this, I managed a brief conversation with someone when trying this out and it was great, a few other messages seemed to chime in as well. perf/eff can be improved as mentioned above but would lose the fun, imo
Re:A minimalistic site to vent and see others doing the same... by eindiran on Wednesday January 27, 2021 @02:36AM (#25925365)
Congratulations on getting to the front page of HN and Reddit / mostly surviving the hug of death!
Re:A minimalistic site to vent and see others doing the same... by andreareina on Wednesday January 27, 2021 @02:59AM (#25925499)
Sounds like you're using offset for pagination.

https://use-the-index-luke.com/no-offset

Re:A minimalistic site to vent and see others doing the same... by VentScape on Wednesday January 27, 2021 @04:23AM (#25926020)
A bit more explanation for you or any other helpful people reading, I'm using Spring's PagingAndSortingRepository.findAll(Pageable) function, and then passing in sort=id,desc&size=10 via the API request params (but no explicit offset AFAIK).

Found one potentially good stackoverflow to dig into so far https://stackoverflow.com/questions/44021665/why-is-a-pagina...

Re:A minimalistic site to vent and see others doing the same... by simply_sam on Thursday January 28, 2021 @05:33AM (#25940286)
Hi, is there any way to contact you privately?

I would like to use this idea on a project of mine.

Re:A minimalistic site to vent and see others doing the same... by VentScape on Thursday January 28, 2021 @12:59PM (#25945868)
Sure. Feel free to DM me on Reddit (u/VentScape). Eventually I'll set up some @ventscape.life emails to use but I haven't gone through the effort yet
Re:A minimalistic site to vent and see others doing the same... by llarsson on Wednesday January 27, 2021 @05:44AM (#25926577)
Holy hell, OP.

What prevents me from just calling "postMessage" directly myself, which does nothing to prevent the "sanitation" that the replace function call there is supposed to do?

Please sanitize messages on the server instead.

Re:A minimalistic site to vent and see others doing the same... by Mapsmithy on Wednesday January 27, 2021 @11:06AM (#25929930)
The fact that it's also called when its added to the stack for display. OP should definitely still sanitize on the server, but it's not as bad as it sounds at first glance.

As an exercise I'd love it someone actually posted a payload to exploit that regex.

Re:A minimalistic site to vent and see others doing the same... by gitrog on Wednesday January 27, 2021 @03:01AM (#25925507)
Sorry, would you mind explaining what this will do?
Re:A minimalistic site to vent and see others doing the same... by thepete2 on Wednesday January 27, 2021 @04:18AM (#25925977)
Improper input sanitation, you can potentially add raw html to other people's pages (XSS).
Re:A minimalistic site to vent and see others doing the same... by madhato on Wednesday January 27, 2021 @11:50AM (#25930439)
Doesn't the regex sanitize it before display?
Re:A minimalistic site to vent and see others doing the same... by some_random on Wednesday January 27, 2021 @01:53PM (#25932222)
Yes but it's pretty easily bypassed
Re:A minimalistic site to vent and see others doing the same... by Mapsmithy on Wednesday January 27, 2021 @09:08PM (#25937213)
I asked earlier because I'm genuinely curious, but do you have a payload that would bypass this particular regex?
Re:A minimalistic site to vent and see others doing the same... by madhato on Wednesday January 27, 2021 @06:49PM (#25935838)
How is it easily bypassed?
Re:A minimalistic site to vent and see others doing the same... by vfinn on Wednesday January 27, 2021 @07:01AM (#25927170)
That's terrible. OP should take the site down and fix those issues.
Re:A minimalistic site to vent and see others doing the same... by vfinn on Wednesday January 27, 2021 @10:15AM (#25929162)
Yeah, go ahead and down vote without explaining yourself. It's so educational!
Re:A minimalistic site to vent and see others doing the same... by SwiftyBug on Wednesday January 27, 2021 @03:12PM (#25933288)
My guess is that you were downvoted because you sound like you are talking about a very important system with a huge number of users that could have catastrophic consequences if the vulnerability is not fixed. It's just a project from a novice programmer having fun. Hence, no need to take the site down.
Re:A minimalistic site to vent and see others doing the same... by vfinn on Thursday January 28, 2021 @01:50AM (#25938983)
So it's not a principled decision? How many users does the site have? 10000, 100000? To me, that's a lot. Thanks for answering.
Re:A minimalistic site to vent and see others doing the same... by halvo on Wednesday January 27, 2021 @03:10AM (#25925562)
What are you warning about?
Re:A minimalistic site to vent and see others doing the same... by mxxx on Wednesday January 27, 2021 @03:21AM (#25925630)
XSS vulnerabilities