Secure development

Using browser storage and HTML5 capabilities safely

Browser origins: browser, code, gate arranged to illustrate using browser storage and html5 capabilities safely.

Using browser storage and HTML5 capabilities safely connects a security requirement to the behaviour of a real feature. The relevant controls need to remain effective across custom code, integrations and the production configuration. Understanding browser storage and html5 capabilities safely helps establish which security property the feature needs and where that property is actually enforced.

What does this involve?

Storage security concerns the copies that remain after an operation has finished. Files, databases, caches and exports can have different access rules and retention periods. A protected main database does not automatically protect a temporary copy or a restored backup.

Web Messaging (also known as Cross Domain Messaging) provides a means of messaging between documents from different origins in a way that is generally safer than the multiple hacks used in the past to accomplish this task. However, there are still some recommendations to keep in mind:

To summarize, it's the capacity to act on parent page's content or location from a newly opened page via the back link exposed by the opener JavaScript object instance.

Why it matters

Consider a realistic failure: browser storage retains sensitive data that an unrelated script running in the same origin can access.

Exposure can involve private records, reusable credentials or information that identifies a customer. The practical impact depends on which copy is accessible, the access an attacker needs and whether the recovered material remains useful.

Implementation guidance should be applied to a real feature and its deployment. Framework defaults, custom handlers and integrated services all influence whether the intended protection remains effective.

How penetration testers check for it

Trace the relevant feature from its entry point to the data or operation it protects, including custom code and alternate paths.

  • Trace where representative sensitive values are written.
  • Compare effective access permissions and relevant device or account states.
  • Check temporary copies, exports, backups and deletion behaviour.
  • Establish whether recovered information grants any further access.

How to fix it

Use the appropriate maintained mechanisms and verify the result in the actual production configuration.

  • When posting a message, explicitly state the expected origin as the second argument to postMessage rather than * in order to prevent sending the message to an unknown origin after a redirect or some other means of the target window's origin changing.
  • Check the origin attribute of the sender to verify the data is originating from the expected location.
  • Perform input validation on the data attribute of the event to ensure that it's in the desired format.
  • Don't assume you have control over the data attribute. A single Cross Site Scripting flaw in the sending page allows an attacker to send messages of any given format.
  • Protect encryption keys independently of encrypted files.
  • Verify removal and recovery behaviour against the intended lifecycle.

Encryption is one part of the design. It cannot compensate for an application that willingly returns plaintext to an unauthorised caller.

Recheck the changed behaviour against the original failure conditions and the legitimate user journey. Keep enough evidence to show which release and configuration were verified, and include related entry points that depend on the same security decision.

Read about our methodology or contact pentested.com to discuss secure development and code review.

See your first test report this week.

Book a 30 minute demo. We will verify one of your targets with you and run a test against it, so you can judge the results on your own systems.

Book a demo