question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Require "secure" cookies

See original GitHub issue

Please describe what the rule should do:

When setting cookies with js, we should require the “secure” parameter. In 2019, with free SSL with letsencrypt, there really is no reason anymore to not be on SSL/https and eslint should require the secure parameter to improve security.

This is (I believe) also easily auto-fixable by eslint.

What category of rule is this? (place an “X” next to just one item)

[ ] Warns about a potential error (problem) [ ] Suggests an alternate way of doing something (suggestion) [ ] Enforces code style (layout) [x] Other (please specify:) Improves security

Provide 2-3 code examples that this rule will warn about:

document.cookie = "username=John Doe";
document.cookie = "username=John Doe; expires=Thu, 18 Dec 2013 12:00:00 UTC";
document.cookie = "username=John Doe; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/";

Should be:
document.cookie = "username=John Doe; secure";
document.cookie = "username=John Doe; expires=Thu, 18 Dec 2013 12:00:00 UTC; secure";
document.cookie = "username=John Doe; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/; secure";

Why should this rule be included in ESLint (instead of a plugin)? This is a core component in making js/the web more secure (even only marginally)

Are you willing to submit a pull request to implement this rule? I have no idea how, but I am happy to test, write documentation or whatever else is needed.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
aladdin-addcommented, May 22, 2019

hi, thanks for creating the issue! it seems an useful rule, however it would only works for browsers. we don’t accept new rules for specific runtime. https://eslint.org/docs/developer-guide/contributing/new-rules#core-rule-guidelines

I would recommended you to add it to an eslint plugin.

1reaction
sindresorhuscommented, May 25, 2019

I agree this would be a better fit for a plugin.

@kkmuffme Open an issue on eslint-plugin-unicorn. I would be happy to host the rule there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using HTTP cookies - MDN Web Docs
A cookie with the Secure attribute is only sent to the server with an encrypted request over the HTTPS protocol.
Read more >
Secure your Cookies (Secure and HttpOnly flags)
Servers that require a higher level of security SHOULD use the Cookie and Set-Cookie headers only over a secure channel. When using cookies...
Read more >
Secure cookie - Wikipedia
When a cookie has the Secure attribute, the user agent will include the cookie in an HTTP request only if the request is...
Read more >
Cookie Security Flags | Learn AppSec - Invicti
The Secure flag specifies that the cookie may only be transmitted using HTTPS connections (SSL/TLS encryption) and never sent in clear text. If...
Read more >
What are Secure Cookies? - Really Simple SSL
HttpOnly. The HttpOnly flag will tell the browser that this cookie can only be accessed by the server. · Secure. The secure parameter...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found