Topic 6 Web Security
Topic 6 Web Security
Web application security aims to address and fulfill the four conditions of security, also
referred to as principles of security:
• Confidentiality: States that the sensitive data stored in the Web application should not
be exposed under any circumstances.
• Integrity: States that the data contained in the Web application is consistent and is not
modified by an unauthorized user.
• Availability: States that the Web application should be accessible to the genuine user
within a specified period of time depending on the request.
• Nonrepudiation: States that the genuine user cannot deny modifying the data
contained in the Web application and that the Web application can prove its identity
to the genuine user.
The process of security analysis runs parallel with Web application development. The group
of programmers and developers who are responsible for code development are also
responsible for the execution of various strategies, post-risk analysis, mitigation and
monitoring.
T6.2) Identifying web security issues
What are the different types of website security issues, risks or threats, and what can make
your business and website an attractive or susceptible target? Many small businesses feel they
do not represent a worthwhile target to attackers, but as you will read, this assumption is plain
wrong. All online entities face a variety of security risks and threats that should be
understood and assessed.
For all too many companies, it‘s not until after a breach has occurred that web security
becomes a priority. An effective approach to IT security must, by definition, be proactive and
defensive. Toward that end, this discussion is aimed at sparking a security mindset, hopefully
injecting the reader with a healthy dose of paranoia.
In particular, this guide focuses on common and significant web security pitfalls to be aware
of, including recommendations on how they can be avoided.
So before we proceed, let‘s clearly the distinction between these two terms:
• Authentication: Verifying that a person is (or at least appears to be) a specific user,
since he/she has correctly provided their security credentials (password, answers to
security questions, fingerprint scan, etc.).
• Authorization: Confirming that a particular user has access to a specific resource or
is granted permission to perform a particular action.
Stated another way, authentication is knowing who an entity is, while authorization is
knowing what a given entity can do.
Anything that your application receives from untrusted sources must be filtered, preferably
according to a whitelist. You should almost never use a blacklist, as getting that right is very
hard and usually easy to bypass. Antivirus software products typically provide stellar
examples of failing blacklists. Pattern matching does not work.
Prevention: The good news is that protecting against injection is ―simply‖ a matter of
filtering your input properly and thinking about whether an input can be trusted. But the bad
news is that all input needs to be properly filtered, unless it can unquestionably be trusted
(but the saying ―never say never‖ does come to mind here).
In a system with 1,000 inputs, for example, successfully filtering 999 of them is not
sufficient, as this still leaves one field that can serve as the Achilles heal to bring down your
system. And you might think that putting an SQL query result into another query is a good
idea, as the database is trusted, but if the perimeter is not, the input comes indirectly from
guys with malintent. This is called Second Order SQL Injection in case you‘re interested.
Since filtering is pretty hard to do right (like crypto), what I usually advise is to rely on your
framework‘s filtering functions: they are proven to work and are thoroughly scrutinized. If
you do not use frameworks, you really need to think hard about whether not using them really
makes sense in your environment. 99% of the time it does not.
Assuming that anyone still wants to roll their own authentication code in 2014 (what are you
thinking??), I advise against it. It is extremely hard to get right, and there are a myriad of
possible pitfalls, just to mention a few:
1. The URL might contain the session id and leak it in the referer header to someone
else.
2. The passwords might not be encrypted either in storage or transit.
3. The session ids might be predictable, thus gaining access is trivial.
4. Session fixation might be possible.
5. Session hijacking might be possible, timeouts not implemented right or using HTTP
(no SSL), etc…
Prevention: The most straightforward way to avoid this web security vulnerability is to use a
framework. You might be able to implement this correctly, but the former is much easier. In
case you do want to roll your own code, be extremely paranoid and educate yourself on what
the pitfalls are. There are quite a few.
Prevention: There‘s a simple web security solution: don‘t return HTML tags to the client.
This has the added benefit of defending against HTML injection, a similar attack whereby the
attacker injects plain HTML content (such as images or loud invisible flash players) – not
high-impact but surely annoying (―please make it stop!‖). Usually, the workaround is simply
converting all HTML entities, so that <script> is returned as <script>. The other
often employed method of sanitization is using regular expressions to strip away HTML tags
using regular expressions on < and >, but this is dangerous as a lot of browsers will interpret
severely broken HTML just fine. Better to convert all characters to their escaped
counterparts.
For example, the code has a download.php module that reads and lets the user download
files, using a CGI parameter to specify the file name (e.g.,
download.php?file=something.txt). Either by mistake or due to laziness, the developer
omitted authorization from the code. The attacker can now use this to download any system
files that the user running PHP has access to, like the application code itself or other data left
lying around on the server, like backups. Uh-oh.
Another common vulnerability example is a password reset function that relies on user input
to determine whose password we‘re resetting. After clicking the valid URL, an attacker can
just modify the username field in the URL to say something like ―admin‖.
Incidentally, both of these examples are things I myself have seen appearing often ―in the
wild‖.
Prevention: Perform user authorization properly and consistently, and whitelist the choices.
More often than not though, the whole problem can be avoided by storing data internally and
not relying on it being passed from the client via CGI parameters. Session variables in most
frameworks are well suited for this purpose.
Prevention: Have a good (preferably automated) ―build and deploy‖ process, which can run
tests on deploy. The poor man‘s security misconfiguration solution is post-commit hooks, to
prevent the code from going out with default passwords and/or development stuff built in.
6. Common Mistake #6: Sensitive data exposure
This web security vulnerability is about crypto and resource protection. Sensitive data should
be encrypted at all times, including in transit and at rest. No exceptions. Credit card
information and user passwords should never travel or be stored unencrypted, and passwords
should always be hashed. Obviously the crypto/hashing algorithm must not be a weak one –
when in doubt, use AES (256 bits and up) and RSA (2048 bits and up).
And while it goes without saying that session IDs and sensitive data should not be traveling
in the URLs and sensitive cookies should have the secure flag on, this is very important and
cannot be over-emphasized.
Prevention:
• In transit: Use HTTPS with a proper certificate and PFS (Perfect Forward Secrecy).
Do not accept anything over non-HTTPS connections. Have the secure flag on
cookies.
• In storage: This is harder. First and foremost, you need to lower your exposure. If you
don‘t need sensitive data, shred it. Data you don‘t have can‘t be stolen. Do not store
credit card information ever, as you probably don‘t want to have to deal with being
PCI compliant. Sign up with a payment processor such as Stripe or Braintree. Second,
if you have sensitive data that you actually do need, store it encrypted and make sure
all passwords are hashed. For hashing, use of bcrypt is recommended. If you don‘t use
bcrypt, educate yourself on salting and rainbow tables.
And at the risk of stating the obvious, do not store the encryption keys next to the protected
data. That‘s like storing your bike with a lock that has the key in it. Protect your backups
with encryption and keep your keys very private. And of course, don‘t lose the keys!
Prevention: On the server side, authorization must always be done. Yes, always. No
exceptions or vulnerabilities will result in serious problems.
Attacker Alice wants to lighten target Todd’s wallet by transfering some of his money to her.
Todd’s bank is vulnerable to CSRF. To send money, Todd has to access the following URL:
http://example.com/app/transferFunds?amount=1500&destinationAccount=4673243243
After this URL is opened, a success page is presented to Todd, and the transfer is done. Alice
also knows, that Todd frequently visits a site under her control at blog.aliceisawesome.com,
where she places the following snippet:
<img
src="http://example.com/app/transferFunds?amount=1500&destinationAccount=46
73243243" width="0" height="0" />
Upon visiting Alice’s website, Todd’s browser thinks that Alice links to an image, and
automatically issues an HTTP GET request to fetch the “picture”, but this actually instructs
Todd’s bank to transfer $1500 to Alice.
Fun fact: CSRF is also the method people used for cookie-stuffing in the past until affiliates
got wiser.
Prevention: Store a secret token in a hidden form field which is inaccessible from the 3rd
party site. You of course always have to verify this hidden field. Some sites ask for your
password as well when modifying sensitive settings (like your password reminder email, for
example), although I‘d suspect this is there to prevent the misuse of your abandoned sessions
(in an internet cafe for example).
The lesson here is that software development does not end when the application is deployed.
There has to be documentation, tests, and plans on how to maintain and keep it updated,
especially if it contains 3rd party or open source components.
Prevention:
• Exercise caution. Beyond obviously using caution when using such components, do
not be a copy-paste coder. Carefully inspect the piece of code you are about to put
into your software, as it might be broken beyond repair (or in some cases,
intentionally malicious).
• Stay up-to-date. Make sure you are using the latest versions of everything that you
trust, and have a plan to update them regularly. At least subscribe to a newsletter of
new security vulnerabilities regarding the product.
It is worth mentioning, that stuffing unsanitized user-defined input into an HTTP header
might lead to header injection which is pretty bad.
Once upon a time, organizations primarily used Web gateways to prevent employees from
wasting time surfing the Web — or worse, from visiting gambling, adult, and other
unauthorized websites.
A few decades later, Web gateways do much more than enforce regulatory compliance and
HR policies. Organizations rely on them to thwart Internet-borne threats in three ways:
However, although Web gateways have been around for decades and continue to evolve, they
aren't bulletproof, and overreliance on them is putting data, users, customers, organizations,
and reputation in harm's way. Here are five of the biggest Web gatway security challenges:
To make things worse, it's also hard to keep up when 571 new websites are created every
second, which generates a high volume of domains and increases the chance that some will
be missed by security controls. It‘s difficult for filters to detect the malicious URLs that
attackers use for three reasons: URLs may be triggered only by the target organization and
remain stealthy during categorization, they‘re short lived (less than 24 hours), and they use
dynamic domains that are harder to thwart than static ones.
A good example is "malvertizing," which injects malicious ads into legitimate online
advertising networks later served by publishers that don't know that ads are malicious. These
malicious ads may not even require any user interaction to infect unsuspecting victims. A
recent example is the large-scale malvertising attacks that occurred in June and July this year
against several Yahoo properties. To circumvent ad blockers‘ ability to separate banner and
display ads, some publishers are integrating ads into their general content. Others, including
GQ publisher Condé Nast, insist that users disable their ad blockers in order to access
content.
Then there's the fact that many seemingly safe websites use common content management
systems that are vulnerable to zero-day exploits and can therefore be compromised by
attackers to serve malicious content. In July, thousands of websites running WordPress and
Joomla — which account for about 60% of all website traffic — served ransomware to all
their visitors. And you may remember that back in early 2015, Forbes.com was breached by
Chinese hackers who served malicious code via its "Thought of the Day" Flash widget.
Leveraging sandboxes to detect malware requires time to run and analyze files. To avoid
affecting user experience, Web gateways often pass files to users while sandboxes complete
their analysis in the background — which essentially means users are exposed to attacks.
Moreover, with the proliferation of sandbox evasion techniques and as malware is often
target-specific, sandboxes are proving to be less effective.
Indeed, recent research has found that 80% of Web gateways failed to block malicious
outbound traffic. Remote access Trojans are another example of how Web gateways can't
detect and stop malicious traffic.
T6.4) Explaining web security measures
A. Basic System Security Measures
The Basic System Security Measures apply to all systems at NYU, regardless of the level of
their System Classification. It is a baseline, which all systems must meet. Note that for most
personal workstations, these are the only Measures that apply. The requirements are:
The best way to safeguard sensitive data is not to handle it at all, and business processes that
can be amended to reduce or eliminate dependence on restricted data should be corrected.
For example, the University ID number can often be substituted for a social security number
and poses much less risk if accidentally disclosed.