Securing Your Plugin

41
SECURING YOUR PLUGIN Penny Wyatt Atlassian QA

Transcript of Securing Your Plugin

Page 1: Securing Your Plugin

SECURING YOUR

PLUGIN

Penny Wyatt

Atlassian QA

Page 2: Securing Your Plugin

Topics

Cross-Site Scripting (XSS) Vulnerabilities

Cross-Site Request Forgery (XSRF)

Vulnerabilities

Confluence WebSudo

File Execution Vulnerabilities

Random Number Vulnerabilities

Page 3: Securing Your Plugin

Cross Site Scripting

(XSS) Vulnerabilities

Page 4: Securing Your Plugin

XSS Vulnerabilities

Attacker runs JavaScript in the victim’s

web browser.

Attacker can do anything the victim can.

Two types:

Persisted XSS

Reflected XSS

Page 5: Securing Your Plugin

Persisted XSS Vulnerabilities

Attacker enters malicious data which is

stored on the server.

The data are presented on a page,

unescaped.

Requires the attacker to have

permission to insert data.

Doesn’t require any action on the

victim’s part.

Page 6: Securing Your Plugin

Reflected XSS Vulnerabilities

Attack is inserted into a URL.

Value from the querystring is reflected

directly onto the page, not stored.

Attacker gets the victim to visit the URL.

Does not require the attacker to have

any access at all.

Requires some minor social

engineering.

Page 7: Securing Your Plugin

Fixing XSS Vulnerabilities

Where the value is inserted into plain HTML,

use HTML encoding.

JIRA - $textutils.htmlEncode($name)

Confluence - $generalUtil.htmlEncode($name)

Bamboo - ${name?html}

Page 8: Securing Your Plugin

Fixing XSS Vulnerabilities

Where the value is inserted into JavaScript,

HTML escaping is insufficient...

Page 9: Securing Your Plugin

Fixing XSS Vulnerabilities

JavaScript escaping is also dangerous.

Better approach – insert escaped value

into HTML and access via the DOM.

Page 10: Securing Your Plugin

Fixing XSS Vulnerabilities

Never insert user-supplied content

directly into JavaScript.

Also includes other script execution

methods

When feasible, restrict data server-side

Page 11: Securing Your Plugin

Fixing XSS Vulnerabilities

Only escape at the Velocity level, never

internally.

Strict boundary for safe/unsafe content.

Reduce risk of double-escaping.

Page 12: Securing Your Plugin

Confluence Anti-XSS

Opt-in auto-escaping for Velocity

templates in Confluence.

Since Confluence 2.9.

Only partial protection.

Some areas still at risk:

HTML generated by excluded methods.

HTML generated client-side.

User-supplied variables inserted into

JavaScript.

Page 13: Securing Your Plugin

Finding XSS Vulnerabilities

Manual code analysis

Read velocity templates, webwork,

Confluence macros, any other source of

HTML.

Trace the source of all parameters.

Page 14: Securing Your Plugin

Finding XSS Vulnerabilities

Manual UI testing

Enter unsafe data in all form fields, including

hidden fields.

Enter unsafe data into all URL parameters.

Watch for unexpected behaviour.

Page 15: Securing Your Plugin

Finding XSS Vulnerabilities

Automated Scanning tools

Burp Suite, Skipfish

Useful to catch obvious flaws.

Lots of false positives, missed

vulnerabilities.

Page 16: Securing Your Plugin

Cross Site Request Forgery(XSRF) Vulnerabilities

Page 17: Securing Your Plugin

XSRF Vulnerabilities

Attacker tricks victim into executing an

action.

Action can be performed merely by

visiting an URL.

Request is hidden on an unrelated page

or used in conjunction with an XSS

vulnerabilities.

Victim may be unaware of the action.

Page 18: Securing Your Plugin

XSRF Vulnerabilities

Page 19: Securing Your Plugin

XSRF Vulnerabilities

Page 20: Securing Your Plugin

XSRF Vulnerabilities

