Title: messing with post_status to secure posts
Last modified: December 30, 2020

---

# messing with post_status to secure posts

 *  [GusGF](https://wordpress.org/support/users/gusgf/)
 * (@gusgf)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/messing-with-post_status-wp_insert_post_data/)
 * On the WP course I’m doing, the tutor has said that for a custom post type we’ve
   created called ‘notes’ it’s best to set the post_status to private. Otherwise
   another user not logged in to the website could via the REST API URL query/see**
   all** the notes created by a sites users. Incidentally I’m using Local by Flywheel
   to host my site locally and it’s not been deployed or hosted.
 * According to him one way of achieving this protection is to set the note’s status
   to ‘private’ in my JS file in modules, when posting to the database.
 * The other way is to use this code in functions.php
 *     ```
       add_filter('wp_insert_post_data', 'makeNotePrivate');
   
       function makeNotePrivate($data){
          if($data['post_type'] == 'note') {
            $data['post_status'] = "private";
          }
       }
       ```
   
 * According to my tutor the caveat to the first method is a user could maliciously
   change my JS code so all ‘note’ posts are saved with a post status of ‘public’!
 * My question is if this malicious end user could access and change the code in
   a JS file could they not also do the same to functions.php? At my knowledge level
   I’m not even sure how a malicious user would do this but apparently it’s possible.
 * All I’m looking for is an explanation of why this is the case I’m not looking
   for an alternative solution so pls no posts saying oh why don’t you try this.
   I just want to understand why he is saying what he is. Thanks
    -  This topic was modified 5 years, 5 months ago by [GusGF](https://wordpress.org/support/users/gusgf/).
    -  This topic was modified 5 years, 5 months ago by [GusGF](https://wordpress.org/support/users/gusgf/).
    -  This topic was modified 5 years, 5 months ago by [GusGF](https://wordpress.org/support/users/gusgf/).

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Moderator [cubecolour](https://wordpress.org/support/users/numeeja/)
 * (@numeeja)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/messing-with-post_status-wp_insert_post_data/#post-13846219)
 * What I think your tutor probably means is not that the js files are actually 
   edited on your server, but as scripts run locally in the user’s browser, the 
   user has the ability to alter the functionality of the script as it runs in their
   own browser.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/messing-with-post_status-wp_insert_post_data/#post-13849168)
 * To further Cubecolour’s reply, while JS runs in the user’s browser and this can
   be altered by the user, PHP code in functions.php runs server side and with a
   properly configured server, there is no way for end users to alter any PHP code.
 * For anything that requires complete security, never do it client side in someone’s
   browser, always do it server side.
 *  Thread Starter [GusGF](https://wordpress.org/support/users/gusgf/)
 * (@gusgf)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/messing-with-post_status-wp_insert_post_data/#post-13849296)
 * Thanks cubecolour, yes was aware of that but I guess I need assurance. Correct
   me if I’m wrong but if a malicious user without a login loaded up the website
   and made a change to the site’s JS then for them to see records subsequently 
   created by legitimate users the following would need to happen.
 * 1. These users would need to be using the same computer/browser as the malicious
   user.
    2. No hard refresh of the browser being used should have occured on that
   computer.
 * Thanks bcworkz, yes was aware of this but not absolutely sure hence the question
   and again just needed assurance.
 * Thanks to you both much appreciated 🙂
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/messing-with-post_status-wp_insert_post_data/#post-13852313)
 * Assuming only logged in users can create new notes (enforced server side), the
   malicious user would also need to be logged in to have any hope of publishing
   a public note. It’s not unheard of for bad actors to gain some minimal access
   to a system through legitimate means, then leverage weaknesses within to gain
   greater abilities than they should normally have.
 * Your first line of defense is vetting newly registered users. This is not always
   possible, or even with proper vetting, a bad actor still might be able to sneak
   in through clever social engineering. If your next line of defense relies upon
   JavaScript, it’s not much of a defense since users can modify the script.
 * Should a bad actor manage to publish a public note, perhaps with spammy pharma
   links, it’ll be visible to all visitors. It doesn’t matter which browser they
   used or what others are using.
 *  [oluwadamilare7](https://wordpress.org/support/users/oluwadamilare7/)
 * (@oluwadamilare7)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/messing-with-post_status-wp_insert_post_data/#post-13883615)
 * Good Day Sir. Sorry, I want to make enquiry on another post you made.
 * [https://wordpress.org/support/topic/the_field-vs-get_field/](https://wordpress.org/support/topic/the_field-vs-get_field/)
 * I would love to know what solution you eventually found to it. I’m in urgent 
   need of it

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘messing with post_status to secure posts’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 5 replies
 * 4 participants
 * Last reply from: [oluwadamilare7](https://wordpress.org/support/users/oluwadamilare7/)
 * Last activity: [5 years, 5 months ago](https://wordpress.org/support/topic/messing-with-post_status-wp_insert_post_data/#post-13883615)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
