On Github mvolz / security
Injection flaws, such as SQL, OS, and LDAP injection occur when untrusted data is sent to an interpreter as part of a command or query. The attacker’s hostile data can trick the interpreter into executing unintended commands or accessing data without proper authorization.
File.expand_path(ballot.$(malicious_command)) run ( " gpg " , "−−trust −model always −o \"#{ File.expand_path ( dst.path ) } \" −e −r \"#{ @recipient } \" \"#{ File.expand_path (ballot.$(malicious_command)) } \" " )Rails PaperClip Plug-in 2.3.2 + performs path filtering.
Never use: exec(), eval(), passthru(), shell_exec()
Use caution: setTimeout(), setInterval(), new Function()
System-run jobs: be careful!
Application functions related to authentication and session management are often not implemented correctly, allowing attackers to compromise passwords, keys, or session tokens, or to exploit other implementation flaws to assume other users’ identities.
"password" + "x@de*pfj%n$m_i_am_a_nice_long_salt" hash_algorithm("passwordx@de*pfj%n$m_i_am_a_nice_long_salt") '08d399fe2647d383277a91729476c61e'
U_SALT = "g8k" if 'password' in request.GET: password = request.GET['password'].strip().lower() if password_hash == md5(password+U_SALT).hexdigest():How many things can you find wrong with this? Salt too short, salt global variable (same for every password), password getting sent through GET rather than POST (will be in URL, which exposes it)
//To hash a password: var bcrypt = require('bcrypt'); bcrypt.genSalt(12, function(err, salt) { bcrypt.hash("my password", salt, function(err, hash) { // Store hash in your password DB. }); }); //To check a password: // Load hash from your password DB. bcrypt.compare("my password", hash, function(err, res) { // res == true }); bcrypt.compare("not my password", hash, function(err, res) { // res == false });
Rails >= 3 ship with ActiveModel::SecurePassword which uses bcrypt-ruby.https://github.com/codahale/bcrypt-ruby
Install extra library and set pwd hashing to bcrypt. https://docs.djangoproject.com/en/1.5/topics/auth/passwords/#using-bcrypt-with-django
XSS flaws occur whenever an application takes untrusted data and sends it to a web browser without proper validation or escaping. XSS allows attackers to execute scripts in the victim’s browser which can hijack user sessions, deface web sites, or redirect the user to malicious sites.
<script class="xss">$('.xss').parents().eq(1).find('a').eq(1).click();$('[data-action=retweet]').click();alert('XSS in Tweetdeck')</script>♥
— *arrrrndy (@derGeruhn) June 11, 2014Node: jade, dustjs-linkedin
Django: The Django template language
RoR: embedded Ruby (erb) -> Frontend security and Cross-Site Scripting (XSS) for Ruby on Rails developers
Wordpress/PHP: Twig
G+: Disallowed
FB: Disallowed
Reddit & Ello: Markdown
Wikipedia: Wikitext
BBCode
Visual Editors- HTML editors: Wordpress/mediawiki
A direct object reference occurs when a developer exposes a reference to an internal implementation object, such as a file, directory, or database key. Without an access control check or other protection, attackers can manipulate these references to access unauthorized data.
Errors on page debugging
Good security requires having a secure configuration defined and deployed for the application, frameworks, application server, web server, database server, and platform. Secure settings should be defined, implemented, and maintained, as defaults are often insecure. Additionally, software should be kept up to date.
umich example, the gov claimed they were using a new version of the package that hadn't been tested well, but in the current version the bug had been patched... so this was a case where out of date software was a big issue!-Matt Lowe, Node Security Training 16-09-14
I couldn't use iframes a lot on this presentation because of X-Frame-Options: deny option was set on a lot of sites! Prevents click jacking, where someone uses your website in another website.Don't use public githubs as production repositories...
# Django settings.py DEBUG = True TEMPLATE_DEBUG = DEBUG ADMINS = ( # ('Your Name', 'your_email@example.com'), ) MANAGERS = ADMINS DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 'NAME': '/mypath/mypath/mydb.db', # Or path to database file if using sqlite3. 'USER': '', # Not used with sqlite3. 'PASSWORD': '', # Not used with sqlite3. 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. 'PORT': '', # Set to empty string for default. Not used with sqlite3. } } # Local time zone for this installation. Choices can be found here: # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name # although not all choices may be available on all operating systems. # On Unix systems, a value of None will cause Django to use the same # timezone as the operating system. # If running in a Windows environment this must be set to the same as your # system time zone. TIME_ZONE = 'America/Detroit' # Language code for this installation. All choices can be found here: # http://www.i18nguy.com/unicode/language-identifiers.html LANGUAGE_CODE = 'en-us' SITE_ID = 1 # If you set this to False, Django will make some optimizations so as not # to load the internationalization machinery. USE_I18N = True # If you set this to False, Django will not format dates, numbers and # calendars according to the current locale USE_L10N = True # Absolute filesystem path to the directory that will hold user-uploaded files. # Example: "/home/media/media.lawrence.com/media/" MEDIA_ROOT = '' # URL that handles the media served from MEDIA_ROOT. Make sure to use a # trailing slash. # Examples: "http://media.lawrence.com/media/", "http://example.com/media/" MEDIA_URL = '' # Absolute path to the directory static files should be collected to. # Don't put anything in this directory yourself; store your static files # in apps' "static/" subdirectories and in STATICFILES_DIRS. # Example: "/home/media/media.lawrence.com/static/" STATIC_ROOT = '' # URL prefix for static files. # Example: "http://media.lawrence.com/static/" STATIC_URL = '/static/' # URL prefix for admin static files -- CSS, JavaScript and images. # Make sure to use a trailing slash. # Examples: "http://foo.com/static/admin/", "/static/admin/". ADMIN_MEDIA_PREFIX = '/static/admin/' # Additional locations of static files STATICFILES_DIRS = ( # Put strings here, like "/home/html/static" or "C:/www/django/static". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. ) # List of finder classes that know how to find static files in # various locations. STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', # 'django.contrib.staticfiles.finders.DefaultStorageFinder', ) # Make this unique, and don't share it with anybody. SECRET_KEY = '*zie$h=6e)7x1q70rxq$%2&l$3cz40i$^u8$wq$^%(5754*$ma' # List of callables that know how to import templates from various sources. TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', # 'django.template.loaders.eggs.Loader', ) MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', # 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', ) ROOT_URLCONF = 'thissite.urls' TEMPLATE_DIRS = ( # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. ) INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', # Uncomment the next line to enable the admin: 'django.contrib.admin', 'django.contrib.humanize', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', 'cms', ) # A sample logging configuration. The only tangible logging # performed by this configuration is to send an email to # the site admins on every HTTP 500 error. # See http://docs.djangoproject.com/en/dev/topics/logging for # more details on how to customize your logging configuration. LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'handlers': { 'mail_admins': { 'level': 'ERROR', 'class': 'django.utils.log.AdminEmailHandler' } }, 'loggers': { 'django.request': { 'handlers': ['mail_admins'], 'level': 'ERROR', 'propagate': True, }, } } EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' try: from local_settings import * except ImportError: passDjango secret key documentation
Add to .gitignore:Rails <=4.0, secret_token.rb, Rails > 4.1, secrets.yml
Many web applications do not properly protect sensitive data, such as credit cards, tax IDs, and authentication credentials. Attackers may steal or modify such weakly protected data to conduct credit card fraud, identity theft, or other crimes. Sensitive data deserves extra protection such as encryption at rest or in transit, as well as special precautions when exchanged with the browser.
base64_encode($credit_card_number); pic.twitter.com/ETRrmn0RYM
— Jan Lehnardt (@janl) September 21, 2014Sensitive data in url (GET)
Exposing data via API
Want to see if your friends are on Ello? Just use the API directly to query their email (useful for spammers too) pic.twitter.com/QEXFNluvpW
— ashkan soltani (@ashk4n) October 1, 2014Most web applications verify function level access rights before making that functionality visible in the UI. However, applications need to perform the same access control checks on the server when each function is accessed. If requests are not verified, attackers will be able to forge requests in order to access functionality without proper authorization.
A CSRF attack forces a logged-on victim’s browser to send a forged HTTP request, including the victim’s session cookie and any other automatically included authentication information, to a vulnerable web application. This allows the attacker to force the victim’s browser to generate requests the vulnerable application thinks are legitimate requests from the victim.
Ruby on Rails and Django both have built-in CSRF support, but verify they are working properly on your app.
Components, such as libraries, frameworks, and other software modules, almost always run with full privileges. If a vulnerable component is exploited, such an attack can facilitate serious data loss or server takeover. Applications using components with known vulnerabilities may undermine application defenses and enable a range of possible attacks and impacts.
Web applications frequently redirect and forward users to other pages and websites, and use untrusted data to determine the destination pages. Without proper validation, attackers can redirect victims to phishing or malware sites, or use forwards to access unauthorized pages.
Free introductory workshops in London:
Django Girls London / PyLadies London
Writing secure express.js apps
It's hopeless
Free and Open Source Browser based Security Framework
Find web application vulnerabilities the easy way!
Experience programming in Node.js and/or completed nodeschool.io's 'learnyounode' and 'levelmeup'
sudo npm install -g security-adventure security-adventure
Everyone else! You don't have to know how to code, period, to do these- although it will go a lot faster if you do, of course! You'll get the most out of these exercises if you type. everything. by. hand.
This is like the difference between taking handwritten notes in class vs. taking photos of slides with your camera phone. You'll grok a lot more, even though it's tedious.License: CC by 3.0
Ladies Who Code and ^Lift Security, who provided me with a scholarship to their training session!