Can vote for a JIRA issue by visiting a

URL.https://extranet.atlassian.com/jira/secure/

VoteOrWatchIssue.jspa?id=19128&vote=vote

No XSRF protection in those days.

Embedded image on another page<img src=

“https://extranet.atlassian.com/jira/secure/

VoteOrWatchIssue.jspa?id=19128&vote=vote”>

Page 21: Securing Your Plugin

XSRF Vulnerabilities

Page 22: Securing Your Plugin

Fixing XSRF Vulnerabilities

Limited-duration token issued by server.

Must provide that token when performing

protected actions.

User can manually confirm an action if

token has expired.

Since Confluence 3.0, JIRA 4.1.

Page 23: Securing Your Plugin

Fixing XSRF Vulnerabilities

Step 1 (JIRA): Add

@RequiresXsrfCheck to doExecute().

Page 24: Securing Your Plugin

Fixing XSRF Vulnerabilities

Step 1 (Confluence): Add

@RequireSecurityToken(true) to

doExecute().

Page 25: Securing Your Plugin

Fixing XSRF Vulnerabilities

Step 2: Add token to forms and querystrings.

JIRA:

Confluence:

Page 26: Securing Your Plugin

Finding XSRF Vulnerabilities

Every action that changes the state of

the plugin or host application is

vulnerable.

Overuse of XSRF protection frustrates

users.

XSRF protection easily circumvented by

XSS.

Page 27: Securing Your Plugin

Confluence WebSudo

Page 28: Securing Your Plugin

Confluence WebSudo

Aka “Secure Administrator Sessions”

Second line of defence against XSS and

XSRF attacks in Confluence.

Protects administration functions by

requiring a second login into an

administrative mode.

Default 10 minute rolling timeout.

Since Confluence 3.3.

Page 29: Securing Your Plugin

Confluence WebSudo

@WebSudoRequired annotation

Can be disabled by sysadmins

Narrows the window in which a stolen

cookie can be used to perform admin

functions, but does not eliminate it.

Disabled in dev mode.

Page 30: Securing Your Plugin

File Execution

Vulnerabilities

Page 31: Securing Your Plugin

File Execution

Vulnerabilities Allowing a user or administrator to

access an arbitrary location on the file

system is dangerous.

Simplest exploit – get Tomcat to serve

an uploaded file.

Escalation of privileges.

Page 32: Securing Your Plugin

Fixing File Execution

Vulnerabilities Never allow administrators or users to

specify server file paths through the UI.

Use known safe directories.

If configuration is absolutely necessary,

store the path in a .properties file on the

server.

Page 33: Securing Your Plugin

Random Number

Vulnerabilities

Page 34: Securing Your Plugin

Random Number Vulnerabilities

Random numbers are often used for

security, e.g.

XSRF tokens.

Reset password tokens.

If you can predict them, you can break

them.

java.util.Random is not secure.

Given one value, you can predict the

next.

Page 35: Securing Your Plugin

Random Number Vulnerabilities

Page 36: Securing Your Plugin

Random Number Vulnerabilities

java.security.SecureRandom is better

Still can be misused.

Predictable seeding (e.g. with the

system time) generates predictable

values.

Page 37: Securing Your Plugin

Random Number Vulnerabilities

Page 38: Securing Your Plugin

Fixing Random Number

Vulnerabilities

atlassian-secure-random package.

Facade for SecureRandom that correctly

instantiates and seeds it.

Allows for future performance and

cryptographic improvements with no

future code change required.

Page 39: Securing Your Plugin

Fixing Random Number

Vulnerabilities

Step 1: Add dependency to the pom:

Step 2: Get the instance, then use in the

same way as a SecureRandom:

Page 40: Securing Your Plugin

Best Coding Practices

HTML-encode user values in Velocity.

Don’t insert user values into JavaScript.

XSRF-protect functions.

Use WebSudo for admin functions in

Confluence.

Restrict file system access to known

safe directories.

Use atlassian-secure-random

Page 41: Securing Your Plugin

Q&A