-
Notifications
You must be signed in to change notification settings - Fork 339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
security: post OAuth token to client webapps if any #1149
security: post OAuth token to client webapps if any #1149
Conversation
At this level of integration you would be better of setting up a proper OAuth service by editing src/models/oauthclients.ts as described in this setup document. |
Yea I tried this once, but on some browsers was not possible from file://... origin (tizen local webapp) so I hacked around to make it work somehow, until a better solution is found. FYI, I used this bit for PWA app: Maybe I will refactor this proof of concept later, but I wished the code could support several platforms. |
Yeah, unfortunately this would make it really easy for an attacker to embed a frame of the local token service in their page and trick the user into giving them complete access to their gateway. I think it's possible to limit the message listener to only respond if the message originates from a file:// URL through ev.origin or something. That would make this PR much more secure. |
Yes I was about to suggest this, meanwhile I got proper OAuth on http. |
I would prefer a whitelist of specific protocols so that the exact behavior is completely specified. |
6965369
to
c7d0f4f
Compare
When client is loaded from file oauth can't be used because location.hostname is null. So we fallback by using postMessage API, instead of parsing the token page. Test could have been done on location.hostname, but for security concerns only file:// protocol is whitelisted Change-Id: I42af71ae822491150c019cff9688356b1a0e2532 Bug: WebThingsIO#1149 Signed-off-by: Philippe Coval <p.coval@samsung.com>
c7d0f4f
to
99336c0
Compare
When client is loaded from file oauth can't be used because location.hostname is null. So we fallback by using postMessage API, instead of parsing the token page. Test could have been done on location.hostname, but for security concerns only file:// protocol is whitelisted Change-Id: I42af71ae822491150c019cff9688356b1a0e2532 Bug: WebThingsIO#1149 Signed-off-by: Philippe Coval <p.coval@samsung.com>
When client is loaded from file oauth can't be used because location.hostname is null. So we fallback by using postMessage API, instead of parsing the token page. Test could have been done on location.hostname, but for security concerns only file:// protocol is whitelisted Change-Id: I42af71ae822491150c019cff9688356b1a0e2532 Bug: WebThingsIO#1149 Signed-off-by: Philippe Coval <p.coval@samsung.com>
99336c0
to
3689ead
Compare
When client is loaded from file oauth can't be used because location.hostname is null. So we fallback by using postMessage API, instead of parsing the token page. Test could have been done on location.hostname, but for security concerns only file:// protocol is whitelisted It was tested on Tizen5 on TM1. Change-Id: I42af71ae822491150c019cff9688356b1a0e2532 Bug: WebThingsIO#1149 Origin: https://github.com/tizenteam/gateway Signed-off-by: Philippe Coval <p.coval@samsung.com>
When client is loaded from file oauth can't be used because location.hostname is null. So we fallback by using postMessage API, instead of parsing the token page. Test could have been done on location.hostname, but for security concerns only file:// protocol is whitelisted Change-Id: I42af71ae822491150c019cff9688356b1a0e2532 Bug: WebThingsIO#1149 Signed-off-by: Philippe Coval <p.coval@samsung.com>
When client is loaded from file oauth can't be used because location.hostname is null. So we fallback by using postMessage API, instead of parsing the token page. Test could have been done on location.hostname, but for security concerns only file:// protocol is whitelisted It was tested on Tizen5 on TM1. Change-Id: I42af71ae822491150c019cff9688356b1a0e2532 Bug: WebThingsIO#1149 Origin: https://github.com/tizenteam/gateway Signed-off-by: Philippe Coval <p.coval@samsung.com>
When client is loaded from file oauth can't be used because location.hostname is null. So we fallback by using postMessage API, instead of parsing the token page. Test could have been done on location.hostname, but for security concerns only file:// protocol is whitelisted It was tested on Tizen5 on TM1. Change-Id: I42af71ae822491150c019cff9688356b1a0e2532 Bug: WebThingsIO#1149 Origin: https://github.com/tizenteam/gateway Signed-off-by: Philippe Coval <p.coval@samsung.com>
When client is loaded from file oauth can't be used because location.hostname is null. So we fallback by using postMessage API, instead of parsing the token page. Test could have been done on location.hostname, but for security concerns only file:// protocol is whitelisted It was tested on Tizen5 on TM1. Change-Id: I42af71ae822491150c019cff9688356b1a0e2532 Bug: WebThingsIO#1149 Origin: https://github.com/tizenteam/gateway Signed-off-by: Philippe Coval <p.coval@samsung.com>
3689ead
to
ab96de7
Compare
When client is loaded from file oauth can't be used because location.hostname is null. So we fallback by using postMessage API, instead of parsing the token page. Test could have been done on location.hostname, but for security concerns only file:// protocol is whitelisted It was tested on Tizen5 on TM1. Change-Id: I42af71ae822491150c019cff9688356b1a0e2532 Bug: WebThingsIO#1149 Origin: https://github.com/tizenteam/gateway Signed-off-by: Philippe Coval <p.coval@samsung.com>
ab96de7
to
a0fbcdc
Compare
When client is loaded from file oauth can't be used because location.hostname is null. So we fallback by using postMessage API, instead of parsing the token page. Test could have been done on location.hostname, but for security concerns only file:// protocol is whitelisted It was tested on Tizen5 on TM1. Change-Id: I42af71ae822491150c019cff9688356b1a0e2532 Bug: WebThingsIO#1149 Origin: https://github.com/tizenteam/gateway Signed-off-by: Philippe Coval <p.coval@samsung.com>
Codecov Report
@@ Coverage Diff @@
## master #1149 +/- ##
==========================================
+ Coverage 72.32% 72.32% +<.01%
==========================================
Files 126 126
Lines 6898 6899 +1
Branches 1031 1031
==========================================
+ Hits 4989 4990 +1
Misses 1664 1664
Partials 245 245
Continue to review full report at Codecov.
|
a0fbcdc
to
0f70e4e
Compare
When client is loaded from file oauth can't be used because location.hostname is null. So we fallback by using postMessage API, instead of parsing the token page. Test could have been done on location.hostname, but for security concerns only file:// protocol is whitelisted It was tested on Tizen5 on TM1. Change-Id: I42af71ae822491150c019cff9688356b1a0e2532 Bug: WebThingsIO#1149 Origin: https://github.com/tizenteam/gateway Signed-off-by: Philippe Coval <p.coval@samsung.com>
I think so it was needed for an "offline" webapp PoC... (loaded from file:// protocol), I made it evolve to support various frameworks (eg: aframe) , so it would be nice to have it in. |
👍, after #1712 this just needs an additional modification to https://github.com/mozilla-iot/gateway/blob/master/src/router.js#L46 to have |
Additionally, since this adds the ability for any random file:// page to clickjack the gateway, the modification to the content-security policy should be guarded by a config option (like 7fbaf56) |
0f70e4e
to
23a1ab2
Compare
When client is loaded from file oauth can't be used because location.hostname is null. So we fallback by using postMessage API, instead of parsing the token page. Test could have been done on location.hostname, but for security concerns only file:// protocol is whitelisted It was tested on Tizen5 on TM1: BUILD_ID=tizen-unified_20180528.1_mobile-wayland-armv7l-tm1 Relate-to: https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage# Change-Id: I42af71ae822491150c019cff9688356b1a0e2532 Bug: WebThingsIO#1149 Origin: https://github.com/tizenteam/gateway Signed-off-by: Philippe Coval <p.coval@samsung.com>
config/default.js
Outdated
@@ -74,5 +74,6 @@ module.exports = { | |||
ssid_base: 'WebThings Gateway', | |||
}, | |||
}, | |||
oauthPostToken: !false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should default to false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I used !false as reminder
@@ -123,6 +123,15 @@ let text = client.get("<span class="origin">https://gateway.local</span>/things" | |||
</div> | |||
</div> | |||
</section> | |||
<script> | |||
/* postToken to client apps if any */ | |||
if (config.get('oauthPostToken') && (window.location.protocol === "file:") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a handlebars template that gets used in the UI. Instead of using config
, you'll need to pass a value into the template.
You're also missing a paren at the end of this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes that code didnt work actually I figured out I used other hack to get token, next version works anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update! There are just a few minor changes then this LGTM
@@ -123,6 +123,15 @@ let text = client.get("<span class="origin">https://gateway.local</span>/things" | |||
</div> | |||
</div> | |||
</section> | |||
<script> | |||
/* postToken to client apps if any */ | |||
if (config.get('oauthPostToken') && (window.location.protocol === "file:") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Content-Security-Policy setting means we'll only be embedded in trusted situations so this doesn't need the config.get here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still use oauthPostToken to prevent a not wanted post action
see next revison
config/default.js
Outdated
@@ -74,5 +74,6 @@ module.exports = { | |||
ssid_base: 'WebThings Gateway', | |||
}, | |||
}, | |||
oauthPostToken: !false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
if (ev.data.message === "token") { | ||
ev.source.postMessage({ message: { token: "{{token}}" }}, "*"); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation of this is a bit off and the close brace from the initial if
statement is missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
When client is loaded from file oauth can't be used because location.hostname is null. So we fallback by using postMessage API, instead of parsing the token page. Test could have been done on location.hostname, but for security concerns only file:// protocol is whitelisted It was tested on Tizen5 on TM1: BUILD_ID=tizen-unified_20180528.1_mobile-wayland-armv7l-tm1 Relate-to: https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage# Change-Id: I42af71ae822491150c019cff9688356b1a0e2532 Bug: WebThingsIO#1149 Origin: https://github.com/tizenteam/gateway Signed-off-by: Philippe Coval <p.coval@samsung.com>
23a1ab2
to
14d3bd2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, other than the one comment.
response.set('Content-Security-Policy', 'frame-ancestors \'none\''); | ||
response.set('Content-Security-Policy', | ||
config.get('oauthPostToken') ? | ||
'frame-ancestors filesystem:' : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe filesystem:
needs single quotes around it: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems not , well with quotes I got an alert that they were ignored:
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:66.0) Gecko/20100101 Firefox/66.0
Content Security Policy: Couldn’t parse invalid host 'filesystem:'
On Tizen:
D/ConsoleMessage( 1681): [WebThings0] file:///js/index.js:438: Mozilla/5.0 (Linux; Tizen 5.0; SAMSUNG TM1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Mobile Safari/537.36
The source list for Content Security Policy directive 'frame-ancestors' contains an invalid source: ''filesystem:''. It will be ignored.
... now i am unsure if scheme should be quoted or not, see:
edit: I will file a bug on MDN
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're right. Confusing docs on MDN.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hobinjk Any other objections? |
When loaded from window.opener CORS is blocked by default,
so this is workaraounding security issues like:
Uncaught DOMException: Blocked a frame with origin (...)
from accessing a cross-origin frame. at (...)
For any security concern this change can be reverted anytime.
Change-Id: I42af71ae822491150c019cff9688356b1a0e2532
Signed-off-by: Philippe Coval p.coval@samsung.com