Web Development
Web Development
Diploma in Engineering
A Repot on:
[ Basic of web development ]
Name:
Board Roll: 4117418230
Semester: 4th
Batch: 2023-26
Session: 2024-25
Secure Web development
ABSTRACT
This chapter is an effort to develop secure web applications based on known
vulnerabilities. It has been seen that in the rapid race of developing web
applications in minimum time and budget, security is given least importance
as consequence of which web applications are developed and hosted with
number of vulnerabilities in them. And in this race, one thing is constant that
attackers take advantage of weaknesses existing in technology for financial
gain and theft of intellectual property. In this proposed method of secure
web development, most common vulnerabilities and their occurrence in
development process is discussed. Mapping vulnerabilities to the actions
needed to take during development process may help developers to
understand vulnerability and avoid vulnerabilities in application.
INTRODUCTION
Since the development of internet, web applications have become very
popular, and, nowadays, they are used in every environment, such as
medical, financial, military systems. But in the race to develop these online
services, web applications have been developed and deployed with minimal
attention given to security risks, resulting in surprising number of corporate
sites that are vulnerable to hackers (Halkidis, 2008). With the rise in web
applications for security critical environment, number of attacks against
these applications has grown as well. Organizations face more security risks
imposed upon them by hackers on achieving fame, glory, profit or
information. Malicious hackers are finding out constructively new ways to
exploit web applications. According to study conducted by Imperva’s
Application Defense Center (ADC), web sites experience an average of 27
attacks per hour or about every two minutes (Be’ery et al, 2011). When sites
come under automated attack, the target can experience up to 25,000
attacks per hour or 7 per second (Be’ery et al, 2011). The number of daily
web based attacks observed was 93% higher in 2010 as compare to 2009,
according to report by Symantec on attack Kits and malicious websites
[SYM].
Web based attacks are rising consistently and there are number of reasons
that make applications so vulnerable. The rise in attack volume in web
applications is due to ready availability of attack toolkits, many of which
exploit known vulnerabilities (Malek, 2004). Hacking tools and guides are
available on-line, almost anyone can launch attack using these resources.
Web applications have become interesting target for many for achieving
fame, profit or information. Hackers continue to focus on web applications
because these are easy points of entry and valuable data is exchanged in
business processes run by these web applications. Developers are mandated
to deliver functionality on time and on budget but not to develop secure
applications. Developers are not generally educated in secure code
practices. According to CERT/CC, more than 90% of vulnerabilities leak out
during development. They are result of ignoring known vulnerabilities
found in other
2
systems (Nany and Gary, 2005). Keeping this fact in mind, this chapter is an
attempt that will help to develop partially secure web applications avoiding
vulnerabilities.
The chapter describes related work, the development life cycle, most
common vulnerabilities in web applications and then explains the actions
proposed to avoid vulnerabilities. In the end, mapping of vulnerability to
action is done to understand and avoid the vulnerabilities and future scope is
discussed.
RELATED WORK
There are existing processes, standards, life cycle models, frameworks, and
methodologies that support or could support secure software development.
Security Development Lifecycle (SDL), which focuses on producing secure
software, is a software assurance methodology and tool that aims at
assisting software developers, designers, builders, and educators in
improving the security of software production. SDL prescribes activities to
embed security into applications and supplies the foundation for a broad
software security assurance that extends across an IT enterprise [FOR],
(Hajar and Salman, 2011). The SDL introduces security and privacy
throughout all phases of the development process. SDL includes five
phases: Training, policy, and organizational capabilities, Requirements and
design, Implementation, Verification, and Release and response. It includes
mandatory security activities executed as part of a software development
process.
The basic idea of this model is develop product in increments i.e., develop a
small sub- product with few requirements and then in next iteration, develop
another sub-product and integrate with existing one. Keep on repeating the
iterations until the final complete product is not ready. Also one important
thing is that security is inculcated in each phase of development life cycle.
COMMON VULNERABILITIES
Vulnerability is a hole or weakness in application, which can be design flaw
or implementation bug that allows an attacker to cause harm to stakeholders
of an application (Chunguang et. al, 2006). Almost 80% of web application
attacks are from known vulnerabilities (Raviv, 2012). This is shown in figure
2. This section introduces 20
5
WV 1- SQL Injection: SQL injection is a very old approach but it's still popular
among attackers. This technique allows an attacker to retrieve crucial
information from a Web server's database. Constructing a dynamic SQL
statement (constructing SQL queries by string concatenation) with user input
may allow an attacker to modify original statement to illegal SQL statement.
The cause of this vulnerability is weak input validation and can be avoided by
allowing only alphanumeric characters, especially avoid double quote (”),
single quote (‘), semicolon (;), colon (:) and dash(-) . Most SQL injection
vulnerabilities can be easily fixed by avoiding use of dynamically constructed
SQL queries and using parameterized queries or stored procedures instead
[WVR], (Uzi Ben-Artzi and Donald, 2003).
functions to protect data and credentials [OWA]. At coding level, avoid hard
coding of data.
7
WV 8- Format string: This vulnerability occurs when the user is able to control
format string used in printf style functions. This attack alters the flow of
application by using string formatting library features to access other
memory space [WAS]. Attackers can set buffer overflow attack taking control
over format string. To avoid this, user input should not be passed to
formatting functions directly (Shirazi, 2009). Formatting functions should
accept only static string as input.
WV 10- Failure to restrict URL access: Failure to restrict URL access may
enable attackers to forge URLs to access hidden pages or admin pages
8
these pages are requested. In case of violation of URL access, an error page
should be return to user.
WV 13- Brute Force: Brute force attack automates a process of trial and error
to guess a person’s user name, password, credit-card number or
cryptographic key [WAS]. In this method unknown value is determined by
using automated process to try large number of possible values. To avoid
this always select a password with minimum of 8 character alphanumeric
and do not use common words and terms as passwords.
WV 16- Injection Flaws (LDAP, SSI, XPath): Injection flaw basically allows to
insert specially formulated data, code, script in order to affect normal
execution [CUS]. Mostly injection flaw attacks occur when user sends some
illegal input. LDAP (Light weight directory access Protocol) injection attack
exploit web sites by constructing LDAP statements from user supplied inputs.
XPath injection constructs queries from user supplied input. SSI (server Side
Include) sends code to web server which is then executed locally [WAS]. To
avoid injection flaws user inputs should be validated properly.
WV19- Improper Error Handling: Many vulnerabilities occur when errors are not
handled properly. A server that is configured to operate in Debug mode may
offer considerable information about the error, which may reveal server and
application pathways, file names, code segments, server types and versions,
and other information. All of these contribute to resources the attacker will
use to exploit the web application and server. Once a poorly handled error is
discovered, an attacker may iterate man types of errors to collect a wide
range of information about the server. Some errors, especially crafted errors
by an attacker, may result in denial of service or cause the server to fail in
some form. Some security features of the web application may become
voided by some error situations, creating yet more vulnerabilities. To counter
this, errors should be handled in such a way that system preserves its secure
state (Shirazi, 2009). All the expected and unexpected errors should be
handled in a proper way and error message generated by application should
be issued only as needed void of any extra information (Younan, 2003).
Act-1: Only accept input values specified in white list and if user supplies any
other input, reject it.
Act-2: When it is not possible to predict exactly type or form of input use
sanitization strategy i.e. use escaping or encoding characters so that
it will not affect back end system.
Act-3: Along with validating external boundaries, each component of
1
2
application must validate data coming from and going to other
components.
1
3
Act-4: Make sure that if an attacker manages to cause an exception, there is
no way for execution flow to reach at end of function. Exceptions
should be handled properly.
Act-5: Implementing resource locking for shared resources and complete
transactions. Understand the thread safety mechanisms provided by
development framework and database.
Act-6: A structured approach must be followed for error handling. Sensitive
information or technical details like background operation causing
exception, stack traces, file system paths should not be disclosed in
error messages. Standard HTTP error codes should be handled by
application and never returned to users.
Act-7: Sensitive data should be transmitted to remote storage in an
encrypted and authenticated fashion.
Act-8: Choose a proper development framework, programming language with
respect to requirements and expected functionality as this decision
can mitigate much possible vulnerability.
Act-9: Applying least privileges and separating duties.
Act-10: storing sensitive data using appropriate access control and encryption
technique.
Act-11: Secure data transmission by using secure data transfer protocols
especially for sensitive data.
Act-12: validating remote codes including data type and size of uploaded
file or attachment.
Act-13: Filter unnecessary requests or decrease requests in order to avoid DoS
or low performance.
Act-14: Inactivity of users for a specific period should fore the system to log
out and login in again.
Act-15: Use library functions instead of using external / system calls. Avoid
invoking operating system calls directly.
Act-16: Simple Coding according to coding standards and well-defined
programming structure.
Act-17: Using validated SSL(secure socket Layer) certificates.
Act-18: In order to ensure that design is implemented in a correct and secure
way, code should be reviewed for issues like memory allocation and
free up , variable initialization. Tools are also available for automated
code review.
Act-19: Do not save password directly, encrypt them using appropriate
cryptographic function. For additional level of protection add
randomly generated data to user inputted password.
Act-20: Re-authenticate users before any critical transaction is authorized to
ensure that if a user session is compromised an attacker would not
be able to perform sensitive transaction on behalf of user unless
he/she is also in possession of user’s credentials.
1
4
Act-21: Locking the account after predefined number of unsuccessful login
attempts and also increasing the response time after each failed login
attempt.
Act-22: Minimize the number of authentication interfaces.
Act-23: The application should be able to detect if a single source IP is
responsible for multiple authentication failures.
Act-24: Reissue a new token after successful authentication and protect it
throughout session’s lifespan.
Act-25: Session tokens need to be unpredictable and sufficiently random.
They should be independent on ser credentials. They must expire
after a reasonable period.
Act-26: Manage session to user mapping safely on server side.
Transmit session tokens over secure channel only. Use cookies to store them
not query string parameters.
Act-27: Set “Secure” and “HttpOnly ” flags to secure cookies and do not store
sensitive information in cookies.
Act-28: Deny access by default unless it is explicitly granted.
Act-29: Use parameterized queries and avoid string concatenation.
Act-30: Disable the functionality not required by application such as
operating system calls, HTTP interfaces, built in compilers, etc.
Act-31: Storing content outside the web root and using and indexed list of
accessible resources instead.
Act-32: Isolate the resource required by the application from other resources
in the underlying server.
Act-33: Store any uploaded content in a directory outside of web server’s
document root or best practice is to store it in database so that it can
not get executed by web server.
Act-34: Perform security focused code review. Ensure that dynamic execution
functions such as eval(), include() or those inside templates do not
take user-supplied data as inputs without strict validation.
Act-35: Do not use persistent cookies to store sensitive information.
Act-36: Instead o fusing query string, favor requests that send information as
HTML form parameter.
Act-37: Before performing requested operation make sure that requests are
legitimate.
Act-38: Token regeneration should be performed prior to any significant
transaction, after a certain number of requests, as a function of time.
Act-39: Do not rely on client-side security measures. Security must be
enforced by the server.
Act-40: Disable standard HTTP methods that are not used by application.
1
5
Act-41: The Web server should run with minimum privileges required and
must apply security patches.
Act-42: Output validation with respect to type and amount of outputted
information based on security policies.
Act-43: Using stored procedures instead of dynamic SQL.
Act-44: Validating function’s return value and calling error/exception handlers
if required.
Act-45: Avoid hard coding of data.
Act-46: Re-implementing unsafe functions using standard library functions.
Act-47: Generating awareness among users and guiding them to differentiate
between original and phishing sites.
Act-48: Addressing with arrays instead of direct pointers manipulation.
Act-49: static creation of external commands in a program and passing static
string which can not be controlled by user, to format string function
and checking the number of arguments sent to that function.
Act-50: choose a proper and hard to guess location for temporary files and
applying access control mechanisms on them (encrypt if required).
Try to create lent side temporary files.
Actions No. of
occurrence
s
Act1 7
Act8 4
Act9 4
Act32 4
Act34 4
1
7
Act17 3
Act30 3
Act39 3
Act40 3
Table3: Top Actions
These are the actions that are commonly overlooked by developers and have
given advantage to attackers. And most important thing is training and
awareness among developers to implement these actions in development
process.
In the future, we can expect more security solutions and more awareness of
their implementation.
ADDITIONAL READING
http://msdn.microsoft.com/security/default.aspx?pull=/library/en-
us/dnsecure/html/sdl.asp (2005).
[SYM] “Threat activity Trends- Web based attack report 2009-10” available
at: http://www.symantec.com/business/threat-report/
Uzi Ben-Artzi L. and Donald S. (2003),. “Web Application Security: A Survey
of Prevention Techniques against SQL Injection”, Thesis Stokholm
University/Royal Institute of Technology, June 2003.
Walker J. (2012), “web application security--keeping your application safe”,
http://ajaxexperience.techtarget.com/images/Presentations/Walker_Joe_
WebApp Security.pdf, retrieved on 9th May, 2012.
[WAS] “Web App Security—how to Minimize Prevalent risk of attacks”,
available at www.qualys.com
[WHW] “White Hat Website Security Statistic Report”, 10th edition Fall 2010,
available at www.whitehatsec.com
[WVR] “Webapps Vulnerability Report”, from Core Impact Professional, Jan
2009.
http://www.coresecurity.com/files/attachments/core_impact_webapps_v
ulnerabilit ies_report.pdf
Younan Y. (2003), “An Overview Of Common Programming Security
Vulnerabilities And Possible Solutions”, Master’s thesis, Vrije University
Brussel.