Posts

Showing posts from February, 2020

How can we prevent XSS attacks?

Preventing cross-site scripting is trivial in some cases but can be much harder depending on the complexity of the application and the ways it handles user-controllable data. In general, effectively preventing XSS vulnerabilities is likely to involve a combination of the following measures: Filter input on arrival - At the point where user input is received, filter as strictly as possible based on what is expected or valid input. Encode data on output - At the point where user-controllable data is output in HTTP responses, encode the output to prevent it from being interpreted as active content. Depending on the output context, this might require applying combinations of HTML, URL, JavaScript, and CSS encoding. Use appropriate response headers - To prevent XSS in HTTP responses that aren't intended to contain any HTML or JavaScript, you can use the Content-Type and X-Content-Type-Options headers to ensure that browsers interpret the responses in the way you intend. Co

How does XSS work?

Image
Cross-site scripting works by manipulating a vulnerable web site so that it returns malicious JavaScript to users. When the malicious code executes inside a victim's browser, the attacker can fully compromise their interaction with the application.

XSS - cross site scripting

What is the difference between XSS and CSRF? XSS involves causing a web site to return malicious JavaScript, while CSRF involves inducing a victim user to perform actions they do not intend to do. What is the difference between XSS and SQL injection?  XSS is a client-side vulnerability that targets other application users, while SQL injection is a server-side vulnerability that targets the application's database. How do I prevent XSS in PHP?  Filter your inputs with a whitelist of allowed characters and use type hints or typecasting. Escape your outputs with htmlentities and ENT_QUOTES for HTML contexts, or JavaScript Unicode escapes for JavaScript contexts. How do I prevent XSS in Java? Filter your inputs with a whitelist of allowed characters and use a library such as Google Guava to HTML-encode your output for HTML contexts, or use JavaScript Unicode escapes for JavaScript contexts

Difference between jQuery parent() and parents() method?

Image
The basic difference is the parent() function travels only one level in the DOM tree, where parents() function search through the whole DOM tree. To understand this, let's look at the below-given HTML code. When you make a call to parent() function like $("#spnText").parent() It will give you "P" as the output.parent() function selects the first parent in the DOM tree. Now,if we call parents() function like $("#spnText").parents() It will give all parents in DOM tree which are, p->dvChild->dvParent->form-> body->html. You can pass a filter in parents() function  as well to select specific parent like if you want to select both the divs then $("#spnText").parents('div');

What are magic methods in PHP?

PHP supports multiple magic methods, those methods can be identified by two underscore prefix(__).  These are special functions should be defined by the user but no need to call them explicitly. It will be called on an appropriate event occurrence. For example, class __construct() will be called while instantiating the class. PHP magic methods must be defined inside the class. Note : Declaring the constructor method private prevents external code from directly creating an object. This is handy for creating singleton classes that restrict the number of objects that can exist. PHP Magic Methods and Purposes Below are the magic methods invoked on creating Class Instance - __construct() -  The __construct() method is most commonly used magic method. Here you can do initialization you need when an object is created. You can define any number of arguments that will be passed when creating objects. __destruct()  - The __destruct() method is called when the object is destroyed

Traits in PHP

What are the Traits in Laravel? Traits are a simple group of methods that you want to include in another class. Why we use Traits? A Trait, like an abstract class, cannot be instantiated by itself. The trait is created to reduce the limitations of single inheritance in PHP by enabling a developer to reuse sets of methods freely in several independent classes living in different class hierarchies.

List of JavaScript object method

Methods Description concat() It returns a new array object that contains two or more merged arrays. copywithin() It copies the part of the given array with its own elements and returns the modified array. every() It determines whether all the elements of an array are satisfying the provided function conditions. fill() It fills elements into an array with static values. filter() It returns the new array containing the elements that pass the provided function conditions. find() It returns the value of the first element in the given array that satisfies the specified condition. findIndex() It returns the index value of the first element in the given array that satisfies the specified condition. forEach() It invokes the provided function once for each element of an array. includes() It checks whether the given array contains the specified element. indexOf() It searches the specified element in the given array

What are life cycle hooks in VueJs?

beforeCreate -  The first component in the creation of hooks. This allows us to perform actions before our component has been added to DOM. We don't have access to DOM inside of this hook. Created  -This hook is invoked when Vue has set up events and data observations. Here, events are active and access to reactive data is enabled through templates that have not yet been mounted or rendered. beforeMount -  The beforeMount hooks runs right before the initial render happens and after the template or render functions have complied. Mounted  - This is a most used hook and you will have full access to the reactive component, templates, and rendered DOM (via. this.$el). The most frequently used patterns are fetching data for your component. beforeUpdate -  This hook runs after data changes on our component and the update cycle begins. But it runs right before the DOM is patched and re-renders. Updated  - This hook runs after data changes on your component and the DOM re-renders.

List of JavaScript array method

Methods Description concat() It returns a new array object that contains two or more merged arrays. copywithin() It copies the part of the given array with its own elements and returns the modified array. every() It determines whether all the elements of an array are satisfying the provided function conditions. fill() It fills elements into an array with static values. filter() It returns the new array containing the elements that pass the provided function conditions. find() It returns the value of the first element in the given array that satisfies the specified condition. findIndex() It returns the index value of the first element in the given array that satisfies the specified condition. forEach() It invokes the provided function once for each element of an array. includes() It checks whether the given array contains the specified element. indexOf() It searches the specified element in the given array