I was preventing my application from cross site scripting defect. I have done the validation part for all the fields present in my application, but I don't know how to prevent this defect if someone injects the code in the url, please help me how to get rid of this defect.
Eg:
Script:
javascript:alert(document.cookie)
like if we inject the above code in the url we can get the username and the session id after logout.
Please suggest me the solution.
html decoding/encoding cant help in this, I tested this on most of the web application (like Atlassian JIRA, Slack) all were allowing this and it was being printed in html page. This tag will only work i following cases:
if it is being printed
in href attribute-
Test
in Onclick attribute
<a href=# onclick="javascript:alert(document.cookie)" >test</a>
So make sure that you are not printing anything directly in href or onClick attribute, if you are doing than add any filter there which can manually detect javascript or dont forgot to append http:// before the link.
Someone entering javascript:alert(document.cookie) in the address bar is not a vulnerability.
If an attacker put a href in their website linking to javascript:alert(document.cookie) then it would simply show the cookies on the attacker's site.
Only the user can enter the code in their own browser. This is known as Self-XSS.
If this is not what you mean, please update your question with an example of a working URL (you could change your domain to example.com for privacy), and then add a comment to let me know and I'll update my answer to help.
Related
I have a little problem: I need to get the source of a website in an android app, but to view the website I have to be logged in. I tried some ways, but it is not working. It is a little bit complicated, because it must work like this:
1. Log in on domain abcd.ef
2. Go to ghij.kl/internal
3. Go to ghij.kl/secure/data.php
3. Go to ghij.kl/secure/data/1.html and save source as string
I already tried to login via POST on abcd.ef, save cookies etc and use them on a new connection to ghij.kl, but that is not working, I receive error 403 from the website. I think the website checks the referrer, but I am not sure and I really need help of (or from?) some experts.
Sincerely,
atom_dad
I'm working on a Java application that need's to be able to connect to my University's websites containing my student information. I'm not exactly sure how to go about doing this as the websites framework is Seam which I don't have any experience with.
This is the main link
https://elion.psu.edu/
and after clicking on student this is the link that I actually need to login to.
https://webaccess.psu.edu/?cosign-elionnx.ais.psu.edu&https://elionnx.ais.psu.edu/eLionStudent/secure/elionHome.seam
Does anyone know how to open the second link (student login page) and programmatically enter the username/password, thne 'click' log in?
There's a lot more stuff that needs to be done after the log in but I'm sure I can figure it out if someone could shed a little light on how I should go about doing this.
Thanks,
-Justin
Basically it looks like an application/x-www-form-urlencoded 'POST' to the URL:
https://webaccess.psu.edu/?cosign-elionnx.ais.psu.edu&https://elionnx.ais.psu.edu/eLionStudent/secure/elionHome.seam
It could be reproduced programatically by making an HTTP POST request (ensure to set the Content-Type Header to application/x-www-form-urlencoded) to that address, and posting the encoded form data. Which would look like this if you tried to submit the login 'asd' and password 'sdf':
ref=https%3A%2F%2Felionnx.ais.psu.edu%2FeLionStudent%2Fsecure%2FelionHome.seam&service=cosign-elionnx.ais.psu.edu&required=&login=asd&password=sdf
A good way to figure out this information (If you are using Chrome) is open the developer-tools and go to the network tab. Check the 'preserve-log' box and then try to submit something on the web page. The very first thing in the list for me was the POST request it attempted to login. By clicking on that you can see lots of detailed information about the actual request itself.
Hope this helps!
I am working on a homework assignment that is due shortly and I have searched and searched and searched for the answer to this and I just don't know where to go at this point.
I am using Eclipse Juno, with Tomcat 7.0 and a MySql database. I have to develop a web application for a pizza place. I have pretty much everything working so will only post the code here if requested since there is a ton.
My problem is I have a login form that calls the j_security_check, which works just fine. However, when the user is logged in they are taken to a customer form which is supposed to display their name, address, phone number and give them the option of editing any of it or just starting their order. My problem is I need to get the j_username and pull the customer information from my database to populate the form when the user is redirected from the login page to the customer.jsp page. We are not supposed to use <% ----- %> in our code if we can help it and to keep that in servlets. I just am lost on how to get that j_username and then call a servlet to populate the form (I can do the population if I can get the data).
HELP PLEASE!!! I know I am missing something really simple here and it is driving me nuts.
Ok I have tried the demo you sent and actually found another demo with the FORM like my project. I still cannot get it to work. I am a little lost. When I do the demo exactly as they have it the servlet generates text and outputs it. I was able to change it to a requestDispatcher and send it to the page I need it to go to on the login. The demo just has it going to the url host.../YourProject/test not an actual page. I am lost on how to get it to call the servlet so I can grab the header information with my project. I have the servlet LoginUser I want the user to login on login.jsp and there is a login_error.jsp in case of an error. When the user successfully log's in they should be taken to customer.jsp and the fields on the page populated with their data. I need to change this to use SSL too but haven't got there yet I am still trying to get the data for the customer.
I suspect what you're using is basic authentication in Tomcat. Check out this post for instructions. In summary, you'll need to grab the authentication header from the servlet request and parse it to grab the username (first you'll likely need to base64 decode it). Then you can use that username to look up the necessary information in the database.
I'm creating a simple Java webapp using Tomcat 7. In this site only logged users can view the content, so I have a main page index.jsp which contains only 2 forms, one to log-in and other to sing-up. Only once the user has logged-in or registered, he can access the website content.
I'd like to avoid users to enter username and password each time, so I think I could use cookies to achieve this, right?
If it's right, I'd like to know how to do it... my first approach is to use a servlet, and use the url of this servlet as the entry point of my webapp, but I'm not sure that this is the best practice at all...
And anyway, if finally it is a good practice, can I set this url as the default entry point or something like that?
I would use a filter. The filter can check for the cookie and handle the authorization pieces in it.
Googling "jsp remember me" would get you more ideas:
It's NOT secure to store passwords in cookies as plain text.
Instead, you can use a long string called 'token' that is issued from the website when you provide your user name and password. See http://jaspan.com/improved_persistent_login_cookie_best_practice for more details.
I would be grateful if someone could please show me an example of how to login to a phpBB forum remotely and perform a search.
The language i am using is java however, i just need to know the steps involved.
even some pointers on what to google to get the answers i need would be great i have googled everything i can think of.
I'm unable to give you code samples for this, but the general process would be
Use a POST request to send the login details to {forumLocation}/ucp?mode=login, this requires the inputs "username" and "password"
Once your are logged in using this method you should just be able to perform searches by sending requests to this url
/search.php?keywords={value1}+{value2}+{value3}&terms=all&submit=Search
Where value1, value2, value3 are your search items.
There is a Java libary which should be able to help you with this called HTTPCLient, which should make maintaining the session once your logged in easy.
This page will give you some more details of sending post inputs HTML forms.
Hope this at least puts you on the right track.